-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MykytaMaliarenko/dev
0.1
- Loading branch information
Showing
29 changed files
with
442 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
import os | ||
import json | ||
|
||
os.environ["test"] = "test" | ||
LOCAL_ENV = "config/env_local.json" | ||
|
||
if os.path.exists(LOCAL_ENV): | ||
with open(LOCAL_ENV) as json_file: | ||
data = json.load(json_file) | ||
for key, value in data.items(): | ||
os.environ[key] = value |
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,21 +1,29 @@ | ||
"""config URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/3.0/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
from rest_framework import routers, permissions | ||
from django.contrib import admin | ||
from django.urls import path | ||
from django.conf.urls import url, include | ||
from drf_yasg.views import get_schema_view | ||
from drf_yasg import openapi | ||
|
||
|
||
schema_view = get_schema_view( | ||
openapi.Info( | ||
title="Rozkald Scheduling API", | ||
default_version='v1', | ||
terms_of_service="https://www.google.com/policies/terms/", | ||
contact=openapi.Contact(email="mykytamaliarenko@gmail.com"), | ||
license=openapi.License(name="BSD License"), | ||
), | ||
public=True, | ||
permission_classes=(permissions.AllowAny,), | ||
) | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), | ||
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), | ||
|
||
url(r'^api/v1/', include('djangoapps.classes.urls')), | ||
url(r'^api/v1/', include('djangoapps.groups.urls')), | ||
url(r'^api/v1/', include('djangoapps.teachers.urls')), | ||
url(r'^api/v1/', include('djangoapps.rooms.urls')), | ||
url(r'^api/v1/', include('djangoapps.timeslots.urls')), | ||
] |
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,3 +1,30 @@ | ||
from django.db import models | ||
from djangoapps.rooms.models import Room | ||
from djangoapps.teachers.models import Teacher | ||
from djangoapps.groups.models import Group | ||
from djangoapps.timeslots.models import TimeSlot | ||
|
||
# Create your models here. | ||
|
||
class Class(models.Model): | ||
""" University Class Model """ | ||
id = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=200) | ||
type = models.CharField(max_length=10) | ||
|
||
day_of_week = models.IntegerField() | ||
week_number = models.IntegerField() | ||
|
||
room = models.ForeignKey(Room, related_name="classes", on_delete=models.CASCADE) | ||
group = models.ForeignKey(Group, related_name="classes", on_delete=models.CASCADE) | ||
teacher = models.ForeignKey(Teacher, related_name="classes", on_delete=models.CASCADE) | ||
time_slot = models.ForeignKey(TimeSlot, related_name="classes", on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
db_table = "class" | ||
|
||
def __repr__(self): | ||
short_name = self.name[:10] + "..." if len(self.name) > 10 else self.name | ||
|
||
return f"<Class id={self.id} name='{short_name}' class_type='{self.type}' " \ | ||
f"room_id={self.room_id} teacher_id={self.teacher_id} group_id={self.group_id} " \ | ||
f"day_of_week={self.day_of_week} week_number={self.week_number} class_time_id={self.time_slot_id}>" |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from rest_framework import serializers | ||
from djangoapps.classes.models import Class | ||
from djangoapps.groups.serializers import GroupSerializer | ||
from djangoapps.rooms.serializers import RoomSerializer | ||
from djangoapps.teachers.serializers import TeacherSerializer | ||
|
||
|
||
class ClassSerializer(serializers.ModelSerializer): | ||
""" Serializer to represent the Class model """ | ||
teacher = TeacherSerializer() | ||
room = RoomSerializer() | ||
group = GroupSerializer() | ||
|
||
class Meta: | ||
model = Class | ||
fields = "__all__" | ||
|
||
|
||
class ClassWithoutGroupSerializer(serializers.ModelSerializer): | ||
""" Serializer to represent the Class model without Room """ | ||
teacher = TeacherSerializer() | ||
room = RoomSerializer() | ||
|
||
class Meta: | ||
model = Class | ||
fields = ("id", "name", "type", "day_of_week", "week_number", "teacher", | ||
"room", "time_slot") |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rest_framework import routers | ||
from django.conf.urls import url, include | ||
|
||
|
||
from djangoapps.classes.views import ClassViewSet, ClassesByGroupList | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r'classes', ClassViewSet, basename='classes') | ||
|
||
urlpatterns = [ | ||
url(r'^classes/group/(?P<group>.+)/$', | ||
ClassesByGroupList.as_view(), name="classes-by-group"), | ||
|
||
url(r'', include(router.urls)), | ||
] |
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,3 +1,53 @@ | ||
from django.shortcuts import render | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.db.models.query import QuerySet | ||
from rest_framework import generics, status | ||
from rest_framework.exceptions import APIException, NotFound, ParseError | ||
from rest_framework.viewsets import ReadOnlyModelViewSet | ||
|
||
# Create your views here. | ||
from djangoapps.classes.models import Class | ||
from djangoapps.groups.models import Group | ||
from djangoapps.classes.serializers import ClassSerializer, ClassWithoutGroupSerializer | ||
|
||
|
||
class ClassViewSet(ReadOnlyModelViewSet): | ||
""" | ||
A simple ViewSet for viewing all classes with all data. | ||
""" | ||
queryset = Class.objects.all() | ||
serializer_class = ClassSerializer | ||
|
||
|
||
class ClassesByGroupList(generics.ListAPIView): | ||
""" | ||
A list of classes by group name of group id. | ||
""" | ||
serializer_class = ClassWithoutGroupSerializer | ||
|
||
def get_queryset(self): | ||
group_id: int or None = None | ||
group_name: str or None = None | ||
|
||
group_raw: str = self.kwargs["group"] | ||
if '-' in group_raw: | ||
if group_raw.index('-') != 0 and group_raw.index('-') != (len(group_raw) - 1): | ||
group_name = group_raw.lower() | ||
else: | ||
raise ParseError | ||
else: | ||
try: | ||
group_id = int(group_raw) | ||
except ValueError: | ||
raise ParseError | ||
|
||
if group_id is not None: | ||
classes = Class.objects.filter(group_id=group_id) | ||
if classes: | ||
return classes | ||
else: | ||
raise NotFound | ||
else: | ||
try: | ||
group: Group = Group.objects.get(name=group_name) | ||
return Class.objects.filter(group_id=group.id) | ||
except ObjectDoesNotExist: | ||
raise NotFound |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class GroupsConfig(AppConfig): | ||
name = "groups" | ||
name = 'groups' |
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,3 +1,16 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
|
||
class Group(models.Model): | ||
""" Group Model """ | ||
id = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=15) | ||
|
||
class Meta: | ||
db_table = "group" | ||
ordering = ["name"] | ||
|
||
def __str__(self): | ||
return f"<Group id={self.id} name='{self.name}'>" |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework import serializers | ||
from djangoapps.groups.models import Group | ||
|
||
|
||
class GroupSerializer(serializers.ModelSerializer): | ||
""" Serializer to represent the Group model """ | ||
|
||
class Meta: | ||
model = Group | ||
fields = ("id", "name") | ||
|
||
read_only_fields = ("id",) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.conf.urls import url | ||
from django.urls import include | ||
from rest_framework import routers | ||
|
||
from djangoapps.groups.views import GroupViewSet, GroupSearchByNameList | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r'groups', GroupViewSet, basename='groups') | ||
|
||
urlpatterns = [ | ||
url(r'^groups/search/(?P<searchRequest>.+)$', | ||
GroupSearchByNameList.as_view(), name="groups-search"), | ||
|
||
url(r'', include(router.urls)), | ||
] |
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,3 +1,22 @@ | ||
from django.shortcuts import render | ||
from rest_framework import generics | ||
from rest_framework.viewsets import ReadOnlyModelViewSet | ||
|
||
# Create your views here. | ||
from djangoapps.groups.models import Group | ||
from djangoapps.groups.serializers import GroupSerializer | ||
|
||
|
||
class GroupViewSet(ReadOnlyModelViewSet): | ||
""" | ||
A simple ViewSet for viewing groups. | ||
""" | ||
|
||
queryset = Group.objects.all() | ||
serializer_class = GroupSerializer | ||
|
||
|
||
class GroupSearchByNameList(generics.ListAPIView): | ||
serializer_class = GroupSerializer | ||
|
||
def get_queryset(self): | ||
request = self.kwargs["searchRequest"] | ||
return Group.objects.filter(name__contains=request) |
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,3 +1,15 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
class Room(models.Model): | ||
""" University Room Model """ | ||
id = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=30) | ||
university_building = models.IntegerField() | ||
|
||
class Meta: | ||
db_table = "room" | ||
ordering = ("university_building",) | ||
|
||
def __repr__(self): | ||
return f"<Room id={self.id} room_name='{self.name}' university_building={self.university_building}>" |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from rest_framework import serializers | ||
from djangoapps.rooms.models import Room | ||
|
||
|
||
class RoomSerializer(serializers.ModelSerializer): | ||
""" Serializer to represent the Room model """ | ||
|
||
class Meta: | ||
model = Room | ||
fields = ("id", "name", "university_building",) | ||
|
||
read_only_fields = ("id",) | ||
|
||
|
||
class RoomBuildingOnlySerializer(serializers.ModelSerializer): | ||
""" Serializer to represent a building value from Room model """ | ||
|
||
class Meta: | ||
model = Room | ||
fields = ("university_building",) | ||
|
||
def to_representation(self, instance: Room): | ||
return instance.university_building |
Oops, something went wrong.