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 @@