Update fake data generator
This commit is contained in:
parent
bdcdbddebe
commit
6c32d16acb
@ -167,6 +167,3 @@ def generate_fake_accounts_data(
|
|||||||
print(f"Created {len(programs)} programs.")
|
print(f"Created {len(programs)} programs.")
|
||||||
print(f"Created {len(students)} students.")
|
print(f"Created {len(students)} students.")
|
||||||
print(f"Created {len(parents)} parents.")
|
print(f"Created {len(parents)} parents.")
|
||||||
|
|
||||||
|
|
||||||
generate_fake_accounts_data(10, 10, 10)
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ from typing import List
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
from factory.django import DjangoModelFactory
|
from factory.django import DjangoModelFactory
|
||||||
from factory import SubFactory, LazyAttribute, Iterator
|
from factory import SubFactory, LazyAttribute, Iterator, LazyFunction
|
||||||
from core.models import ActivityLog, NewsAndEvents, Session, Semester, SEMESTER, POST
|
from core.models import ActivityLog, NewsAndEvents, Session, Semester, SEMESTER, POST
|
||||||
|
|
||||||
# Set up Django environment
|
# Set up Django environment
|
||||||
@ -32,9 +32,11 @@ class NewsAndEventsFactory(DjangoModelFactory):
|
|||||||
|
|
||||||
title: str = LazyAttribute(lambda x: fake.sentence(nb_words=4))
|
title: str = LazyAttribute(lambda x: fake.sentence(nb_words=4))
|
||||||
summary: str = LazyAttribute(lambda x: fake.paragraph(nb_sentences=3))
|
summary: str = LazyAttribute(lambda x: fake.paragraph(nb_sentences=3))
|
||||||
posted_as: str = fake.random_element(elements=[choice[0] for choice in POST])
|
posted_as: str = LazyFunction(
|
||||||
updated_date: timezone.datetime = fake.date_time_this_year()
|
lambda: fake.random_element(elements=[choice[0] for choice in POST])
|
||||||
upload_time: timezone.datetime = fake.date_time_this_year()
|
)
|
||||||
|
# updated_date: timezone.datetime = fake.date_time_this_year()
|
||||||
|
# upload_time: timezone.datetime = fake.date_time_this_year()
|
||||||
|
|
||||||
|
|
||||||
class SessionFactory(DjangoModelFactory):
|
class SessionFactory(DjangoModelFactory):
|
||||||
@ -50,7 +52,7 @@ class SessionFactory(DjangoModelFactory):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Session
|
model = Session
|
||||||
|
|
||||||
session: str = LazyAttribute(lambda x: fake.sentence(nb_words=2))
|
session: str = LazyAttribute(lambda x: str(fake.random_int(min=2020, max=2030)))
|
||||||
is_current_session: bool = fake.boolean(chance_of_getting_true=50)
|
is_current_session: bool = fake.boolean(chance_of_getting_true=50)
|
||||||
next_session_begins = LazyAttribute(lambda x: fake.future_datetime())
|
next_session_begins = LazyAttribute(lambda x: fake.future_datetime())
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import random
|
||||||
from typing import Type
|
from typing import Type
|
||||||
from factory.django import DjangoModelFactory
|
from factory.django import DjangoModelFactory
|
||||||
from factory import SubFactory, LazyAttribute, Iterator
|
from factory import SubFactory, LazyAttribute, Iterator
|
||||||
@ -152,6 +153,59 @@ class CourseOfferFactory(DjangoModelFactory):
|
|||||||
dep_head = SubFactory(DepartmentHeadFactory)
|
dep_head = SubFactory(DepartmentHeadFactory)
|
||||||
|
|
||||||
|
|
||||||
|
def populate_course_allocation(num_allocations: int) -> None:
|
||||||
|
"""
|
||||||
|
Populate the CourseAllocation model with fake data.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
num_allocations (int): The number of CourseAllocation instances to generate.
|
||||||
|
"""
|
||||||
|
# Fetch all available courses and sessions
|
||||||
|
courses = list(Course.objects.all())
|
||||||
|
sessions = list(Session.objects.all())
|
||||||
|
|
||||||
|
if not courses:
|
||||||
|
print("No courses found. Please add some courses before running this script.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not sessions:
|
||||||
|
print("No sessions found. Please add some sessions before running this script.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Fetch all available users (lecturers)
|
||||||
|
lecturers = list(
|
||||||
|
User.objects.filter(is_lecturer=True)
|
||||||
|
) # Assuming lecturers are lecturer
|
||||||
|
|
||||||
|
if not lecturers:
|
||||||
|
print(
|
||||||
|
"No lecturers found. Please add some lecturers before running this script."
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
for _ in range(num_allocations):
|
||||||
|
lecturer = random.choice(lecturers)
|
||||||
|
session = random.choice(sessions)
|
||||||
|
|
||||||
|
# Create a CourseAllocation instance
|
||||||
|
allocation = CourseAllocation.objects.create(
|
||||||
|
lecturer=lecturer,
|
||||||
|
session=session,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assign random courses to the course allocation
|
||||||
|
random_courses = random.sample(
|
||||||
|
courses, random.randint(1, len(courses))
|
||||||
|
) # Pick 1 to n random courses
|
||||||
|
allocation.courses.set(random_courses)
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"Created CourseAllocation for lecturer: {lecturer.username} with {len(random_courses)} courses."
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"Successfully populated {num_allocations} CourseAllocation instances.")
|
||||||
|
|
||||||
|
|
||||||
def generate_fake_course_data(
|
def generate_fake_course_data(
|
||||||
num_programs: int,
|
num_programs: int,
|
||||||
num_courses: int,
|
num_courses: int,
|
||||||
@ -193,6 +247,3 @@ def generate_fake_course_data(
|
|||||||
# Generate fake course offers
|
# Generate fake course offers
|
||||||
course_offers = CourseOfferFactory.create_batch(num_course_offers)
|
course_offers = CourseOfferFactory.create_batch(num_course_offers)
|
||||||
print(f"Created {len(course_offers)} course offers.")
|
print(f"Created {len(course_offers)} course offers.")
|
||||||
|
|
||||||
|
|
||||||
generate_fake_course_data(10, 10, 10, 10, 10, 10)
|
|
||||||
|
|||||||
@ -55,12 +55,12 @@
|
|||||||
<button class="btn btn-sm" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
<button class="btn btn-sm" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<i class="fa fa-ellipsis-vertical"></i>
|
<i class="fa fa-ellipsis-vertical"></i>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu position-fixed">
|
<ul class="dropdown-menu">
|
||||||
<li><a class="dropdown-item" href="{% url 'staff_edit' pk=lecturer.pk %}"><i class="unstyled me-2 fas fa-edit"></i>{% trans 'Update' %}</a></li>
|
<li><a class="dropdown-item" href="{% url 'staff_edit' pk=lecturer.pk %}"><i class="unstyled me-2 fas fa-edit"></i>{% trans 'Update' %}</a></li>
|
||||||
<li><a class="dropdown-item" target="_blank" href="{% url 'profile_single' lecturer.id %}?download_pdf=1"><i class="unstyled me-2 fas fa-download"></i>{% trans 'Download PDF' %}</a></li>
|
<li><a class="dropdown-item" target="_blank" href="{% url 'profile_single' lecturer.id %}?download_pdf=1"><i class="unstyled me-2 fas fa-download"></i>{% trans 'Download PDF' %}</a></li>
|
||||||
<li><a class="dropdown-item text-danger" href="{% url 'lecturer_delete' pk=lecturer.pk %}"><i class="unstyled me-2 fas fa-trash-alt"></i> {% trans 'Delete' %}</a></li>
|
<li><a class="dropdown-item text-danger" href="{% url 'lecturer_delete' pk=lecturer.pk %}"><i class="unstyled me-2 fas fa-trash-alt"></i> {% trans 'Delete' %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@
|
|||||||
<button class="btn btn-sm" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
<button class="btn btn-sm" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<i class="fa fa-ellipsis-vertical"></i>
|
<i class="fa fa-ellipsis-vertical"></i>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu position-fixed">
|
<ul class="dropdown-menu">
|
||||||
<li><a class="dropdown-item" href="{% url 'student_edit' student.student.pk %}"><i class="unstyled me-2 fas fa-edit"></i>{% trans 'Update' %}</a></li>
|
<li><a class="dropdown-item" href="{% url 'student_edit' student.student.pk %}"><i class="unstyled me-2 fas fa-edit"></i>{% trans 'Update' %}</a></li>
|
||||||
<li><a class="dropdown-item" target="_blank" href="{% url 'profile_single' student.student.id %}?download_pdf=1"><i class="unstyled me-2 fas fa-download"></i>{% trans 'Download PDF' %}</a></li>
|
<li><a class="dropdown-item" target="_blank" href="{% url 'profile_single' student.student.id %}?download_pdf=1"><i class="unstyled me-2 fas fa-download"></i>{% trans 'Download PDF' %}</a></li>
|
||||||
<li><a class="dropdown-item text-danger" href="{% url 'student_delete' student.pk %}"><i class="unstyled me-2 fas fa-trash-alt"></i>{% trans 'Delete' %}</a></li>
|
<li><a class="dropdown-item text-danger" href="{% url 'student_delete' student.pk %}"><i class="unstyled me-2 fas fa-trash-alt"></i>{% trans 'Delete' %}</a></li>
|
||||||
|
|||||||
@ -52,7 +52,7 @@
|
|||||||
<button class="btn btn-sm" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
<button class="btn btn-sm" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<i class="fa fa-ellipsis-vertical"></i>
|
<i class="fa fa-ellipsis-vertical"></i>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu position-fixed">
|
<ul class="dropdown-menu">
|
||||||
<li><a class="dropdown-item" href="{% url 'edit_program' pk=program.pk %}"><i class="unstyled me-2 fas fa-edit"></i>{% trans 'Update' %}</a></li>
|
<li><a class="dropdown-item" href="{% url 'edit_program' pk=program.pk %}"><i class="unstyled me-2 fas fa-edit"></i>{% trans 'Update' %}</a></li>
|
||||||
<li><a class="dropdown-item text-danger" href="{% url 'program_delete' pk=program.pk %}"><i class="unstyled me-2 fas fa-trash-alt"></i>{% trans 'Delete' %}</a></li>
|
<li><a class="dropdown-item text-danger" href="{% url 'program_delete' pk=program.pk %}"><i class="unstyled me-2 fas fa-trash-alt"></i>{% trans 'Delete' %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@ -77,7 +77,7 @@
|
|||||||
data-bs-boundary="window" aria-haspopup="true" aria-expanded="false">
|
data-bs-boundary="window" aria-haspopup="true" aria-expanded="false">
|
||||||
<i class="fas fa-ellipsis-v m-0"></i>
|
<i class="fas fa-ellipsis-v m-0"></i>
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu position-fixed">
|
<div class="dropdown-menu">
|
||||||
<a class="dropdown-item" href="{% url 'edit_course' slug=course.slug %}">
|
<a class="dropdown-item" href="{% url 'edit_course' slug=course.slug %}">
|
||||||
<i class="unstyled me-2 fas fa-pencil-alt"></i> {% trans 'Edit' %}
|
<i class="unstyled me-2 fas fa-pencil-alt"></i> {% trans 'Edit' %}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user