-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5b5dd6
commit 759a239
Showing
17 changed files
with
569 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django import forms | ||
from django.utils.translation import gettext_lazy as _ | ||
from localflavor.ro.forms import ROCNPField | ||
|
||
from donations.models import Donor | ||
|
||
|
||
class DonorInputForm(forms.ModelForm): | ||
street = forms.CharField(max_length=100, label=_("Strada")) | ||
street_number = forms.CharField(max_length=10, label=_("Număr")) | ||
block = forms.CharField(max_length=10, label=_("Bloc"), required=False) | ||
entrance = forms.CharField(max_length=10, label=_("Scara"), required=False) | ||
floor = forms.CharField(max_length=10, label=_("Etaj"), required=False) | ||
apartment = forms.CharField(max_length=10, label=_("Apartament"), required=False) | ||
terms = forms.BooleanField(label=_("Terms"), required=True) | ||
|
||
ngo_id = forms.IntegerField(widget=forms.HiddenInput(), required=False) | ||
personal_identifier = ROCNPField(label="CNP") | ||
|
||
class Meta: | ||
model = Donor | ||
fields = [ | ||
"first_name", | ||
"last_name", | ||
"initial", | ||
"city", | ||
"county", | ||
"phone", | ||
"email", | ||
"is_anonymous", | ||
"two_years", | ||
] | ||
|
||
@staticmethod | ||
def _clean_checkbox(value): | ||
if value == "on": | ||
return True | ||
return False | ||
|
||
def clean_is_anonymous(self): | ||
return self._clean_checkbox(self.cleaned_data["is_anonymous"]) | ||
|
||
def clean_two_years(self): | ||
return self._clean_checkbox(self.cleaned_data["two_years"]) | ||
|
||
def clean_terms(self): | ||
return self._clean_checkbox(self.cleaned_data["terms"]) |
30 changes: 30 additions & 0 deletions
30
backend/donations/migrations/0003_donor_initial_donor_personal_identifier_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 4.2.9 on 2024-01-04 13:58 | ||
|
||
from django.db import migrations, models | ||
import django_cryptography.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("donations", "0002_alter_ngo_form_url"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="donor", | ||
name="initial", | ||
field=models.CharField(blank=True, default="", max_length=5, verbose_name="initials"), | ||
), | ||
migrations.AddField( | ||
model_name="donor", | ||
name="personal_identifier", | ||
field=django_cryptography.fields.encrypt( | ||
models.CharField(blank=True, default="", max_length=13, verbose_name="CNP") | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="ngo", | ||
name="form_url", | ||
field=models.CharField(blank=True, default="", max_length=255, unique=True, verbose_name="form url"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,98 @@ | ||
from django.conf import settings | ||
from django.http import Http404 | ||
from django.shortcuts import redirect, render | ||
from django.urls import reverse | ||
|
||
from .base import BaseHandler | ||
from ..forms import DonorInputForm | ||
from ..models import Donor, Ngo | ||
|
||
|
||
class DonationSucces(BaseHandler): | ||
pass | ||
template_name = "succes.html" | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
ngo = Ngo.objects.get(form_url=kwargs["ngo_url"].lower()) | ||
context["ngo"] = ngo | ||
return context | ||
|
||
def get(self, request, *args, **kwargs): | ||
context = self.get_context_data(**kwargs) | ||
|
||
return render(self.request, self.template_name, context) | ||
|
||
|
||
class FormSignature(BaseHandler): | ||
pass | ||
template_name = "signature.html" | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
ngo = Ngo.objects.get(form_url=kwargs["ngo_url"].lower()) | ||
context["ngo"] = ngo | ||
return context | ||
|
||
def get(self, request, *args, **kwargs): | ||
context = self.get_context_data(**kwargs) | ||
|
||
return render(self.request, self.template_name, context) | ||
|
||
class NgoHandler(BaseHandler): | ||
pass | ||
def post(self, request, *args, **kwargs): | ||
context = self.get_context_data(**kwargs) | ||
|
||
return redirect(reverse("ngo-twopercent-success", kwargs={"ngo_url": context["ngo_url"]})) | ||
|
||
|
||
class TwoPercentHandler(BaseHandler): | ||
pass | ||
def get_context_data(self, request, **kwargs): | ||
ngo_url: str = kwargs["ngo_url"].lower() | ||
if not Ngo.objects.filter(form_url=ngo_url).exists(): | ||
raise Http404("Nu exista o asociație cu acest URL") | ||
|
||
ngo = Ngo.objects.get(form_url=ngo_url) | ||
form_counties = settings.FORM_COUNTIES | ||
|
||
context = {"is_authenticated": False, "ngo_url": ngo_url, "ngo": ngo, "counties": form_counties} | ||
|
||
if request.user.is_authenticated and request.user.ngo == ngo: | ||
context["is_authenticated"] = True | ||
return context | ||
|
||
context["limit"] = settings.DONATIONS_LIMIT | ||
context["can_donate"] = True | ||
|
||
return context | ||
|
||
def get(self, request, *args, **kwargs): | ||
context = self.get_context_data(request, **kwargs) | ||
|
||
template = "twopercent.html" | ||
|
||
if context["is_authenticated"]: | ||
template = "ngo/ngo-details.html" | ||
|
||
return render(request, template, context) | ||
|
||
def post(self, request, *args, **kwargs): | ||
post = request.POST | ||
context = self.get_context_data(request, **kwargs) | ||
|
||
form = DonorInputForm(post) | ||
if not form.is_valid(): | ||
context.update(form.cleaned_data) | ||
context["errors"] = {"fields": list(form.errors.values())} | ||
|
||
return render(request, "twopercent.html", context) | ||
|
||
new_donor: Donor = form.save(commit=False) | ||
new_donor.ngo = context["ngo"] | ||
|
||
new_donor.save() | ||
|
||
new_donor.pdf_url = self._generate_pdf(form.cleaned_data, context["ngo"]) | ||
|
||
return redirect(reverse("ngo-twopercent-signature", kwargs={"ngo_url": context["ngo_url"]})) | ||
|
||
@staticmethod | ||
def _generate_pdf(donor_data, param): | ||
return "PDF_URL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.