feat: Add basic user data export

This commit is contained in:
moanos [he/him] 2024-11-18 23:01:27 +01:00
parent f1c79a5f94
commit 08e20e1875
3 changed files with 17 additions and 2 deletions

View File

@ -37,7 +37,7 @@
<h2>{% trans 'Profil verwalten' %}</h2>
<p>
<a class="btn2" href="{% url 'password_change' %}">{% translate "Change password" %}</a>
<a class="btn2" href="{% url 'index' %}">{% translate "Daten exportieren" %}</a>
<a class="btn2" href="{% url 'user-me-export' %}">{% translate "Daten exportieren" %}</a>
</p>
</div>
</p>

View File

@ -54,6 +54,7 @@ urlpatterns = [
# ex: user/1
path("user/<int:user_id>/", views.user_detail, name="user-detail"),
path("user/me/", views.my_profile, name="user-me"),
path('user/me/export/', views.export_own_profile, name='user-me-export'),
path('accounts/register/',
RegistrationView.as_view(

View File

@ -1,12 +1,14 @@
import logging
from django.http import HttpResponseRedirect, JsonResponse
from django.http import HttpResponseRedirect, JsonResponse, HttpResponse
from django.shortcuts import render, redirect
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from django.utils import translation
from django.core.exceptions import PermissionDenied
from django.contrib.auth.decorators import user_passes_test
from django.core.serializers import serialize
import json
from .mail import mail_admins_new_report
from notfellchen import settings
@ -569,3 +571,15 @@ def external_site_warning(request):
def detail_view_rescue_organization(request, rescue_organization_id):
org = RescueOrganization.objects.get(pk=rescue_organization_id)
return render(request, 'fellchensammlung/details/detail-rescue-organization.html', context={"org": org})
def export_own_profile(request):
user = request.user
ANs = AdoptionNotice.objects.filter(owner=user)
user_as_json = serialize('json', [user])
user_editable = json.loads(user_as_json)
user_editable[0]["fields"]["password"] = "Password hash redacted for security reasons"
user_as_json = json.dumps(user_editable)
ANs_as_json = serialize('json', ANs)
full_json = f"{user_as_json}, {ANs_as_json}"
return HttpResponse(full_json, content_type="application/json")