Skip to content

Commit

Permalink
[UPDATES] - Improved documentation and fixed issues with Sonarlint
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
nulzo authored Dec 11, 2023
2 parents 7724dc2 + 1555d45 commit 0ea6ac9
Show file tree
Hide file tree
Showing 217 changed files with 30,595 additions and 1,214 deletions.
30 changes: 30 additions & 0 deletions backend/api/endpoints/authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,45 @@


class APIAuthenticateList(APIView):
"""View for authenticating users in the CSLC Ticket Portal API.
Attributes:
- serializer_class: UserSerializer instance for serializing user data.
- renderer_classes: Tuple of renderer classes for API view.
Methods:
- get: Retrieves a list of all users and returns serialized user data.
- post: Creates a new user and returns serialized user data if valid.
"""

serializer_class = UserSerializer
renderer_classes = (BrowsableAPIRenderer, JSONRenderer, HTMLFormRenderer)

def get(self, request: Request) -> Response:
"""
Handles GET requests to retrieve a list of users.
Args:
request (Request): The HTTP request object.
Returns:
Response: A response containing a serialized list of users' data.
"""
users = User.generic.all()
serializer = UserSerializer(users, many=True)
return Response(serializer.data)

def post(self, request: Request) -> Response:
"""
Handles POST requests to create a new user or retrieve an existing user.
Args:
request (Request): The HTTP request object containing user data.
Returns:
Response: A response containing the serialized user data if the user is successfully
created, or the error messages if the user data is invalid.
"""
user, created = User.generic.get_or_create(request.data)
print(user)
serializer = UserSerializer(data=request.data)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 4.2.7 on 2023-12-07 16:25

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


class Migration(migrations.Migration):
dependencies = [
("api", "0002_alter_ticket_student_alter_ticket_tutor"),
]

operations = [
migrations.AddField(
model_name="ticket",
name="difficulty",
field=models.CharField(
blank=True,
choices=[("EASY", "Easy"), ("MEDIUM", "Medium"), ("HARD", "Hard")],
max_length=20,
null=True,
),
),
migrations.AddField(
model_name="ticket",
name="was_flagged",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="ticket",
name="tutor",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="assistant_tutor_ticket",
to="api.user",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.7 on 2023-12-07 16:28

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


class Migration(migrations.Migration):
dependencies = [
("api", "0003_ticket_difficulty_ticket_was_flagged_and_more"),
]

operations = [
migrations.AddField(
model_name="ticket",
name="asst_tutor",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="assistant_tutor_ticket",
to="api.user",
),
),
migrations.AlterField(
model_name="ticket",
name="tutor",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="tutor_ticket",
to="api.user",
),
),
]
24 changes: 24 additions & 0 deletions backend/api/models/hours.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@


class HourManager(models.Manager):
'''A manager for the Hour model that provides custom query methods for managing tutor hours."""
def get_all_hours(self) -> QuerySet:
"""Returns all tutor hours.
Returns:
QuerySet: A queryset containing all tutor hours.
"""
return super().get_queryset().all()
def get_tutor(self, name: str) -> QuerySet:
"""Returns tutor hours filtered by tutor name.
Args:
name (str): The name of the tutor.
Returns:
QuerySet: A queryset containing tutor hours filtered by the given tutor name.
'''

def get_all_hours(self) -> QuerySet:
return super().get_queryset().all()

Expand All @@ -13,7 +33,11 @@ def get_tutor(self, name: str) -> QuerySet:


class Hour(models.Model):
"""A model to represent tutor hours."""

class Day(models.IntegerChoices):
"""An enumeration of days of the week."""

MONDAY = 1
TUESDAY = 2
WEDNESDAY = 3
Expand Down
12 changes: 12 additions & 0 deletions backend/api/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Ticket(models.Model):
(OPENED, "Opened"),
(CLOSED, "Closed"),
]
DIFFICULTY_CHOICES = [("EASY", "Easy"), ("MEDIUM", "Medium"), ("HARD", "Hard")]

professor = models.ForeignKey("api.Professor", on_delete=models.PROTECT)
# section = models.ForeignKey("api.Section", null=True, on_delete=models.PROTECT)
Expand All @@ -75,6 +76,13 @@ class Ticket(models.Model):
related_name="tutor_ticket",
blank=True,
)
asst_tutor = models.ForeignKey(
"api.User",
null=True,
on_delete=models.PROTECT,
related_name="assistant_tutor_ticket",
blank=True,
)
name = models.CharField(blank=False, max_length=50)
title = models.CharField(blank=False, max_length=25)
description = models.TextField(max_length=1024)
Expand All @@ -85,6 +93,10 @@ class Ticket(models.Model):
closed_at = models.DateTimeField(null=True, blank=True)
was_successful = models.BooleanField(default=False)
was_reopened = models.BooleanField(default=False)
was_flagged = models.BooleanField(default=False)
difficulty = models.CharField(
max_length=20, choices=DIFFICULTY_CHOICES, blank=True, null=True
)

generic = models.Manager()
ticket = TicketManager()
Expand Down
118 changes: 118 additions & 0 deletions backend/api/scripts/load_semester.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,124 @@


class ParseSemester:
'''
A class used to parse and process semester data from a CSV file
...
Attributes
----------
courses : dict
a dictionary to store course data
sections : dict
a dictionary to store section data
professors : dict
a dictionary to store professor data
csv_file : str
the file directory of the CSV data
column_names : list
a list of column names from the CSV file
professor_data : pandas.DataFrame
a DataFrame to store professor data from the CSV file
Methods
-------
read_csv()
Reads the CSV file and processes the data into dictionaries for courses, sections, and professors
get_professors() -> dict
Returns the dictionary of professor data
get_courses() -> dict
Returns the dictionary of course data
get_sections() -> dict
Returns the dictionary of section data
normalize_text(text: str) -> str
Normalizes the input text and returns the normalized string
write_professors()
Writes professor data to the database
write_courses()
Writes course data to the database
write_sections()
Writes section data to the database
"""
def __init__(self, file_dir: str) -> None:
pass
def read_csv(self):
"""
Reads the CSV file and processes the data into dictionaries for courses, sections, and professors
"""
pass
def get_professors(self) -> dict:
"""
Returns the dictionary of professor data
"""
pass
def get_courses(self) -> dict:
"""
Returns the dictionary of course data
"""
pass
def get_sections(self) -> dict:
"""
Returns the dictionary of section data
"""
pass
def normalize_text(self, text: str) -> str:
"""
Normalizes the input text and returns the normalized string
Parameters
----------
text : str
The text to be normalized
Returns
-------
str
The normalized text
"""
pass
def write_professors(self) -> None:
"""
Writes professor data to the database
"""
pass
def write_courses(self) -> None:
"""
Writes course data to the database
"""
pass
def write_sections(self) -> None:
"""
Writes section data to the database
"""
pass
def run(csv_file: str | None = None) -> bool:
"""
Runs the data processing and writing tasks for the CSV file
Parameters
----------
csv_file : str, optional
The file directory of the CSV data
Returns
-------
bool
True if the process is successful, False otherwise
"""
pass
'''

def __init__(self, file_dir: str) -> None:
self.courses: dict = {}
self.sections: dict = {}
Expand Down
8 changes: 4 additions & 4 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class TicketSerializer(serializers.ModelSerializer):
professor = serializers.PrimaryKeyRelatedField(queryset=Professor.generic.all())
course = serializers.PrimaryKeyRelatedField(queryset=Course.generic.all())
issue = serializers.PrimaryKeyRelatedField(queryset=Issues.generic.all())
tutor = serializers.PrimaryKeyRelatedField(
queryset=User.generic.all().filter(is_tutor=True)
)
# tutor = serializers.PrimaryKeyRelatedField(required=False,
# queryset=User.generic.all().filter(is_tutor=True)
# )

class Meta:
model = Ticket
Expand All @@ -51,7 +51,7 @@ class TicketGetSerializer(serializers.ModelSerializer):
course = serializers.StringRelatedField()
issue = serializers.StringRelatedField()
student = serializers.StringRelatedField()
tutor = serializers.StringRelatedField()
# tutor = serializers.StringRelatedField()

class Meta:
model = Ticket
Expand Down
5 changes: 5 additions & 0 deletions backend/base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,8 @@
STATIC_URL = "static/"

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

GRAPH_MODELS = {
"all_applications": True,
"group_models": True,
}
20 changes: 17 additions & 3 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ea6ac9

Please sign in to comment.