Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Aug 22, 2024
1 parent c323a0b commit 2421ba8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
23 changes: 18 additions & 5 deletions backend/hub/management/commands/seed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from shutil import copyfile

from faker.generator import random

from accounts.models import User, COMMITTEE_GROUP, STAFF_GROUP
from django.contrib.auth.models import Group
from django.core.management.base import BaseCommand
Expand Down Expand Up @@ -89,7 +91,11 @@ def handle(self, *args, **kwargs):
for i in range(ORG_NUMBER):
city = City.objects.order_by("?").first()
domain = Domain.objects.order_by("?").first()
status = ["pending", "accepted", "rejected"][i % 3]
organization_status = [
Organization.STATUS.pending,
Organization.STATUS.accepted,
Organization.STATUS.rejected,
][i % 3]

org = Organization.objects.create(
name=fake.company(),
Expand All @@ -108,7 +114,7 @@ def handle(self, *args, **kwargs):
legal_representative_phone=fake.phone_number(),
organization_head_name=fake.name(),
board_council=fake.name(),
status=status,
status=organization_status,
accept_terms_and_conditions=True,
)

Expand All @@ -125,9 +131,9 @@ def handle(self, *args, **kwargs):
org.last_balance_sheet.name = "test.pdf"
org.save()

if status == "rejected":
if organization_status == Organization.STATUS.rejected:
self.stdout.write(f"Created organization {org}")
elif status == "accepted":
elif organization_status == Organization.STATUS.accepted:
candidate = Candidate.objects.create(
org=org,
domain=domain,
Expand All @@ -141,7 +147,14 @@ def handle(self, *args, **kwargs):
self.stdout.write(f"Created organization {org} and candidate {candidate.name}")

for candidate in Candidate.objects.order_by("?")[:10]:
candidate.status = "accepted"
candidate.status = random.choice(
[
Candidate.STATUS.pending,
Candidate.STATUS.accepted,
Candidate.STATUS.confirmed,
Candidate.STATUS.rejected,
]
)
candidate.save()

self.stdout.write("Loaded organizations data")
Expand Down
11 changes: 8 additions & 3 deletions backend/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ def save(self, *args, **kwargs):


class Organization(StatusModel, TimeStampedModel):
# DRAFT: empty organization created by us, it might be invalid (e.g., created for another user of an org
# PENDING: the organization doesn't have all the necessary documents
# ACCEPTED: the organization has all required documentation and can vote
# REJECTED: the organization was rejected by the electoral commission
STATUS = Choices(
("draft", _("Draft")),
("pending", _("Pending approval")),
("accepted", _("Accepted")),
("rejected", _("Rejected")),
# ("eligible", _("Eligible to vote")),
# ("ineligible", _("Ineligible to vote")),
# ("disabled", _("Disabled")),
)
status = models.CharField(_("Status"), choices=STATUS, default=STATUS.draft, max_length=30, db_index=True)

Expand Down Expand Up @@ -460,6 +461,10 @@ def get_queryset(self):


class Candidate(StatusModel, TimeStampedModel):
# PENDING: has been created/proposed and is waiting for support from organizations
# ACCEPTED: has been accepted by the admins of the platform
# CONFIRMED: has received confirmation from the electoral commission
# REJECTED: has been rejected
STATUS = Choices(
("pending", _("Pending")),
("accepted", _("Accepted")),
Expand Down

0 comments on commit 2421ba8

Please sign in to comment.