from georeport.models import Category, Image, Report
-from django import forms
from .minio import get_url
-import pdb
-from django.utils.safestring import mark_safe
# TODO: reorder
class CategoryUserInline(admin.TabularInline):
- model = Category.users.through
+ model = Category.users.through # type:ignore through is not known
extra = 0
can_delete = False
class CategoryGroupInline(admin.TabularInline):
- model = Category.groups.through
+ model = Category.groups.through # type:ignore through is not known
extra = 0
can_delete = False
--- /dev/null
+# Copyright: (c) 2025, Jörn Menne <jmenne@posteo.de>
+# GNU General Public License v3.0 (see LICSENE or https://www.gnu.org/license/gpl-3.0.md)
+import json
+from .models import Category
+import os
+
+# TODO: User and groups are currently not exported
+# This has to be added to work correctly.
+
+
+def write_categories_to_file(path="cat.json"):
+ """
+ Creates a json file, which contains all
+ necessary information to repopulate the database from scratch
+ with the categories.
+
+ Arguments:
+ path: The path to the json file
+ """
+ categories = Category.objects.all() # type:ignore
+
+ data = []
+ for cat in categories:
+ catData = {}
+ catData["name"] = cat.name
+ catData["parent"] = cat.parent.name if cat.parent else ""
+
+ data.append(catData)
+
+ jsondata = json.dumps(data, indent=4)
+ with open(path, "w") as file:
+ file.write(jsondata)
+
+
+def populateCategories(path="cat.json"):
+ """
+ populates a database with categories provided by a json-file.
+ It works best, if the json was created by the function write_categories_to_file.
+
+ Arguments:
+ path: The path to the json-file
+ """
+
+ if not os.path.exists(path):
+ print("File not found")
+ return
+ with open(path, "r") as file:
+ data = json.load(file)
+ for x in data:
+ cat = Category(name=x["name"])
+ if x["parent"] != "":
+ cat.parent = Category.objects.filter(name=x["parent"]).first() # type: ignore Attribute object is not known
+ cat.save()
from django.contrib.auth.models import Group, User
from typing import override
-from django.forms import DecimalField
# Create your models here.
def key(value, arg):
+ """
+ Custom templatetag to access dictionaries in templates
+ """
return value[arg]
+# Copyright: (c) 2025, Jörn Menne <jmenne@posteo.de>
+# GNU General Public License v3.0 (see LICSENE or https://www.gnu.org/license/gpl-3.0.md)
+
from . import views
from django.urls import path
+
# TODO: Adjust to open311
# /services: -> List with Categories <- GET ✅
# /sercvice/{id} -> single Category <- GET ✅
A view takes a request and creates a respond for the request.
"""
-import os
-import shutil
from base64 import urlsafe_b64decode
from Crypto.Cipher import ChaCha20
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.views.decorators.http import require_GET, require_http_methods, require_safe
-from minio import Minio
-
-from pinpoint_report.settings import DEFAULT_FROM_EMAIL
from .admin import send_update
-from .forms import ImageForm, ReportForm
+from .forms import ReportForm
from .models import Category, Report
from .minio import handle_file_uploads, get_url
subject=subject,
message=message,
recipient_list=recipient_list,
- from_email=DEFAULT_FROM_EMAIL,
+ from_email=settings.DEFAULT_FROM_EMAIL,
fail_silently=True,
)
subject=subject,
message=message,
recipient_list=recipient_list,
- from_email=DEFAULT_FROM_EMAIL,
+ from_email=settings.DEFAULT_FROM_EMAIL,
fail_silently=True,
)