diff --git a/backend/donations/migrations/0002_alter_ngo_form_url.py b/backend/donations/migrations/0002_alter_ngo_form_url.py new file mode 100644 index 00000000..cfaf8239 --- /dev/null +++ b/backend/donations/migrations/0002_alter_ngo_form_url.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.8 on 2024-01-03 16:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("donations", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="ngo", + name="form_url", + field=models.CharField(blank=True, default="", max_length=255, verbose_name="form url"), + ), + ] diff --git a/backend/donations/models.py b/backend/donations/models.py index f0ccde92..db1f0eb4 100644 --- a/backend/donations/models.py +++ b/backend/donations/models.py @@ -70,17 +70,12 @@ class Ngo(models.Model): is_active = models.BooleanField(verbose_name=_("is active"), db_index=True, default=True) # url to the ngo's 2% form, that contains only the ngo's details - form_url = models.URLField(verbose_name=_("form url"), blank=True, null=False, default="", max_length=255) - - # TODO: Seems unused - # tags = models.CharField(verbose_name=_("tags"),max_length=255, db_index=True, blank=True) + form_url = models.CharField( + verbose_name=_("form url"), blank=True, null=False, default="", max_length=255, unique=True + ) date_created = models.DateTimeField(verbose_name=_("date created"), db_index=True, auto_now_add=timezone.now) - # does the NGO allow the donor to upload the signed document - # TODO: This seems unused - # allow_upload = models.BooleanField(verbose_name=_("allow upload"),db_index=True, default=False) - class Meta: verbose_name = _("NGO") verbose_name_plural = _("NGOs") diff --git a/backend/donations/views/my_account.py b/backend/donations/views/my_account.py index b9a6c079..05a4b24d 100644 --- a/backend/donations/views/my_account.py +++ b/backend/donations/views/my_account.py @@ -1,7 +1,8 @@ from django.contrib.auth.decorators import login_required -from django.utils.decorators import method_decorator from django.shortcuts import render +from django.utils.decorators import method_decorator +from ..models import Ngo from .base import AccountHandler @@ -16,11 +17,59 @@ class MyAccountHandler(AccountHandler): def get(self, request, *args, **kwargs): context = { "user": request.user, - # TODO: - "ngo": None, + "ngo": request.user.ngo if request.user.ngo else None, } return render(request, self.template_name, context) class NgoDetailsHandler(AccountHandler): - pass + template_name = "ngo/ngo-details.html" + + def get(self, request, *args, **kwargs): + context = { + "user": request.user, + "ngo": request.user.ngo if request.user.ngo else None, + } + + return render(request, self.template_name, context) + + def post(self, request, *args, **kwargs): + post = request.POST + + ngo: Ngo = request.user.ngo + + if not ngo: + 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") + ngo.email = post.get("ong-email") + ngo.website = post.get("ong-website") + ngo.address = post.get("ong-adresa") + ngo.county = post.get("ong-judet") + ngo.active_region = post.get("ong-activitate") + ngo.form_url = post.get("ong-url") + ngo.registration_number = post.get("ong-cif") + ngo.bank_account = post.get("ong-cont") + ngo.has_special_status = True if post.get("special-status") == "on" else False + ngo.is_accepting_forms = True if post.get("accepts-forms") == "on" else False + ngo.logo_url = post.get("ong-logo-url", "") + ngo.image_url = post.get("ong-logo") + ngo.other_emails = "" + + ngo.save() + + context = { + "user": request.user, + "ngo": request.user.ngo if request.user.ngo else None, + } + + return render(request, self.template_name, context) diff --git a/backend/templates/v1/all-ngos.html b/backend/templates/v1/all-ngos.html index a80adb3a..ee0a8f14 100644 --- a/backend/templates/v1/all-ngos.html +++ b/backend/templates/v1/all-ngos.html @@ -24,7 +24,7 @@

Asociații pentru care poți redirecționa 3.5%

- {% set logo = ngo.logo if ngo.logo else DEFAULT_NGO_LOGO %} + {% set logo = ngo.logo_url if ngo.logo_url else DEFAULT_NGO_LOGO %} @@ -48,4 +48,4 @@

Asociații pentru care poți redirecționa 3.5%

{% block scripts %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/backend/templates/v1/components/ngo-details-form.html b/backend/templates/v1/components/ngo-details-form.html index cffa6afd..f4ada6ca 100644 --- a/backend/templates/v1/components/ngo-details-form.html +++ b/backend/templates/v1/components/ngo-details-form.html @@ -5,48 +5,48 @@ Datele asociației:
- +
-
- +
- +
- +
- +
- - - + + {% for number in range(1, 7) %} {% endfor %} @@ -63,7 +63,7 @@ +
-
+
@@ -92,40 +92,40 @@
- +
- +
- +
- +
- +
{% if is_admin %}
Admin - +
@@ -159,7 +159,7 @@

- Daca vrei sa schimbi cine detine aces ONG, adauga mai jos adresa de email a noul cont: + Daca vrei sa schimbi cine deține aces ONG, adaugă mai jos adresa de email a noul cont:

@@ -172,7 +172,7 @@
- +
diff --git a/backend/templates/v1/components/ngo-header.html b/backend/templates/v1/components/ngo-header.html index d0b6cf1f..c8723e7f 100644 --- a/backend/templates/v1/components/ngo-header.html +++ b/backend/templates/v1/components/ngo-header.html @@ -6,8 +6,8 @@
- {% if ngo.logo %} - + {% if ngo.logo_url %} + {% endif %}
@@ -41,4 +41,4 @@

-
\ No newline at end of file +
diff --git a/backend/templates/v1/index.html b/backend/templates/v1/index.html index 2463ab57..0edad4a0 100644 --- a/backend/templates/v1/index.html +++ b/backend/templates/v1/index.html @@ -67,7 +67,7 @@