From 916a249edecaa35f4f34b176c67874eba4519a0e Mon Sep 17 00:00:00 2001 From: Tudor Amariei Date: Fri, 5 Jan 2024 14:28:49 +0200 Subject: [PATCH] Fix new ngo form --- backend/donations/admin.py | 27 +++++++++++++++++++ backend/donations/views/my_account.py | 11 +++++--- backend/templates/v1/components/county.html | 4 +-- .../v1/components/ngo-details-form.html | 12 +++++++-- backend/templates/v1/twopercent.html | 6 ++++- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/backend/donations/admin.py b/backend/donations/admin.py index dfca61bd..e947e580 100644 --- a/backend/donations/admin.py +++ b/backend/donations/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from .models import Ngo, Donor +from django.utils.translation import gettext_lazy as _ @admin.register(Ngo) @@ -14,3 +15,29 @@ class DonorAdmin(admin.ModelAdmin): list_display = ("id", "email", "first_name", "last_name", "ngo") list_display_links = ("email",) list_filter = ("date_created",) + + exclude = ("personal_identifier",) + + fieldsets = ( + ( + _("NGO"), + {"fields": ("ngo",)}, + ), + ( + _("Identity"), + {"fields": ("first_name", "last_name", "initial", "county", "city", "email", "phone")}, + ), + ( + _("Info"), + {"fields": ("is_anonymous", "income_type", "two_years")}, + ), + ( + _("File"), + {"fields": ("pdf_url", "filename", "has_signed")}, + ), + ( + _("Date"), + {"fields": ("date_created",)}, + ), + ) + readonly_fields = ("date_created",) diff --git a/backend/donations/views/my_account.py b/backend/donations/views/my_account.py index 74efe0e9..79c9a438 100644 --- a/backend/donations/views/my_account.py +++ b/backend/donations/views/my_account.py @@ -79,16 +79,15 @@ def post(self, request, *args, **kwargs): ngo: Ngo = request.user.ngo + is_new_ngo = False if not ngo: + is_new_ngo = True + ngo = Ngo() - ngo.save() ngo.is_verified = False ngo.is_active = True - request.user.ngo = ngo - request.user.save() - ngo.name = post.get("ong-nume") ngo.description = post.get("ong-descriere") ngo.phone = post.get("ong-tel") @@ -111,6 +110,10 @@ def post(self, request, *args, **kwargs): ngo.save() + if is_new_ngo: + request.user.ngo = ngo + request.user.save() + context = { "user": request.user, "ngo": request.user.ngo if request.user.ngo else None, diff --git a/backend/templates/v1/components/county.html b/backend/templates/v1/components/county.html index ca300a8b..31675706 100644 --- a/backend/templates/v1/components/county.html +++ b/backend/templates/v1/components/county.html @@ -1,8 +1,8 @@ - {% for number in range(1, 7) %} - + {% endfor %} {% for county_name in counties %} diff --git a/backend/templates/v1/components/ngo-details-form.html b/backend/templates/v1/components/ngo-details-form.html index dcb2e47e..62c393be 100644 --- a/backend/templates/v1/components/ngo-details-form.html +++ b/backend/templates/v1/components/ngo-details-form.html @@ -43,13 +43,21 @@
- {% include "components/county.html" %} + {% with identifier="ong-judet" %} + {% with county=ngo.county if ngo %} + {% include "components/county.html" %} + {% endwith %} + {% endwith %}
- {% include "components/county.html" %} + {% with identifier="ong-activitate" %} + {% with county=ngo.active_region if ngo %} + {% include "components/county.html" %} + {% endwith %} + {% endwith %}
diff --git a/backend/templates/v1/twopercent.html b/backend/templates/v1/twopercent.html index b9c701b8..23df1f79 100644 --- a/backend/templates/v1/twopercent.html +++ b/backend/templates/v1/twopercent.html @@ -124,7 +124,11 @@

Pasul 1. Completează și descarcă formularu
- {% include "components/county.html" %} + {% with identifier="county" %} + {% with county=county %} + {% include "components/county.html" %} + {% endwith %} + {% endwith %}