-
Notifications
You must be signed in to change notification settings - Fork 3
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
f699b8b
commit 0c4bedc
Showing
13 changed files
with
426 additions
and
324 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
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,19 +1,29 @@ | ||
import datetime | ||
from typing import Any | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.core.management import call_command | ||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
|
||
from portal.models import Poll, PollOption, PollVote, TargetPopulation | ||
from user.models import Profile | ||
|
||
|
||
User = get_user_model() | ||
from utils.types import DjangoUserModel, DjangoUserType | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **kwargs): | ||
def _create_user( | ||
self, username: str, email: str, password: str, graduation_date: datetime.date | ||
) -> DjangoUserType: | ||
"""Helper to create a user with profile""" | ||
if not DjangoUserModel.objects.filter(username=username).exists(): | ||
user = DjangoUserModel.objects.create_user(username, email, password) | ||
profile = Profile.objects.get(user=user) | ||
setattr(profile, "expected_graduation", graduation_date) | ||
profile.save() | ||
return user | ||
return DjangoUserModel.objects.get(username=username) | ||
|
||
def handle(self, *args: Any, **kwargs: Any) -> None: | ||
|
||
# Define graduation years | ||
df_2022 = datetime.date(2022, 5, 15) | ||
|
@@ -22,55 +32,12 @@ def handle(self, *args, **kwargs): | |
df_2025 = datetime.date(2025, 5, 17) | ||
|
||
# Create users and set graduation years | ||
if not User.objects.filter(username="user1").first(): | ||
user1 = User.objects.create_user("user1", "[email protected]", "user") | ||
user1_profile = Profile.objects.get(user=user1) | ||
user1_profile.expected_graduation = df_2022 | ||
user1_profile.save() | ||
else: | ||
user1 = User.objects.get(username="user1") | ||
|
||
if not User.objects.filter(username="user2").first(): | ||
user2 = User.objects.create_user("user2", "[email protected]", "user2") | ||
user2_profile = Profile.objects.get(user=user2) | ||
user2_profile.expected_graduation = df_2023 | ||
user2_profile.save() | ||
else: | ||
user2 = User.objects.get(username="user2") | ||
|
||
if not User.objects.filter(username="user3").first(): | ||
user3 = User.objects.create_user("user3", "[email protected]", "user3") | ||
user3_profile = Profile.objects.get(user=user3) | ||
user3_profile.expected_graduation = df_2024 | ||
user3_profile.save() | ||
else: | ||
user3 = User.objects.get(username="user3") | ||
|
||
if not User.objects.filter(username="user_cas").first(): | ||
user_cas = User.objects.create_user("user_cas", "[email protected]", "user_cas") | ||
user_cas_profile = Profile.objects.get(user=user_cas) | ||
user_cas_profile.expected_graduation = df_2025 | ||
user_cas_profile.save() | ||
else: | ||
user_cas = User.objects.get(username="user_cas") | ||
|
||
if not User.objects.filter(username="user_wh").first(): | ||
user_wh = User.objects.create_user("user_wh", "[email protected]", "user_wh") | ||
user_wh_profile = Profile.objects.get(user=user_wh) | ||
user_wh_profile.expected_graduation = df_2024 | ||
user_wh_profile.save() | ||
else: | ||
user_wh = User.objects.get(username="user_wh") | ||
|
||
if not User.objects.filter(username="user_nursing").first(): | ||
user_nursing = User.objects.create_user( | ||
"user_nursing", "[email protected]", "user_nursing" | ||
) | ||
user_nursing_profile = Profile.objects.get(user=user_nursing) | ||
user_nursing_profile.expected_graduation = df_2023 | ||
user_nursing_profile.save() | ||
else: | ||
user_nursing = User.objects.get(username="user_nursing") | ||
self._create_user("user1", "[email protected]", "user", df_2022) | ||
self._create_user("user2", "[email protected]", "user2", df_2023) | ||
self._create_user("user3", "[email protected]", "user3", df_2024) | ||
self._create_user("user_cas", "[email protected]", "user_cas", df_2025) | ||
self._create_user("user_wh", "[email protected]", "user_wh", df_2024) | ||
self._create_user("user_nursing", "[email protected]", "user_nursing", df_2023) | ||
|
||
# Create target populations | ||
call_command("load_target_populations", "--years", "2022, 2023, 2024, 2025") | ||
|
Oops, something went wrong.