Skip to content

Commit

Permalink
Refactor donations app
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Dec 6, 2024
1 parent d1e7e7d commit ba68370
Show file tree
Hide file tree
Showing 31 changed files with 319 additions and 290 deletions.
3 changes: 2 additions & 1 deletion backend/donations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from redirectioneaza.common.admin import HasNgoFilter
from users.models import User

from .models.donors import Donor
from .models.jobs import Job, JobStatusChoices
from .models.main import Donor, Ngo
from .models.ngos import Ngo
from .workers.update_organization import update_organization

logger = logging.getLogger(__name__)
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions backend/donations/common/models_hashing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import hashlib

from django.conf import settings


def hash_id_secret(prefix: str, pk: int) -> str:
return hashlib.blake2s(
f"{prefix}-{pk}-{settings.SECRET_KEY_HASH}".encode(), digest_size=16, usedforsecurity=False
).hexdigest()
2 changes: 1 addition & 1 deletion backend/donations/forms/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.utils.translation import gettext_lazy as _
from localflavor.ro.forms import ROCNPField

from donations.models.main import Donor
from donations.models.donors import Donor


class DonorInputForm(forms.ModelForm):
Expand Down
3 changes: 2 additions & 1 deletion backend/donations/management/commands/generate_donations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from faker import Faker
from localflavor.ro.ro_counties import COUNTIES_CHOICES

from donations.models.main import Donor, Ngo
from donations.models.donors import Donor
from donations.models.ngos import Ngo
from donations.pdf import create_pdf

fake = Faker("ro_RO")
Expand Down
2 changes: 1 addition & 1 deletion backend/donations/management/commands/generate_orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from faker import Faker
from localflavor.ro.ro_counties import COUNTIES_CHOICES

from donations.models.main import Ngo
from donations.models.ngos import Ngo

fake = Faker("ro_RO")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.core.exceptions import ValidationError
from django.core.management import BaseCommand

from donations.models.main import (
from donations.models.ngos import (
Ngo,
REGISTRATION_NUMBER_REGEX,
REGISTRATION_NUMBER_REGEX_SANS_VAT,
Expand Down
28 changes: 15 additions & 13 deletions backend/donations/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Generated by Django 4.2.9 on 2024-02-02 12:06

from django.db import migrations, models
import django.db.models.deletion
import django.db.models.functions.text
import donations.models.main
import functools

import django.db.models.functions.text
from django.db import migrations, models

import donations.models.donors
import donations.models.ngos


class Migration(migrations.Migration):

Expand Down Expand Up @@ -64,7 +66,7 @@ class Migration(migrations.Migration):
models.FileField(
blank=True,
upload_to=functools.partial(
donations.models.main.year_ngo_donor_directory_path, *("donation-forms",), **{}
donations.models.donors.year_ngo_donor_directory_path, *("donation-forms",), **{}
),
verbose_name="PDF file",
),
Expand Down Expand Up @@ -103,7 +105,7 @@ class Migration(migrations.Migration):
models.SlugField(
max_length=100,
unique=True,
validators=[donations.models.main.ngo_slug_validator],
validators=[donations.models.ngos.ngo_slug_validator],
verbose_name="slug",
),
),
Expand All @@ -114,8 +116,8 @@ class Migration(migrations.Migration):
"logo",
models.ImageField(
blank=True,
storage=donations.models.main.select_public_storage,
upload_to=functools.partial(donations.models.main.ngo_directory_path, *("logos",), **{}),
storage=donations.models.ngos.select_public_storage,
upload_to=functools.partial(donations.models.ngos.ngo_directory_path, *("logos",), **{}),
verbose_name="logo",
),
),
Expand All @@ -124,8 +126,8 @@ class Migration(migrations.Migration):
"image",
models.ImageField(
blank=True,
storage=donations.models.main.select_public_storage,
upload_to=functools.partial(donations.models.main.ngo_directory_path, *("images",), **{}),
storage=donations.models.ngos.select_public_storage,
upload_to=functools.partial(donations.models.ngos.ngo_directory_path, *("images",), **{}),
verbose_name="image",
),
),
Expand All @@ -136,7 +138,7 @@ class Migration(migrations.Migration):
db_index=True,
max_length=100,
unique=True,
validators=[donations.models.main.ngo_id_number_validator],
validators=[donations.models.ngos.ngo_id_number_validator],
verbose_name="registration number",
),
),
Expand Down Expand Up @@ -173,9 +175,9 @@ class Migration(migrations.Migration):
"prefilled_form",
models.FileField(
blank=True,
storage=donations.models.main.select_public_storage,
storage=donations.models.ngos.select_public_storage,
upload_to=functools.partial(
donations.models.main.year_ngo_directory_path, *("ngo-forms",), **{}
donations.models.ngos.year_ngo_directory_path, *("ngo-forms",), **{}
),
verbose_name="form with prefilled ngo data",
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Django 4.2.10 on 2024-02-19 08:54

from django.db import migrations, models
import donations.models.main

import donations.models.ngos


class Migration(migrations.Migration):
Expand All @@ -20,7 +21,7 @@ class Migration(migrations.Migration):
model_name="ngo",
name="slug",
field=models.SlugField(
max_length=150, unique=True, validators=[donations.models.main.ngo_slug_validator], verbose_name="slug"
max_length=150, unique=True, validators=[donations.models.ngos.ngo_slug_validator], verbose_name="slug"
),
),
]
Loading

0 comments on commit ba68370

Please sign in to comment.