Skip to content

Commit bdee5c1

Browse files
better ngo validation (#375)
* better ngo validation * Save the NGO locality * fix requirements * Split the NGO description into paragraphs * texts --------- Co-authored-by: Daniel Ursache Dogariu <contact@danniel.net>
1 parent ca2e0cc commit bdee5c1

File tree

6 files changed

+84
-68
lines changed

6 files changed

+84
-68
lines changed

backend/donations/forms/ngo_account.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
from localflavor.ro.forms import ROCIFField
66

77
from donations.common.validation.phone_number import validate_phone_number
8+
from donations.models.ngos import Ngo
89

910

1011
class NgoPresentationForm(forms.Form):
1112
is_accepting_forms = forms.BooleanField(label=_("Is accepting forms"), required=False)
1213

1314
name = forms.CharField(label=_("Name"), max_length=255, required=True)
14-
cif = ROCIFField(label=_("CUI/CIF"), required=True)
15+
if settings.ENABLE_FULL_CUI_VALIDATION:
16+
cif = ROCIFField(label=_("CUI/CIF"), required=True)
17+
else:
18+
cif = forms.CharField(label=_("CUI/CIF"), max_length=10, min_length=2, required=True)
19+
1520
logo = forms.ImageField(label=_("Logo"), required=False)
1621
website = forms.URLField(label=_("Website"), required=False)
1722

@@ -22,12 +27,13 @@ class NgoPresentationForm(forms.Form):
2227
display_phone = forms.BooleanField(label=_("Display phone"), required=False)
2328

2429
address = forms.CharField(label=_("Address"), max_length=255, required=True)
25-
locality = forms.CharField(label=_("Locality"), max_length=255, required=False)
30+
locality = forms.CharField(label=_("Locality"), max_length=100, required=False)
2631
county = forms.ChoiceField(label=_("County"), choices=settings.FORM_COUNTIES_CHOICES, required=True)
2732
active_region = forms.ChoiceField(label=_("Active region"), choices=settings.FORM_COUNTIES_CHOICES, required=True)
2833

2934
def __init__(self, *args, **kwargs):
3035
is_fully_editable = kwargs.pop("is_fully_editable", True)
36+
self.ngo = kwargs.pop("ngo")
3137

3238
super().__init__(*args, **kwargs)
3339

@@ -47,6 +53,14 @@ def __init__(self, *args, **kwargs):
4753
for field_name in ngohub_fields:
4854
self.fields[field_name].required = False
4955

56+
def clean_cif(self):
57+
cif = self.cleaned_data.get("cif")
58+
59+
if Ngo.objects.filter(registration_number=cif).exclude(pk=self.ngo.pk).exists():
60+
raise forms.ValidationError(_("An NGO with this CUI/CIF already exists."))
61+
62+
return cif
63+
5064
def clean_logo(self):
5165
logo = self.cleaned_data.get("logo")
5266
if not logo:

backend/donations/views/ngo_account.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def post(self, request, *args, **kwargs):
164164

165165
is_fully_editable = ngo.ngohub_org_id is None
166166

167-
form = NgoPresentationForm(post, files=request.FILES, is_fully_editable=is_fully_editable)
167+
form = NgoPresentationForm(post, files=request.FILES, is_fully_editable=is_fully_editable, ngo=ngo)
168168
if not form.is_valid():
169169
messages.error(request, _("There are some errors on the presentation form."))
170170
context.update({"ngo_presentation": form})
@@ -193,6 +193,7 @@ def post(self, request, *args, **kwargs):
193193
ngo.website = form.cleaned_data["website"]
194194
ngo.address = form.cleaned_data["address"]
195195
ngo.county = form.cleaned_data["county"]
196+
ngo.locality = form.cleaned_data["locality"]
196197
ngo.active_region = form.cleaned_data["active_region"]
197198

198199
ngo.is_accepting_forms = form.cleaned_data["is_accepting_forms"]

backend/locale/ro/LC_MESSAGES/django.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,15 +2351,15 @@ msgstr "Email de contact al organizației"
23512351

23522352
#: templates/v2/ngo-account/my-organization/ngo-presentation.html:101
23532353
msgid "Display e-mail in the profile"
2354-
msgstr "Afișează email-ul în profil"
2354+
msgstr "Afișează email-ul pe pagina publică"
23552355

23562356
#: templates/v2/ngo-account/my-organization/ngo-presentation.html:110
23572357
msgid "Organization contact phone"
23582358
msgstr "Telefon de contact al organizației"
23592359

23602360
#: templates/v2/ngo-account/my-organization/ngo-presentation.html:115
23612361
msgid "Display phone in the profile"
2362-
msgstr "Afișează telefonul în profil"
2362+
msgstr "Afișează telefonul pe pagina publică"
23632363

23642364
#: templates/v2/ngo-account/my-organization/ngo-presentation.html:124
23652365
msgid "Organization address"

backend/redirectioneaza/settings/app_configs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
except IndexError:
122122
pass
123123

124-
FORM_COUNTIES_CHOICES = [(county, county) for county in FORM_COUNTIES]
124+
EXTENDED_FORM_COUNTIES = [1, 2, 3, 4, 5, 6] + FORM_COUNTIES
125+
FORM_COUNTIES_CHOICES = [(county, county) for county in EXTENDED_FORM_COUNTIES]
125126

126127
FORM_COUNTIES_NATIONAL = deepcopy(FORM_COUNTIES)
127128
FORM_COUNTIES_NATIONAL.insert(0, "Național")

0 commit comments

Comments
 (0)