Skip to content

Commit

Permalink
Fix new ngo form
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Jan 5, 2024
1 parent 6afbe86 commit 916a249
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
27 changes: 27 additions & 0 deletions backend/donations/admin.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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",)
11 changes: 7 additions & 4 deletions backend/donations/views/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions backend/templates/v1/components/county.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<select class="form-control" id="county" name="county" required x-moz-errormessage="Județul este obligatoriu" title="Județul este obligatoriu">
<select class="form-control" id="{{ identifier }}" name="{{ identifier }}" required x-moz-errormessage="Județul este obligatoriu" title="Județul este obligatoriu">
<option value="" class="select-placeholder">Județul</option>
<optgroup label="București">
{% for number in range(1, 7) %}
<option value="{{ number }}" {{ "selected" if number == county }}>Sector {{ number }}</option>
<option value="{{ number }}" {{ "selected" if number|string == county }}>Sector {{ number }}</option>
{% endfor %}
</optgroup>
{% for county_name in counties %}
Expand Down
12 changes: 10 additions & 2 deletions backend/templates/v1/components/ngo-details-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@
<input class="form-control" type="text" name="ong-adresa" placeholder="Adresa Asociației" value="{{ ngo.address if ngo }}" required maxlength="100" />
</div>
<div class="col-xs-4">
{% include "components/county.html" %}
{% with identifier="ong-judet" %}
{% with county=ngo.county if ngo %}
{% include "components/county.html" %}
{% endwith %}
{% endwith %}
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<label for="ong-activitate">În ce regiune iși desfășoară ONG-ul activitatea?</label>
{% include "components/county.html" %}
{% with identifier="ong-activitate" %}
{% with county=ngo.active_region if ngo %}
{% include "components/county.html" %}
{% endwith %}
{% endwith %}
</div>
</div>
<div class="form-group choose-url-group">
Expand Down
6 changes: 5 additions & 1 deletion backend/templates/v1/twopercent.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ <h3 class="donation-page-subtitle">Pasul 1. Completează și descarcă formularu

<div class="form-group">
<div class="col-xs-6">
{% include "components/county.html" %}
{% with identifier="county" %}
{% with county=county %}
{% include "components/county.html" %}
{% endwith %}
{% endwith %}
</div>
<div class="col-xs-6">
<input type="text" class="form-control text-capitalize" id="city" value="{{ city if city }}" name="city" placeholder="Localitate" x-moz-errormessage="Orașul este obligatoriu" maxlength="40" required />
Expand Down

0 comments on commit 916a249

Please sign in to comment.