feat: Add basic user data export
This commit is contained in:
		@@ -37,7 +37,7 @@
 | 
				
			|||||||
                <h2>{% trans 'Profil verwalten' %}</h2>
 | 
					                <h2>{% trans 'Profil verwalten' %}</h2>
 | 
				
			||||||
                <p>
 | 
					                <p>
 | 
				
			||||||
                    <a class="btn2" href="{% url 'password_change' %}">{% translate "Change password" %}</a>
 | 
					                    <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>
 | 
					                </p>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            </p>
 | 
					            </p>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,6 +54,7 @@ urlpatterns = [
 | 
				
			|||||||
    # ex: user/1
 | 
					    # ex: user/1
 | 
				
			||||||
    path("user/<int:user_id>/", views.user_detail, name="user-detail"),
 | 
					    path("user/<int:user_id>/", views.user_detail, name="user-detail"),
 | 
				
			||||||
    path("user/me/", views.my_profile, name="user-me"),
 | 
					    path("user/me/", views.my_profile, name="user-me"),
 | 
				
			||||||
 | 
					    path('user/me/export/', views.export_own_profile, name='user-me-export'),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    path('accounts/register/',
 | 
					    path('accounts/register/',
 | 
				
			||||||
         RegistrationView.as_view(
 | 
					         RegistrationView.as_view(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,14 @@
 | 
				
			|||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.http import HttpResponseRedirect, JsonResponse
 | 
					from django.http import HttpResponseRedirect, JsonResponse, HttpResponse
 | 
				
			||||||
from django.shortcuts import render, redirect
 | 
					from django.shortcuts import render, redirect
 | 
				
			||||||
from django.urls import reverse
 | 
					from django.urls import reverse
 | 
				
			||||||
from django.contrib.auth.decorators import login_required
 | 
					from django.contrib.auth.decorators import login_required
 | 
				
			||||||
from django.utils import translation
 | 
					from django.utils import translation
 | 
				
			||||||
from django.core.exceptions import PermissionDenied
 | 
					from django.core.exceptions import PermissionDenied
 | 
				
			||||||
from django.contrib.auth.decorators import user_passes_test
 | 
					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 .mail import mail_admins_new_report
 | 
				
			||||||
from notfellchen import settings
 | 
					from notfellchen import settings
 | 
				
			||||||
@@ -569,3 +571,15 @@ def external_site_warning(request):
 | 
				
			|||||||
def detail_view_rescue_organization(request, rescue_organization_id):
 | 
					def detail_view_rescue_organization(request, rescue_organization_id):
 | 
				
			||||||
    org = RescueOrganization.objects.get(pk=rescue_organization_id)
 | 
					    org = RescueOrganization.objects.get(pk=rescue_organization_id)
 | 
				
			||||||
    return render(request, 'fellchensammlung/details/detail-rescue-organization.html', context={"org": org})
 | 
					    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")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user