Skip to content

Commit

Permalink
Implement Swagger (#858)
Browse files Browse the repository at this point in the history
* started on removing choiceenums

* refactored cheatsheet and membership

* refacotered strike enum

* refactored Groups enum

* removed AppModel choiceenum

* added swagger
  • Loading branch information
MadsNyl authored Sep 20, 2024
1 parent 99ba049 commit a17c46d
Show file tree
Hide file tree
Showing 64 changed files with 492 additions and 118 deletions.
2 changes: 1 addition & 1 deletion app/badge/filters/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from app.badge.models import BadgeCategory, UserBadge
from app.badge.models.badge import Badge
from app.common.enums import GroupType
from app.common.enums import NativeGroupType as GroupType
from app.content.models import User
from app.group.models.membership import Membership

Expand Down
89 changes: 77 additions & 12 deletions app/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from enumchoicefield import ChoiceEnum


# This can't be removed because it is used in the migrations. It is not used in the code.
class UserClass(ChoiceEnum):
FIRST = "1. Klasse"
SECOND = "2. Klasse"
Expand All @@ -14,6 +15,23 @@ class UserClass(ChoiceEnum):
ALUMNI = "Alumni"


class NativeUserClass(models.TextChoices):
FIRST = "FIRST", "1. Klasse"
SECOND = "SECOND", "2. Klasse"
THIRD = "THIRD", "3. Klasse"
FOURTH = "FOURTH", "4. Klasse"
FIFTH = "FIFTH", "5. Klasse"
ALUMNI = "ALUMNI", "Alumni"


def get_user_class_number(user_class: NativeUserClass) -> int:
_class = user_class.label
if user_class == NativeUserClass.ALUMNI:
return 6
return int(_class.split(".")[0])


# This can't be removed because it is used in the migrations. It is not used in the code
class UserStudy(ChoiceEnum):
DATAING = "Dataingeniør"
DIGFOR = "Digital forretningsutvikling"
Expand All @@ -23,7 +41,16 @@ class UserStudy(ChoiceEnum):
INFO = "Informasjonsbehandling"


class AdminGroup(ChoiceEnum):
class NativeUserStudy(models.TextChoices):
DATAING = "DATAING", "Dataingeniør"
DIGFOR = "DIGFOR", "Digital forretningsutvikling"
DIGINC = "DIGINC", "Digital infrastruktur og cybersikkerhet"
DIGSAM = "DIGSAM", "Digital samhandling"
DRIFT = "DRIFT", "Drift"
INFO = "INFO", "Informasjonsbehandling"


class AdminGroup(models.TextChoices):
HS = "HS"
INDEX = "Index"
NOK = "Nok"
Expand All @@ -40,24 +67,20 @@ def admin(cls):
return (cls.HS, cls.INDEX)


class Groups(ChoiceEnum):
class Groups(models.TextChoices):
TIHLDE = "TIHLDE"
JUBKOM = "JubKom"
REDAKSJONEN = "Redaksjonen"
FONDET = "Forvaltningsgruppen"
PLASK = "Plask"
DRIFT = "Drift"


class AppModel(ChoiceEnum):
EVENT = "Event"
JOBPOST = "Jobpost"
NEWS = "News"
USER = "User"
CHEATSHEET = "Cheatsheet"
WEEKLY_BUSINESS = "Weekly Business"
@classmethod
def all(cls):
return (cls.TIHLDE, cls.JUBKOM, cls.REDAKSJONEN, cls.FONDET, cls.PLASK, cls.DRIFT)


# This can't be removed because it is used in the migrations. It is not used in the code.
class GroupType(ChoiceEnum):
TIHLDE = "TIHLDE"
BOARD = "Styre"
Expand All @@ -72,9 +95,20 @@ class GroupType(ChoiceEnum):
def public_groups(cls):
return [cls.BOARD, cls.SUBGROUP, cls.COMMITTEE, cls.INTERESTGROUP]


class NativeGroupType(models.TextChoices):
TIHLDE = "TIHLDE", "TIHLDE"
BOARD = "BOARD", "Styre"
SUBGROUP = "SUBGROUP", "Undergruppe"
COMMITTEE = "COMMITTEE", "Komité"
STUDYYEAR = "STUDYYEAR", "Studieår"
STUDY = "STUDY", "Studie"
INTERESTGROUP = "INTERESTGROUP", "Interesse Gruppe"
OTHER = "OTHER", "Annet"

@classmethod
def all(cls):
return list(map(lambda c: (c.name, c.value), cls))
def public_groups(cls):
return [cls.BOARD, cls.SUBGROUP, cls.COMMITTEE, cls.INTERESTGROUP]


class EnvironmentOptions(Enum):
Expand All @@ -83,13 +117,22 @@ class EnvironmentOptions(Enum):
PRODUCTION = "PRODUCTION"


# This can't be removed because it is used in the migrations. It is not used in the code
class CheatsheetType(ChoiceEnum):
FILE = "Fil"
GITHUB = "GitHub"
LINK = "Link"
OTHER = "Annet"


class NativeCheatsheetType(models.TextChoices):
FILE = "FILE", "Fil"
GITHUB = "GITHUB", "GitHub"
LINK = "LINK", "Link"
OTHER = "OTHER", "Annet"


# This can't be removed because it is used in the migrations. It is not used in the code
class MembershipType(ChoiceEnum):
LEADER = "Leader"
MEMBER = "Member"
Expand All @@ -103,6 +146,16 @@ def all(cls):
return tuple((i.name, i.value) for i in cls)


class NativeMembershipType(models.TextChoices):
LEADER = "LEADER", "Leader"
MEMBER = "MEMBER", "Member"

@classmethod
def board_members(cls):
return (cls.LEADER,)


# This can't be removed because it is used in the migrations. It is not used in the code
class StrikeEnum(ChoiceEnum):
PAST_DEADLINE = "PAST_DEADLINE"
NO_SHOW = "NO_SHOW"
Expand All @@ -111,6 +164,18 @@ class StrikeEnum(ChoiceEnum):
EVAL_FORM = "EVAL_FORM"


class NativeStrikeEnum(models.TextChoices):
PAST_DEADLINE = "PAST_DEADLINE"
NO_SHOW = "NO_SHOW"
LATE = "LATE"
BAD_BEHAVIOR = "BAD_BEHAVIOR"
EVAL_FORM = "EVAL_FORM"

@classmethod
def all(cls):
return [cls.PAST_DEADLINE, cls.NO_SHOW, cls.LATE, cls.BAD_BEHAVIOR, cls.EVAL_FORM]


class CodexGroups(models.TextChoices):
DRIFT = "Drift"
INDEX = "Index"
Expand Down
2 changes: 1 addition & 1 deletion app/content/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.html import escape
from django.utils.safestring import mark_safe

from app.common.enums import GroupType
from app.common.enums import NativeGroupType as GroupType
from app.content import models
from app.group.models.membership import Membership

Expand Down
4 changes: 1 addition & 3 deletions app/content/enums.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django.db import models

from enumchoicefield import ChoiceEnum


class UserClass(models.IntegerChoices):
FIRST = 1
Expand All @@ -11,7 +9,7 @@ class UserClass(models.IntegerChoices):
FIFTH = 5


class CategoryEnum(ChoiceEnum):
class CategoryEnum(models.TextChoices):
ACTIVITY = "Aktivitet"
SOSIALT = "Sosialt"
BEDPRES = "Bedpres"
Expand Down
6 changes: 5 additions & 1 deletion app/content/factories/cheatsheet_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import factory
from factory.django import DjangoModelFactory

from app.common.enums import CheatsheetType, UserClass, UserStudy
from app.common.enums import (
NativeCheatsheetType as CheatsheetType,
NativeUserClass as UserClass,
NativeUserStudy as UserStudy
)
from app.content.models import Cheatsheet


Expand Down
2 changes: 1 addition & 1 deletion app/content/factories/strike_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import factory
from factory.django import DjangoModelFactory

from app.common.enums import StrikeEnum
from app.common.enums import NativeStrikeEnum as StrikeEnum
from app.content.factories.event_factory import EventFactory
from app.content.factories.user_factory import UserFactory
from app.content.models.strike import Strike
Expand Down
2 changes: 1 addition & 1 deletion app/content/filters/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django_filters import filters
from django_filters.rest_framework.filterset import FilterSet

from app.common.enums import GroupType
from app.common.enums import NativeGroupType as GroupType
from app.content.models import Strike
from app.group.models.membership import Membership

Expand Down
5 changes: 4 additions & 1 deletion app/content/filters/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django_filters.rest_framework import BooleanFilter, CharFilter, FilterSet

from app.common.enums import Groups, GroupType
from app.common.enums import (
Groups,
NativeGroupType as GroupType
)
from app.content.models import User
from app.content.models.strike import Strike

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Generated by Django 4.2.5 on 2024-09-20 08:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("content", "0067_alter_minute_group"),
]

operations = [
migrations.AlterField(
model_name="cheatsheet",
name="grade",
field=models.CharField(
choices=[
("FIRST", "1. Klasse"),
("SECOND", "2. Klasse"),
("THIRD", "3. Klasse"),
("FOURTH", "4. Klasse"),
("FIFTH", "5. Klasse"),
("ALUMNI", "Alumni"),
],
default="FIRST",
max_length=50,
),
),
migrations.AlterField(
model_name="cheatsheet",
name="study",
field=models.CharField(
choices=[
("DATAING", "Dataingeniør"),
("DIGFOR", "Digital forretningsutvikling"),
("DIGINC", "Digital infrastruktur og cybersikkerhet"),
("DIGSAM", "Digital samhandling"),
("DRIFT", "Drift"),
("INFO", "Informasjonsbehandling"),
],
default="DATAING",
max_length=50,
),
),
migrations.AlterField(
model_name="cheatsheet",
name="type",
field=models.CharField(
choices=[
("FILE", "Fil"),
("GITHUB", "GitHub"),
("LINK", "Link"),
("OTHER", "Annet"),
],
default="LINK",
max_length=50,
),
),
]
14 changes: 6 additions & 8 deletions app/content/models/cheatsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

from django.db import models

from enumchoicefield import EnumChoiceField

from app.common.enums import (
AdminGroup,
CheatsheetType,
NativeCheatsheetType as CheatsheetType,
Groups,
UserClass,
UserStudy,
NativeUserClass as UserClass,
NativeUserStudy as UserStudy,
)
from app.common.permissions import BasePermissionModel
from app.util.models import BaseModel
Expand All @@ -21,10 +19,10 @@ class Cheatsheet(BaseModel, BasePermissionModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=200)
creator = models.CharField(max_length=200)
grade = EnumChoiceField(UserClass, default=UserClass.FIRST)
study = EnumChoiceField(UserStudy, default=UserStudy.DATAING)
grade = models.CharField(max_length=50, choices=UserClass.choices, default=UserClass.FIRST)
study = models.CharField(max_length=50, choices=UserStudy.choices, default=UserStudy.DATAING)
course = models.CharField(max_length=200)
type = EnumChoiceField(CheatsheetType, default=CheatsheetType.LINK)
type = models.CharField(max_length=50, choices=CheatsheetType.choices, default=CheatsheetType.LINK)
official = models.BooleanField(default=False)
url = models.URLField(max_length=600)

Expand Down
6 changes: 3 additions & 3 deletions app/content/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from app.content.models import Category
from app.content.models.user import User
from app.emoji.models.reaction import Reaction
from app.forms.enums import EventFormType
from app.forms.enums import NativeEventFormType
from app.group.models.group import Group
from app.util.models import BaseModel, OptionalImage
from app.util.utils import now, yesterday
Expand Down Expand Up @@ -174,11 +174,11 @@ def has_priorities(self):

@property
def evaluation(self):
return self.forms.filter(type=EventFormType.EVALUATION).first()
return self.forms.filter(type=NativeEventFormType.EVALUATION).first()

@property
def survey(self):
return self.forms.filter(type=EventFormType.SURVEY).first()
return self.forms.filter(type=NativeEventFormType.SURVEY).first()

def check_request_user_has_access_through_organizer(self, user, organizer):
return user.memberships_with_events_access.filter(group=organizer).exists()
Expand Down
5 changes: 4 additions & 1 deletion app/content/models/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from django.contrib.contenttypes.fields import GenericRelation
from django.db import models

from app.common.enums import AdminGroup, Groups
from app.common.enums import (
AdminGroup,
Groups
)
from app.common.permissions import BasePermissionModel, check_has_access
from app.emoji.models.reaction import Reaction
from app.util.models import BaseModel, OptionalImage
Expand Down
4 changes: 2 additions & 2 deletions app/content/models/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from sentry_sdk import capture_exception

from app.common.enums import StrikeEnum
from app.common.enums import NativeStrikeEnum as StrikeEnum
from app.common.permissions import BasePermissionModel
from app.communication.enums import UserNotificationSettingType
from app.communication.notifier import Notify
Expand All @@ -20,7 +20,7 @@
from app.content.models.strike import create_strike
from app.content.models.user import User
from app.content.util.registration_utils import get_payment_expiredate
from app.forms.enums import EventFormType
from app.forms.enums import NativeEventFormType as EventFormType
from app.payment.util.order_utils import check_if_order_is_paid, has_paid_order
from app.util import now
from app.util.models import BaseModel
Expand Down
5 changes: 4 additions & 1 deletion app/content/models/toddel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.db import models

from app.common.enums import AdminGroup, Groups
from app.common.enums import (
AdminGroup,
Groups
)
from app.common.permissions import BasePermissionModel
from app.util.models import BaseModel
from app.util.utils import datetime_format
Expand Down
Loading

0 comments on commit a17c46d

Please sign in to comment.