goodmap 0.4.4__py3-none-any.whl → 0.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- goodmap/core_api.py +212 -25
- goodmap/data_models/location.py +2 -1
- goodmap/data_validator.py +1 -1
- goodmap/db.py +448 -0
- goodmap/goodmap.py +27 -1
- goodmap/templates/goodmap-admin.html +743 -0
- {goodmap-0.4.4.dist-info → goodmap-0.5.1.dist-info}/METADATA +11 -3
- goodmap-0.5.1.dist-info/RECORD +14 -0
- {goodmap-0.4.4.dist-info → goodmap-0.5.1.dist-info}/WHEEL +1 -1
- goodmap/templates/admin.html +0 -0
- goodmap-0.4.4.dist-info/RECORD +0 -14
- {goodmap-0.4.4.dist-info → goodmap-0.5.1.dist-info}/LICENSE.md +0 -0
goodmap/db.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
2
4
|
from functools import partial
|
|
3
5
|
|
|
4
6
|
from goodmap.core import get_queried_data
|
|
@@ -7,6 +9,15 @@ from goodmap.core import get_queried_data
|
|
|
7
9
|
# it should be replaced with dynamic solution
|
|
8
10
|
|
|
9
11
|
|
|
12
|
+
def json_file_atomic_dump(data, file_path):
|
|
13
|
+
dir_name = os.path.dirname(file_path)
|
|
14
|
+
with tempfile.NamedTemporaryFile("w", dir=dir_name, delete=False) as temp_file:
|
|
15
|
+
json.dump(data, temp_file)
|
|
16
|
+
temp_file.flush()
|
|
17
|
+
os.fsync(temp_file.fileno())
|
|
18
|
+
os.replace(temp_file.name, file_path)
|
|
19
|
+
|
|
20
|
+
|
|
10
21
|
# ------------------------------------------------
|
|
11
22
|
# get_location_obligatory_fields
|
|
12
23
|
|
|
@@ -30,6 +41,8 @@ def get_location_obligatory_fields(db):
|
|
|
30
41
|
|
|
31
42
|
# ------------------------------------------------
|
|
32
43
|
# get_data
|
|
44
|
+
|
|
45
|
+
|
|
33
46
|
def google_json_db_get_data(self):
|
|
34
47
|
return json.loads(self.blob.download_as_text(client=None))["map"]
|
|
35
48
|
|
|
@@ -104,6 +117,427 @@ def get_locations(db, location_model):
|
|
|
104
117
|
return partial(globals()[f"{db.module_name}_get_locations"], location_model=location_model)
|
|
105
118
|
|
|
106
119
|
|
|
120
|
+
# ------------------------------------------------
|
|
121
|
+
# add_location
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def json_file_db_add_location(self, location_data, location_model):
|
|
125
|
+
location = location_model.model_validate(location_data)
|
|
126
|
+
with open(self.data_file_path, "r") as file:
|
|
127
|
+
json_file = json.load(file)
|
|
128
|
+
|
|
129
|
+
map_data = json_file["map"].get("data", [])
|
|
130
|
+
idx = next(
|
|
131
|
+
(i for i, point in enumerate(map_data) if point.get("uuid") == location_data["uuid"]), None
|
|
132
|
+
)
|
|
133
|
+
if idx is not None:
|
|
134
|
+
raise ValueError(f"Location with uuid {location_data['uuid']} already exists")
|
|
135
|
+
|
|
136
|
+
map_data.append(location.model_dump())
|
|
137
|
+
json_file["map"]["data"] = map_data
|
|
138
|
+
|
|
139
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def json_db_add_location(self, location_data, location_model):
|
|
143
|
+
location = location_model.model_validate(location_data)
|
|
144
|
+
idx = next(
|
|
145
|
+
(
|
|
146
|
+
i
|
|
147
|
+
for i, point in enumerate(self.data.get("data", []))
|
|
148
|
+
if point.get("uuid") == location_data["uuid"]
|
|
149
|
+
),
|
|
150
|
+
None,
|
|
151
|
+
)
|
|
152
|
+
if idx is not None:
|
|
153
|
+
raise ValueError(f"Location with uuid {location_data['uuid']} already exists")
|
|
154
|
+
self.data["data"].append(location.model_dump())
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def add_location(db, location_data, location_model):
|
|
158
|
+
return globals()[f"{db.module_name}_add_location"](db, location_data, location_model)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
# ------------------------------------------------
|
|
162
|
+
# update_location
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def json_file_db_update_location(self, uuid, location_data, location_model):
|
|
166
|
+
location = location_model.model_validate(location_data)
|
|
167
|
+
with open(self.data_file_path, "r") as file:
|
|
168
|
+
json_file = json.load(file)
|
|
169
|
+
|
|
170
|
+
map_data = json_file["map"].get("data", [])
|
|
171
|
+
idx = next((i for i, point in enumerate(map_data) if point.get("uuid") == uuid), None)
|
|
172
|
+
if idx is None:
|
|
173
|
+
raise ValueError(f"Location with uuid {uuid} not found")
|
|
174
|
+
|
|
175
|
+
map_data[idx] = location.model_dump()
|
|
176
|
+
json_file["map"]["data"] = map_data
|
|
177
|
+
|
|
178
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def json_db_update_location(self, uuid, location_data, location_model):
|
|
182
|
+
location = location_model.model_validate(location_data)
|
|
183
|
+
idx = next(
|
|
184
|
+
(i for i, point in enumerate(self.data.get("data", [])) if point.get("uuid") == uuid), None
|
|
185
|
+
)
|
|
186
|
+
if idx is None:
|
|
187
|
+
raise ValueError(f"Location with uuid {uuid} not found")
|
|
188
|
+
self.data["data"][idx] = location.model_dump()
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def update_location(db, uuid, location_data, location_model):
|
|
192
|
+
return globals()[f"{db.module_name}_update_location"](db, uuid, location_data, location_model)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# ------------------------------------------------
|
|
196
|
+
# delete_location
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def json_file_db_delete_location(self, uuid):
|
|
200
|
+
with open(self.data_file_path, "r") as file:
|
|
201
|
+
json_file = json.load(file)
|
|
202
|
+
|
|
203
|
+
map_data = json_file["map"].get("data", [])
|
|
204
|
+
idx = next((i for i, point in enumerate(map_data) if point.get("uuid") == uuid), None)
|
|
205
|
+
if idx is None:
|
|
206
|
+
raise ValueError(f"Location with uuid {uuid} not found")
|
|
207
|
+
|
|
208
|
+
del map_data[idx]
|
|
209
|
+
json_file["map"]["data"] = map_data
|
|
210
|
+
|
|
211
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def json_db_delete_location(self, uuid):
|
|
215
|
+
idx = next(
|
|
216
|
+
(i for i, point in enumerate(self.data.get("data", [])) if point.get("uuid") == uuid), None
|
|
217
|
+
)
|
|
218
|
+
if idx is None:
|
|
219
|
+
raise ValueError(f"Location with uuid {uuid} not found")
|
|
220
|
+
del self.data["data"][idx]
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def delete_location(db, uuid):
|
|
224
|
+
return globals()[f"{db.module_name}_delete_location"](db, uuid)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
# ------------------------------------------------
|
|
228
|
+
# add_suggestion
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def json_db_add_suggestion(self, suggestion_data):
|
|
232
|
+
suggestions = self.data.setdefault("suggestions", [])
|
|
233
|
+
if any(s.get("uuid") == suggestion_data.get("uuid") for s in suggestions):
|
|
234
|
+
raise ValueError(f"Suggestion with uuid {suggestion_data['uuid']} already exists")
|
|
235
|
+
|
|
236
|
+
record = dict(suggestion_data)
|
|
237
|
+
record["status"] = "pending"
|
|
238
|
+
suggestions.append(record)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def json_file_db_add_suggestion(self, suggestion_data):
|
|
242
|
+
with open(self.data_file_path, "r") as file:
|
|
243
|
+
json_file = json.load(file)
|
|
244
|
+
|
|
245
|
+
suggestions = json_file["map"].get("suggestions", [])
|
|
246
|
+
if any(s.get("uuid") == suggestion_data.get("uuid") for s in suggestions):
|
|
247
|
+
raise ValueError(f"Suggestion with uuid {suggestion_data['uuid']} already exists")
|
|
248
|
+
|
|
249
|
+
record = dict(suggestion_data)
|
|
250
|
+
record["status"] = "pending"
|
|
251
|
+
suggestions.append(record)
|
|
252
|
+
json_file["map"]["suggestions"] = suggestions
|
|
253
|
+
|
|
254
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def add_suggestion(db, suggestion_data):
|
|
258
|
+
return globals()[f"{db.module_name}_add_suggestion"](db, suggestion_data)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
# ------------------------------------------------
|
|
262
|
+
# get_suggestions
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def json_db_get_suggestions(self, query_params):
|
|
266
|
+
suggestions = self.data.get("suggestions", [])
|
|
267
|
+
|
|
268
|
+
statuses = query_params.get("status")
|
|
269
|
+
if statuses:
|
|
270
|
+
suggestions = [s for s in suggestions if s.get("status") in statuses]
|
|
271
|
+
|
|
272
|
+
return suggestions
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def json_file_db_get_suggestions(self, query_params):
|
|
276
|
+
with open(self.data_file_path, "r") as file:
|
|
277
|
+
json_file = json.load(file)
|
|
278
|
+
|
|
279
|
+
suggestions = json_file["map"].get("suggestions", [])
|
|
280
|
+
|
|
281
|
+
statuses = query_params.get("status")
|
|
282
|
+
if statuses:
|
|
283
|
+
suggestions = [s for s in suggestions if s.get("status") in statuses]
|
|
284
|
+
|
|
285
|
+
return suggestions
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def get_suggestions(db):
|
|
289
|
+
return globals()[f"{db.module_name}_get_suggestions"]
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
# ------------------------------------------------
|
|
293
|
+
# get_suggestion
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def json_db_get_suggestion(self, suggestion_id):
|
|
297
|
+
return next(
|
|
298
|
+
(s for s in self.data.get("suggestions", []) if s.get("uuid") == suggestion_id), None
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def json_file_db_get_suggestion(self, suggestion_id):
|
|
303
|
+
with open(self.data_file_path, "r") as file:
|
|
304
|
+
json_file = json.load(file)
|
|
305
|
+
return next(
|
|
306
|
+
(s for s in json_file["map"].get("suggestions", []) if s.get("uuid") == suggestion_id), None
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def get_suggestion(db):
|
|
311
|
+
return globals()[f"{db.module_name}_get_suggestion"]
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
# ------------------------------------------------
|
|
315
|
+
# update_suggestion
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def json_db_update_suggestion(self, suggestion_id, status):
|
|
319
|
+
suggestions = self.data.get("suggestions", [])
|
|
320
|
+
for s in suggestions:
|
|
321
|
+
if s.get("uuid") == suggestion_id:
|
|
322
|
+
s["status"] = status
|
|
323
|
+
return
|
|
324
|
+
raise ValueError(f"Suggestion with uuid {suggestion_id} not found")
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def json_file_db_update_suggestion(self, suggestion_id, status):
|
|
328
|
+
with open(self.data_file_path, "r") as file:
|
|
329
|
+
json_file = json.load(file)
|
|
330
|
+
|
|
331
|
+
suggestions = json_file["map"].get("suggestions", [])
|
|
332
|
+
for s in suggestions:
|
|
333
|
+
if s.get("uuid") == suggestion_id:
|
|
334
|
+
s["status"] = status
|
|
335
|
+
break
|
|
336
|
+
else:
|
|
337
|
+
raise ValueError(f"Suggestion with uuid {suggestion_id} not found")
|
|
338
|
+
|
|
339
|
+
json_file["map"]["suggestions"] = suggestions
|
|
340
|
+
|
|
341
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def update_suggestion(db, suggestion_id, status):
|
|
345
|
+
return globals()[f"{db.module_name}_update_suggestion"](db, suggestion_id, status)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
# ------------------------------------------------
|
|
349
|
+
# delete_suggestion
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def json_db_delete_suggestion(self, suggestion_id):
|
|
353
|
+
suggestions = self.data.get("suggestions", [])
|
|
354
|
+
idx = next((i for i, s in enumerate(suggestions) if s.get("uuid") == suggestion_id), None)
|
|
355
|
+
if idx is None:
|
|
356
|
+
raise ValueError(f"Suggestion with uuid {suggestion_id} not found")
|
|
357
|
+
|
|
358
|
+
del suggestions[idx]
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def json_file_db_delete_suggestion(self, suggestion_id):
|
|
362
|
+
with open(self.data_file_path, "r") as file:
|
|
363
|
+
json_file = json.load(file)
|
|
364
|
+
|
|
365
|
+
suggestions = json_file["map"].get("suggestions", [])
|
|
366
|
+
idx = next((i for i, s in enumerate(suggestions) if s.get("uuid") == suggestion_id), None)
|
|
367
|
+
if idx is None:
|
|
368
|
+
raise ValueError(f"Suggestion with uuid {suggestion_id} not found")
|
|
369
|
+
|
|
370
|
+
del suggestions[idx]
|
|
371
|
+
json_file["map"]["suggestions"] = suggestions
|
|
372
|
+
|
|
373
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def delete_suggestion(db, suggestion_id):
|
|
377
|
+
return globals()[f"{db.module_name}_delete_suggestion"](db, suggestion_id)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
# ------------------------------------------------
|
|
381
|
+
# add_report
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def json_db_add_report(self, report_data):
|
|
385
|
+
reports = self.data.setdefault("reports", [])
|
|
386
|
+
if any(r.get("uuid") == report_data.get("uuid") for r in reports):
|
|
387
|
+
raise ValueError(f"Report with uuid {report_data['uuid']} already exists")
|
|
388
|
+
|
|
389
|
+
reports.append(report_data)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def json_file_db_add_report(self, report_data):
|
|
393
|
+
with open(self.data_file_path, "r") as file:
|
|
394
|
+
json_file = json.load(file)
|
|
395
|
+
|
|
396
|
+
reports = json_file["map"].get("reports", [])
|
|
397
|
+
if any(r.get("uuid") == report_data.get("uuid") for r in reports):
|
|
398
|
+
raise ValueError(f"Report with uuid {report_data['uuid']} already exists")
|
|
399
|
+
|
|
400
|
+
reports.append(report_data)
|
|
401
|
+
json_file["map"]["reports"] = reports
|
|
402
|
+
|
|
403
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def add_report(db, report_data):
|
|
407
|
+
return globals()[f"{db.module_name}_add_report"](db, report_data)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
# ------------------------------------------------
|
|
411
|
+
# get_reports
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def json_db_get_reports(self, query_params):
|
|
415
|
+
reports = self.data.get("reports", [])
|
|
416
|
+
|
|
417
|
+
statuses = query_params.get("status")
|
|
418
|
+
if statuses:
|
|
419
|
+
reports = [r for r in reports if r.get("status") in statuses]
|
|
420
|
+
|
|
421
|
+
priorities = query_params.get("priority")
|
|
422
|
+
if priorities:
|
|
423
|
+
reports = [r for r in reports if r.get("priority") in priorities]
|
|
424
|
+
|
|
425
|
+
return reports
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def json_file_db_get_reports(self, query_params):
|
|
429
|
+
with open(self.data_file_path, "r") as file:
|
|
430
|
+
json_file = json.load(file)
|
|
431
|
+
|
|
432
|
+
reports = json_file["map"].get("reports", [])
|
|
433
|
+
|
|
434
|
+
statuses = query_params.get("status")
|
|
435
|
+
if statuses:
|
|
436
|
+
reports = [r for r in reports if r.get("status") in statuses]
|
|
437
|
+
|
|
438
|
+
priorities = query_params.get("priority")
|
|
439
|
+
if priorities:
|
|
440
|
+
reports = [r for r in reports if r.get("priority") in priorities]
|
|
441
|
+
|
|
442
|
+
return reports
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def get_reports(db):
|
|
446
|
+
return globals()[f"{db.module_name}_get_reports"]
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
# ------------------------------------------------
|
|
450
|
+
# get_report
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def json_db_get_report(self, report_id):
|
|
454
|
+
return next((r for r in self.data.get("reports", []) if r.get("uuid") == report_id), None)
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def json_file_db_get_report(self, report_id):
|
|
458
|
+
with open(self.data_file_path, "r") as file:
|
|
459
|
+
json_file = json.load(file)
|
|
460
|
+
|
|
461
|
+
return next(
|
|
462
|
+
(r for r in json_file["map"].get("reports", []) if r.get("uuid") == report_id), None
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def get_report(db):
|
|
467
|
+
return globals()[f"{db.module_name}_get_report"]
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
# ------------------------------------------------
|
|
471
|
+
# update_report
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def json_db_update_report(self, report_id, status=None, priority=None):
|
|
475
|
+
reports = self.data.get("reports", [])
|
|
476
|
+
for r in reports:
|
|
477
|
+
if r.get("uuid") == report_id:
|
|
478
|
+
if status:
|
|
479
|
+
r["status"] = status
|
|
480
|
+
if priority:
|
|
481
|
+
r["priority"] = priority
|
|
482
|
+
return
|
|
483
|
+
raise ValueError(f"Report with uuid {report_id} not found")
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def json_file_db_update_report(self, report_id, status=None, priority=None):
|
|
487
|
+
with open(self.data_file_path, "r") as file:
|
|
488
|
+
json_file = json.load(file)
|
|
489
|
+
|
|
490
|
+
reports = json_file["map"].get("reports", [])
|
|
491
|
+
for r in reports:
|
|
492
|
+
if r.get("uuid") == report_id:
|
|
493
|
+
if status:
|
|
494
|
+
r["status"] = status
|
|
495
|
+
if priority:
|
|
496
|
+
r["priority"] = priority
|
|
497
|
+
break
|
|
498
|
+
else:
|
|
499
|
+
raise ValueError(f"Report with uuid {report_id} not found")
|
|
500
|
+
|
|
501
|
+
json_file["map"]["reports"] = reports
|
|
502
|
+
|
|
503
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def update_report(db, report_id, status=None, priority=None):
|
|
507
|
+
return globals()[f"{db.module_name}_update_report"](db, report_id, status, priority)
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
# ------------------------------------------------
|
|
511
|
+
# delete_report
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def json_db_delete_report(self, report_id):
|
|
515
|
+
reports = self.data.get("reports", [])
|
|
516
|
+
idx = next((i for i, r in enumerate(reports) if r.get("uuid") == report_id), None)
|
|
517
|
+
if idx is None:
|
|
518
|
+
raise ValueError(f"Report with uuid {report_id} not found")
|
|
519
|
+
del reports[idx]
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def json_file_db_delete_report(self, report_id):
|
|
523
|
+
with open(self.data_file_path, "r") as file:
|
|
524
|
+
json_file = json.load(file)
|
|
525
|
+
|
|
526
|
+
reports = json_file["map"].get("reports", [])
|
|
527
|
+
idx = next((i for i, r in enumerate(reports) if r.get("uuid") == report_id), None)
|
|
528
|
+
if idx is None:
|
|
529
|
+
raise ValueError(f"Report with uuid {report_id} not found")
|
|
530
|
+
|
|
531
|
+
del reports[idx]
|
|
532
|
+
json_file["map"]["reports"] = reports
|
|
533
|
+
|
|
534
|
+
json_file_atomic_dump(json_file, self.data_file_path)
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
def delete_report(db, report_id):
|
|
538
|
+
return globals()[f"{db.module_name}_delete_report"](db, report_id)
|
|
539
|
+
|
|
540
|
+
|
|
107
541
|
# TODO extension function should be replaced with simple extend which would take a db plugin
|
|
108
542
|
# it could look like that:
|
|
109
543
|
# `db.extend(goodmap_db_plugin)` in plugin all those functions would be organized
|
|
@@ -113,4 +547,18 @@ def extend_db_with_goodmap_queries(db, location_model):
|
|
|
113
547
|
db.extend("get_data", get_data(db))
|
|
114
548
|
db.extend("get_locations", get_locations(db, location_model))
|
|
115
549
|
db.extend("get_location", get_location(db, location_model))
|
|
550
|
+
db.extend("add_location", partial(add_location, location_model=location_model))
|
|
551
|
+
db.extend("update_location", partial(update_location, location_model=location_model))
|
|
552
|
+
db.extend("delete_location", delete_location)
|
|
553
|
+
if db.module_name in ("json_db", "json_file_db"):
|
|
554
|
+
db.extend("add_suggestion", add_suggestion)
|
|
555
|
+
db.extend("get_suggestions", get_suggestions(db))
|
|
556
|
+
db.extend("get_suggestion", get_suggestion(db))
|
|
557
|
+
db.extend("update_suggestion", update_suggestion)
|
|
558
|
+
db.extend("delete_suggestion", delete_suggestion)
|
|
559
|
+
db.extend("add_report", add_report)
|
|
560
|
+
db.extend("get_reports", get_reports(db))
|
|
561
|
+
db.extend("get_report", get_report(db))
|
|
562
|
+
db.extend("update_report", update_report)
|
|
563
|
+
db.extend("delete_report", delete_report)
|
|
116
564
|
return db
|
goodmap/goodmap.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
|
-
from flask import Blueprint, render_template
|
|
3
|
+
from flask import Blueprint, redirect, render_template, session
|
|
4
4
|
from flask_wtf.csrf import CSRFProtect, generate_csrf
|
|
5
5
|
from platzky import platzky
|
|
6
6
|
from platzky.config import Config, languages_dict
|
|
7
|
+
from platzky.models import CmsModule
|
|
7
8
|
|
|
8
9
|
from goodmap.core_api import core_pages
|
|
9
10
|
from goodmap.data_models.location import create_location_model
|
|
@@ -48,5 +49,30 @@ def create_app_from_config(config: Config) -> platzky.Engine:
|
|
|
48
49
|
def index():
|
|
49
50
|
return render_template("map.html", feature_flags=config.feature_flags)
|
|
50
51
|
|
|
52
|
+
@goodmap.route("/goodmap-admin")
|
|
53
|
+
def admin():
|
|
54
|
+
user = session.get("user", None)
|
|
55
|
+
if not user:
|
|
56
|
+
return redirect("/admin")
|
|
57
|
+
|
|
58
|
+
# TODO: This should be replaced with a proper user authentication check,
|
|
59
|
+
# cms_modules should be passed from the app
|
|
60
|
+
return render_template(
|
|
61
|
+
"goodmap-admin.html",
|
|
62
|
+
feature_flags=config.feature_flags,
|
|
63
|
+
user=user,
|
|
64
|
+
cms_modules=app.cms_modules,
|
|
65
|
+
)
|
|
66
|
+
|
|
51
67
|
app.register_blueprint(goodmap)
|
|
68
|
+
goodmap_cms_modules = CmsModule.model_validate(
|
|
69
|
+
{
|
|
70
|
+
"name": "Map admin panel",
|
|
71
|
+
"description": "Admin panel for managing map data",
|
|
72
|
+
"slug": "goodmap-admin",
|
|
73
|
+
"template": "goodmap-admin.html",
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
app.add_cms_module(goodmap_cms_modules)
|
|
77
|
+
|
|
52
78
|
return app
|