Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixtures #3252

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions apps/authentication/fixtures/development_users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
- model: authentication.Membership
pk: 1
fields:
username: test1student
registered: "2024-8-19"
note: "Test note"
description: "Test description"
expiration_date: "2026-10-01"

- model: authentication.Membership
pk: 2
fields:
username: test2student
registered: "2024-8-19"
note: "Test note"
description: "Test description"
expiration_date: "2026-10-01"


- model: authentication.OnlineUser
pk: 1
fields:
is_superuser: 1
is_staff: 1
username: test1
ntnu_username: test1student
gender: male
first_name: test
last_name: user1
email: [email protected]
password: "pbkdf2_sha256$720000$cR1si6IeZiYooLaIFz93k7$9o7XJ34lG+DEeQ8N0mQBtACvecVMADZo3H3eyoT9Puw=" # 123
last_login: "2019-08-09T13:00:30+00:00"
field_of_study: 0 # Default: GUEST
started_date: "2019-08-09"
compiled: false
infomail: false
jobmail: false
phone_number: ""
address: ""
zip_code: ""
allergies: ""
nickname: ""
website: ""
github: ""
linkedin: ""
bio: ""
auth0_subject: "auth0|66c49513bd99017647045a3f"

- model: authentication.OnlineUser
pk: 2
fields:
is_superuser: 1
is_staff: 1
username: test2
ntnu_username: test2student
gender: male
first_name: test
last_name: user2
email: [email protected]
password: "pbkdf2_sha256$720000$cR1si6IeZiYooLaIFz93k7$9o7XJ34lG+DEeQ8N0mQBtACvecVMADZo3H3eyoT9Puw=" # 123
last_login: "2020-03-09T13:00:30+00:00"
field_of_study: 0 # Default: GUEST
started_date: "2020-03-09"
compiled: false
infomail: false
jobmail: false
phone_number: ""
address: ""
zip_code: ""
allergies: ""
nickname: ""
website: ""
github: ""
linkedin: ""
bio: ""
auth0_subject: "auth0|66c4b5e9414409b3e0298f28"
74 changes: 74 additions & 0 deletions apps/events/fixtures/development_events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
- model: auth.Group
pk: 1
fields:
name: "Organizers"

- model: auth.Group
pk: 2
fields:
name: "Speakers"

- model: auth.Group
pk: 3
fields:
name: "Participants"



- model: events.Event
pk: 1
fields:
title: "Python Workshop"
event_start: "2023-06-15T18:00:00+02:00"
event_end: "2023-06-15T21:00:00+02:00"
location: "Online Meeting Room"
ingress_short: "Learn Python basics in this interactive workshop"
ingress: "Join us for an exciting Python workshop where you'll learn the fundamentals of programming in Python."
description: "This workshop is perfect for beginners who want to start their journey in Python programming. We'll cover basic syntax, data types, control structures, and more."
event_type: 1 # Assuming 1 represents a workshop in your EventType choices
organizer: 1 # Assuming 1 is the ID of an existing Group
visible: true

- model: events.AttendanceEvent
pk: 1
fields:
event: 1
max_capacity: 100
waitlist: true
guest_attendance: false
registration_start: "2023-06-01T00:00:00+02:00"
unattend_deadline: "2023-06-14T23:59:59+02:00"
registration_end: "2023-06-15T17:00:00+02:00"
automatically_set_marks: false
marks_has_been_set: false
# rule_bundles: []
# extras: []
# payments: []

- model: events.Event
pk: 2
fields:
title: "Tech Talk: AI and Machine Learning"
event_start: "2023-07-01T19:00:00+02:00"
event_end: "2023-07-01T21:00:00+02:00"
location: "Main Auditorium"
ingress_short: "Explore the latest trends in AI and Machine Learning"
ingress: "Join us for an insightful tech talk on the current state and future of AI and Machine Learning technologies."
description: "Our guest speaker, a renowned expert in the field, will discuss recent advancements, practical applications, and potential future developments in AI and Machine Learning."
event_type: 2 # Assuming 2 represents a tech talk in your EventType choices
organizer: 2 # Assuming 2 is the ID of another existing Group
visible: true

- model: events.Event
pk: 3
fields:
title: "Hackathon: Solve Real-World Problems"
event_start: "2023-08-20T09:00:00+02:00"
event_end: "2023-08-21T18:00:00+02:00"
location: "Innovation Hub"
ingress_short: "48-hour hackathon to create solutions for local challenges"
ingress: "Participate in our annual hackathon where teams compete to develop innovative solutions for real-world problems faced by local communities."
description: "This exciting 48-hour event brings together developers, designers, and problem-solvers to create impactful solutions. Form teams, brainstorm ideas, and build prototypes that could make a difference in people's lives."
event_type: 3 # Assuming 3 represents a hackathon in your EventType choices
organizer: 3 # Assuming 3 is the ID of another existing Group
visible: true
92 changes: 92 additions & 0 deletions scripts/management/commands/load_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import logging
from datetime import timedelta

from django.core.management import call_command

# from lego.apps.events.models import Event
# from lego.apps.files.models import File
# from lego.apps.files.storage import storage
# from lego.apps.users.fixtures.initial_abakus_groups import load_abakus_groups
# from lego.apps.users.fixtures.test_abakus_groups import load_test_abakus_groups
# from lego.apps.users.models import AbakusGroup, User
from django.core.management.base import BaseCommand
from django.utils import timezone

from apps.events.models import AttendanceEvent, Event

log = logging.getLogger(__name__)


class Command(BaseCommand):
help = "Loads initial data from fixtures."
verbosity = 0

def add_arguments(self, parser):
parser.add_argument(
"--development",
action="store_true",
default=False,
help="Load development fixtures.",
)
parser.add_argument(
"--generate", action="store_true", default=False, help="Generate fixtures"
)

def call_command(self, *args, **options):
call_command(*args, verbosity=self.verbosity, **options)

def load_fixtures(self, fixtures):
for fixture in fixtures:
path = "apps/{}".format(fixture)
self.call_command("loaddata", path)

def handle(self, *args, **options):
log.info("Loading regular fixtures:")
log.info("Loading development fixtures:")
self.load_fixtures(["authentication/fixtures/development_users.yaml"])
self.load_fixtures(["events/fixtures/development_events.yaml"])
self.load_fixtures(
[
# "users/fixtures/development_users.yaml",
# "users/fixtures/development_memberships.yaml",
# "companies/fixtures/development_companies.yaml",
# "events/fixtures/development_events.yaml",
# "events/fixtures/development_pools.yaml",
# "events/fixtures/development_registrations.yaml",
# "articles/fixtures/development_articles.yaml",
# "quotes/fixtures/development_quotes.yaml",
# "podcasts/fixtures/development_podcasts.yaml",
# "polls/fixtures/development_polls.yaml",
# "oauth/fixtures/development_applications.yaml",
# "reactions/fixtures/development_reactions.yaml",
# "joblistings/fixtures/development_joblistings.yaml",
# "surveys/fixtures/development_surveys.yaml",
# "users/fixtures/development_photo_consents.yaml",
]
)

self.update_event_dates()

log.info("Done!")

def update_event_dates(self):
date = timezone.now().replace(hour=16, minute=15, second=0, microsecond=0)
for i, event in enumerate(Event.objects.all()):
event.event_start = date + timedelta(days=i + 10)
event.event_end = date + timedelta(days=i + 10, hours=4)

event.save()

try:
attendance_event = AttendanceEvent.objects.get(event=event)
# registration time one day ago
attendance_event.registration_start = timezone.now() - timedelta(days=1)
attendance_event.registration_end = event.event_start - timedelta(
days=1
)
attendance_event.unattend_deadline = event.event_start - timedelta(
days=0.5
)
attendance_event.save()
except AttendanceEvent.DoesNotExist:
log.warning(f"No AttendanceEvent found for Event ID {event.id}")