-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update third party layer: Minissas (#3720) * update minisass third party layer * update minisass url * remove unused file * Add api to retrieve minisass * Store minisass token, update frontend --------- Co-authored-by: Faneva Andriamiadantsoa <fanevanjanahary@gmail.com>
- Loading branch information
1 parent
0a05a92
commit 41e6522
Showing
7 changed files
with
231 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import requests | ||
import os | ||
import json | ||
|
||
from preferences import preferences | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from django.conf import settings | ||
|
||
|
||
class MiniSASSObservationsView(APIView): | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get(self, request, format=None): | ||
file_path = os.path.join( | ||
settings.MEDIA_ROOT, | ||
'observations_data.json') | ||
data = None | ||
|
||
if os.path.exists(file_path): | ||
with open(file_path, 'r') as file: | ||
data = json.load(file) | ||
|
||
if data: | ||
return Response(data) | ||
|
||
url = "https://minisass.org/monitor/observations/" | ||
token = preferences.SiteSetting.minisass_token | ||
headers = { | ||
"Authorization": f"Bearer {token}" | ||
} | ||
|
||
response = requests.get(url, headers=headers) | ||
|
||
if response.status_code == 200: | ||
data = response.json() | ||
with open(file_path, 'w') as file: | ||
json.dump(data, file) | ||
return Response(data) | ||
else: | ||
return Response( | ||
response.text, | ||
status=response.status_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.11 on 2024-08-18 17:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('bims', '0432_sitesetting_park_layer_csv'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='sitesetting', | ||
name='minisass_token', | ||
field=models.CharField(blank=True, default=''), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters