Skip to content

Commit

Permalink
Fix migrations and model changes
Browse files Browse the repository at this point in the history
- redo all migrations
- change Ngo, Donor imports to use the right source
  • Loading branch information
tudoramariei committed Jan 27, 2024
1 parent a9db710 commit 9685d36
Show file tree
Hide file tree
Showing 25 changed files with 201 additions and 506 deletions.
2 changes: 1 addition & 1 deletion backend/donations/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from .models import Ngo, Donor
from .models.main import Ngo, Donor
from django.utils.translation import gettext_lazy as _


Expand Down
2 changes: 1 addition & 1 deletion backend/donations/forms.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 import Donor
from donations.models.main import Donor


class DonorInputForm(forms.ModelForm):
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 import Ngo
from donations.models.main import Ngo

fake = Faker("ro_RO")

Expand Down
313 changes: 121 additions & 192 deletions backend/donations/migrations/0001_initial.py

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions backend/donations/migrations/0002_alter_ngo_form_url.py

This file was deleted.

31 changes: 31 additions & 0 deletions backend/donations/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.9 on 2024-01-27 08:54

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("donations", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="job",
name="owner",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name="owner"
),
),
migrations.AddField(
model_name="donor",
name="ngo",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="donations.ngo", verbose_name="NGO"
),
),
]

This file was deleted.

This file was deleted.

This file was deleted.

23 changes: 0 additions & 23 deletions backend/donations/migrations/0006_donor_pdf_file.py

This file was deleted.

This file was deleted.

10 changes: 8 additions & 2 deletions backend/donations/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
from users.models import User


class JobStatusChoices(models.TextChoices):
NEW = "new", _("New")
ERROR = "error", _("Error")
DONE = "done", _("Done")


class Job(models.Model):
"""Keep track for download jobs"""

Expand All @@ -15,8 +21,8 @@ class Job(models.Model):
verbose_name=_("status"),
blank=False,
null=False,
default="new",
choices=("new", "error", "done"),
default=JobStatusChoices.NEW,
choices=JobStatusChoices.choices,
max_length=5,
db_index=True,
)
Expand Down
15 changes: 11 additions & 4 deletions backend/donations/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ def year_directory_path(subdir, instance, filename) -> str:
return "{0}/{1}/{2}/{3}".format(subdir, timestamp.date().year, instance.pk, filename)


def ngo_identifier_validator(value):
valid_identifier_sample: str = "asociatia-de-exemplu"
def ngo_slug_validator(value):
valid_slug_sample: str = "asociatia-de-exemplu"
error_message = _("%(value)s is not a valid identifier. The identifier must look like %(sample)s") % {
"value": value,
"sample": valid_identifier_sample,
"sample": valid_slug_sample,
}

if not value.islower():
raise ValidationError(error_message)


def ngo_id_number_validator(value):
error_message = _("The ID number must be 8 digits long")
if len(value) != 8:
raise ValidationError(error_message)


class Ngo(models.Model):
# DEFAULT_NGO_LOGO = "https://storage.googleapis.com/redirectioneaza/logo_bw.png"

Expand All @@ -48,7 +54,7 @@ class Ngo(models.Model):
max_length=100,
db_index=True,
unique=True,
validators=[ngo_identifier_validator],
validators=[ngo_slug_validator],
)

name = models.CharField(verbose_name=_("Name"), blank=False, null=False, max_length=100, db_index=True)
Expand Down Expand Up @@ -85,6 +91,7 @@ class Ngo(models.Model):
blank=False,
null=False,
unique=True,
validators=[ngo_id_number_validator],
)

address = models.TextField(verbose_name=_("address"), blank=True, null=False, default="")
Expand Down
2 changes: 1 addition & 1 deletion backend/donations/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from users.models import User
from .base import BaseHandler
from ..models import Ngo, Donor
from ..models.main import Ngo, Donor


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion backend/donations/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.urls import reverse
from django.utils.decorators import method_decorator

from ..models import Ngo
from ..models.main import Ngo
from ..models.jobs import Job
from .base import BaseHandler, AccountHandler

Expand Down
2 changes: 1 addition & 1 deletion backend/donations/views/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils.decorators import method_decorator

from .base import AccountHandler
from ..models import Donor, Ngo
from ..models.main import Donor, Ngo


class MyAccountDetailsHandler(AccountHandler):
Expand Down
2 changes: 1 addition & 1 deletion backend/donations/views/ngo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils import timezone

from .base import BaseHandler
from ..models import Donor, Ngo
from ..models.main import Donor, Ngo
from ..pdf import create_pdf


Expand Down
2 changes: 1 addition & 1 deletion backend/donations/views/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse

from .base import BaseHandler
from ..models import Ngo
from ..models.main import Ngo


class HomePage(BaseHandler):
Expand Down
4 changes: 2 additions & 2 deletions backend/partners/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.8 on 2023-12-27 14:48
# Generated by Django 4.2.9 on 2024-01-27 08:54

from django.db import migrations, models
import django.db.models.functions.text
Expand All @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
("name", models.CharField(blank=True, db_index=True, max_length=100, verbose_name="name")),
("subdomain", models.CharField(max_length=100, unique=True, verbose_name="subdomain")),
("is_active", models.BooleanField(db_index=True, default=True, verbose_name="is active")),
("ngos", models.ManyToManyField(to="donations.ngo", verbose_name="NGOs")),
("ngos", models.ManyToManyField(blank=True, to="donations.ngo", verbose_name="NGOs")),
],
options={
"verbose_name": "Partner",
Expand Down
18 changes: 0 additions & 18 deletions backend/partners/migrations/0002_alter_partner_ngos.py

This file was deleted.

Loading

0 comments on commit 9685d36

Please sign in to comment.