Skip to content

Commit

Permalink
Add event sub topics feature
Browse files Browse the repository at this point in the history
  • Loading branch information
thealphadollar committed Dec 18, 2023
1 parent e0612c4 commit 3b7cb7f
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 0 deletions.
Empty file added event_sub_topics/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions event_sub_topics/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin

from .models import EventSubTopic

admin.site.register(EventSubTopic)
6 changes: 6 additions & 0 deletions event_sub_topics/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class EventSubTopicsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "event_sub_topics"
28 changes: 28 additions & 0 deletions event_sub_topics/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0 on 2023-12-18 13:47

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


class Migration(migrations.Migration):

initial = True

dependencies = [
('event_topics', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='EventSubTopic',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, null=True)),
('slug', models.CharField(max_length=200, null=True)),
('event_topic_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='event_topics.eventtopic')),
],
options={
'indexes': [models.Index(fields=['slug', 'event_topic_id'], name='event_sub_t_slug_e7fe13_idx')],
},
),
]
Empty file.
20 changes: 20 additions & 0 deletions event_sub_topics/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.db import models


class EventSubTopic(models.Model):
name = models.CharField(max_length=200, null=True)
slug = models.CharField(max_length=200, null=True)

event_topic_id = models.ForeignKey(
"event_topics.EventTopic",
on_delete=models.CASCADE,
null=True,
)

class Meta:
indexes = [
models.Index(fields=["slug", "event_topic_id"]),
]

def __str__(self):
return f"{self.name} ({self.slug}) - {self.event_topic_id}"
9 changes: 9 additions & 0 deletions event_sub_topics/serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import serializers

from .models import EventSubTopic


class EventSubTopicSerializer(serializers.ModelSerializer):
class Meta:
model = EventSubTopic
fields = ("id", "name", "slug", "event_topic_id")
1 change: 1 addition & 0 deletions event_sub_topics/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your tests here.
21 changes: 21 additions & 0 deletions event_sub_topics/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.urls import path

from .views import EventSubTopicCreate, EventSubTopicList, EventSubTopicRetrieve, EventSubTopicRetrieveUpdate

urlpatterns = [
path("event-sub-topics/", EventSubTopicCreate.as_view(), name="event_sub_topic_create"),
path("event-sub-topics/<int:pk>/", EventSubTopicRetrieveUpdate.as_view(), name="event_sub_topic_detail"),
path(
"event-topics/<int:event_topic_id>/event-sub-topics", EventSubTopicList.as_view(), name="event_sub_topic_list"
),
path(
"events/<int:event_id>/event-sub-topic",
EventSubTopicRetrieve.as_view(),
name="event_event_sub_topic_view_detail",
),
path(
"custom-placeholders/<int:custom_placeholder_id>/event-sub-topic",
EventSubTopicRetrieve.as_view(),
name="custom_placeholder_event_sub_topic_view_detail",
),
]
46 changes: 46 additions & 0 deletions event_sub_topics/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from rest_framework import generics

from open_event_api.permissions import IsSuperAdminForUpdate

from .models import EventSubTopic
from .serializer import EventSubTopicSerializer


class EventSubTopicCreate(generics.CreateAPIView):
"""Allows creation of EventSubTopic."""

serializer_class = EventSubTopicSerializer


class EventSubTopicList(generics.ListAPIView):
"""Allows listing EventSubTopic."""

queryset = EventSubTopic.objects.all()
serializer_class = EventSubTopicSerializer

# Fields to allow sorting by
ordering_fields = ["name"]


class EventSubTopicRetrieve(generics.RetrieveAPIView):
"""Allows viewing of the related EventSubTopic."""

queryset = EventSubTopic.objects.all()
serializer_class = EventSubTopicSerializer

def get(self, request, *args, **kwargs):
if kwargs.get("event_id") is not None:
# TODO: implement fetching event sub topic by event id
self.kwargs["pk"] = 1
if kwargs.get("custom_placeholder_id") is not None:
# TODO: implement fetching event sub topic by custom placeholder id
self.kwargs["pk"] = 1

return self.retrieve(request, *args, **kwargs)


class EventSubTopicRetrieveUpdate(generics.RetrieveUpdateAPIView):
"""Allows viewing and updating of EventSubTopic."""

permission_classes = (IsSuperAdminForUpdate,)
serializer_class = EventSubTopicSerializer
1 change: 1 addition & 0 deletions open_event_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"notification_contents.apps.NotificationContentsConfig",
"video_channels.apps.VideoChannelsConfig",
"services.apps.ServicesConfig",
"event_sub_topics.apps.EventSubTopicsConfig",
]

MIDDLEWARE = [
Expand Down
1 change: 1 addition & 0 deletions open_event_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
path("v2/", include("event_types.urls")),
path("v2/", include("panel_permissions.urls")),
path("v2/", include("services.urls")),
path("v2/", include("event_sub_topics.urls")),
path("v2/custom-system-roles/", include("custom_sys_roles.urls")),
# api docs via spectacular
path("v2/schema/", SpectacularAPIView.as_view(), name="schema"),
Expand Down

0 comments on commit 3b7cb7f

Please sign in to comment.