Skip to content

Commit

Permalink
feat: added serializers to watchlist and news
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Oct 11, 2023
1 parent 1f7c64c commit d235532
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ profilepictures/
# For Rope Project settings
.ropeproject

.python-version

env/
venv/
Expand Down
26 changes: 17 additions & 9 deletions news/event_urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from django.urls import path

from . import views
from .ical import HSEventFeed, HSEventSingleFeed
from .views import template_views

app_name = "events"
urlpatterns = [
path("", views.EventListView.as_view(), name="all"),
path("<int:pk>/", views.EventView.as_view(), name="details"),
path("<int:pk>/edit/", views.EventUpdateView.as_view(), name="edit"),
path("<int:pk>/attended/", views.EventAttendeeEditView.as_view(), name="attended"),
path("<int:pk>/skills/", views.EventAttendeeSkillsView.as_view(), name="skills"),
path("new", views.EventCreateView.as_view(), name="new"),
path("<int:pk>/delete/", views.EventDeleteView.as_view(), name="delete"),
path("<int:event_id>/register/", views.register_on_event, name="register"),
path("", template_views.EventListView.as_view(), name="all"),
path("<int:pk>/", template_views.EventView.as_view(), name="details"),
path("<int:pk>/edit/", template_views.EventUpdateView.as_view(), name="edit"),
path(
"<int:pk>/attended/",
template_views.EventAttendeeEditView.as_view(),
name="attended",
),
path(
"<int:pk>/skills/",
template_views.EventAttendeeSkillsView.as_view(),
name="skills",
),
path("new", template_views.EventCreateView.as_view(), name="new"),
path("<int:pk>/delete/", template_views.EventDeleteView.as_view(), name="delete"),
path("<int:event_id>/register/", template_views.register_on_event, name="register"),
path("feed.ics", HSEventFeed()),
path("<int:pk>/feed.ics", HSEventSingleFeed()),
]
22 changes: 22 additions & 0 deletions news/serializers/article.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from rest_framework import serializers

from news.models import Article


class ArticleListSerializer(serializers.ModelSerializer):
class Meta:
model = Article
fields = (
"id",
"title",
"ingress_content",
"internal",
"pub_date",
"thumbnail",
)


class ArticleRetrieveSerializer(ArticleListSerializer):
class Meta:
model = Article
fields = "__all__"
22 changes: 22 additions & 0 deletions news/serializers/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from rest_framework import serializers

from news.models import Event


class EventListSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = fields = (
"id",
"title",
"ingress_content",
"internal",
"pub_date",
"thumbnail",
)


class EventRetrieveSerializer(EventListSerializer):
class Meta:
model = Event
fields = "__all__"
9 changes: 9 additions & 0 deletions news/serializers/event_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import serializers

from news.models import EventRegistration


class EventRegistrationSerializer(serializers.ModelSerializer):
class Meta:
model = EventRegistration
fields = "__all__"
9 changes: 9 additions & 0 deletions news/serializers/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import serializers

from news.models import Upload


class UploadSerializer(serializers.ModelSerializer):
class Meta:
model = Upload
fields = "__all__"
18 changes: 12 additions & 6 deletions news/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from django.conf.urls import url

from . import views
from .views import template_views

app_name = "news"
urlpatterns = [
url(r"^$", views.ArticleListView.as_view(), name="all"),
url(r"^(?P<pk>[0-9]+)/$", views.ArticleView.as_view(), name="details"),
url(r"^(?P<pk>[0-9]+)/edit", views.ArticleUpdateView.as_view(), name="edit"),
url(r"^new", views.ArticleCreateView.as_view(), name="new"),
url(r"^(?P<pk>[0-9]+)/delete", views.ArticleDeleteView.as_view(), name="delete"),
url(r"^$", template_views.ArticleListView.as_view(), name="all"),
url(r"^(?P<pk>[0-9]+)/$", template_views.ArticleView.as_view(), name="details"),
url(
r"^(?P<pk>[0-9]+)/edit", template_views.ArticleUpdateView.as_view(), name="edit"
),
url(r"^new", template_views.ArticleCreateView.as_view(), name="new"),
url(
r"^(?P<pk>[0-9]+)/delete",
template_views.ArticleDeleteView.as_view(),
name="delete",
),
]
14 changes: 14 additions & 0 deletions news/views/article.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import viewsets

from news.models import Article
from news.serializers.article import ArticleListSerializer, ArticleRetrieveSerializer


class ArticleViewSet(viewsets.ModelViewSet):
queryset = Article.objects.all()
serializer_class = ArticleListSerializer

def get_serializer_class(self):
if self.action == "list":
return ArticleListSerializer
return ArticleRetrieveSerializer
14 changes: 14 additions & 0 deletions news/views/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import viewsets

from news.models import Event
from news.serializers.event import EventListSerializer, EventRetrieveSerializer


class EventViewSet(viewsets.ModelViewSet):
queryset = Event.objects.all()
serializer_class = EventListSerializer

def get_serializer_class(self):
if self.action == "list":
return EventListSerializer
return EventRetrieveSerializer
4 changes: 2 additions & 2 deletions news/views.py → news/views/template_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

from committees.models import Committee

from .forms import (
from ..forms import (
ArticleForm,
EventForm,
eventAttendeeFormSet,
eventSkillFormSet,
uploadformset,
)
from .models import Article, Event, EventRegistration
from ..models import Article, Event, EventRegistration


class EventView(DetailView):
Expand Down
9 changes: 9 additions & 0 deletions news/views/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import viewsets

from news.models import Upload
from news.serializers.upload import UploadSerializer


class UploadViewSet(viewsets.ModelViewSet):
queryset = Upload.objects.all()
serializer_class = UploadSerializer
9 changes: 9 additions & 0 deletions watchlist/serializers/shift_slot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import serializers

from watchlist.models import ShiftSlot


class ShiftSlotSerializer(serializers.ModelSerializer):
class Meta:
model = ShiftSlot
fields = "__all__"
17 changes: 12 additions & 5 deletions watchlist/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from django.urls import path

from . import views
from website.urls import api_router

from .views import shift_slot, template_views

app_name = "watchlist"
api_router.register("shiftslots", shift_slot.ShiftSlotViewSet)

urlpatterns = [
path("", views.watchlistView.as_view(), name="vaktliste"),
path("register/<int:pk>", views.WatchListRegisterView.as_view(), name="register"),
path("", template_views.watchlistView.as_view(), name="vaktliste"),
path(
"register/<int:pk>",
template_views.WatchListRegisterView.as_view(),
name="register",
),
path(
"unregister/<int:pk>",
views.WatchListUnregisterView.as_view(),
template_views.WatchListUnregisterView.as_view(),
name="unregister",
),
path("reset", views.WatchListResetView.as_view(), name="reset"),
path("reset", template_views.WatchListResetView.as_view(), name="reset"),
]
9 changes: 9 additions & 0 deletions watchlist/views/shift_slot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import viewsets

from watchlist.models import ShiftSlot
from watchlist.serializers.shift_slot import ShiftSlotSerializer


class ShiftSlotViewSet(viewsets.ModelViewSet):
queryset = ShiftSlot.objects.all()
serializer_class = ShiftSlotSerializer
4 changes: 2 additions & 2 deletions watchlist/views.py → watchlist/views/template_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from userprofile.models import Skill

from .models import ShiftSlot
from .utils import get_shift_weekview_columns, get_shift_weekview_rows
from ..models import ShiftSlot
from ..utils import get_shift_weekview_columns, get_shift_weekview_rows


class watchlistView(TemplateView):
Expand Down
6 changes: 6 additions & 0 deletions website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework import routers

from inventory.views.item import InventoryListAPIView
from news.views import article, event, upload
from search.views import SearchAPIView, SearchView
from userprofile.views import (
MembersAPIView,
Expand All @@ -17,6 +18,7 @@
TermsOfServiceCreateView,
TermsOfServiceView,
)
from watchlist.views import shift_slot
from website.views import (
AboutView,
AcceptTosRedirectView,
Expand All @@ -34,6 +36,10 @@

# Add rest framework urls
api_router = routers.DefaultRouter()
api_router.register("upload", upload.UploadViewSet)
api_router.register("event", event.EventViewSet)
api_router.register("article", article.ArticleViewSet)
api_router.register("shiftslot", shift_slot.ShiftSlotViewSet)

urlpatterns = [
path("", IndexView.as_view(), name="index"),
Expand Down

0 comments on commit d235532

Please sign in to comment.