-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,5 @@ | ||
from django.contrib import admin | ||
|
||
from .models import EventSubTopic | ||
|
||
admin.site.register(EventSubTopic) |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class EventSubTopicsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'event_sub_topics' |
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,28 @@ | ||
# Generated by Django 5.0 on 2024-01-28 18:12 | ||
|
||
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(blank=True, max_length=2147483647, null=True)), | ||
('slug', models.CharField(blank=True, max_length=2147483647, null=True)), | ||
('event_topic', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='event_topics.eventtopic')), | ||
], | ||
options={ | ||
'unique_together': {('slug', 'event_topic')}, | ||
}, | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
event_sub_topics/migrations/0002_alter_eventsubtopic_name_alter_eventsubtopic_slug.py
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 @@ | ||
# Generated by Django 5.0 on 2024-01-29 14:19 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('event_sub_topics', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='eventsubtopic', | ||
name='name', | ||
field=models.CharField(blank=True, max_length=200, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='eventsubtopic', | ||
name='slug', | ||
field=models.CharField(blank=True, max_length=200, null=True), | ||
), | ||
] |
Empty file.
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,13 @@ | ||
from django.db import models | ||
from event_topics.models import EventTopic | ||
|
||
class EventSubTopic(models.Model): | ||
name = models.CharField(max_length=200, null=True, blank=True) | ||
slug = models.CharField(max_length=200, null=True, blank=True) | ||
event_topic = models.ForeignKey(EventTopic, on_delete=models.CASCADE, null=True, blank=True) | ||
|
||
class Meta: | ||
unique_together = (('slug', 'event_topic'),) | ||
|
||
def __str__(self): | ||
return 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,8 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import EventSubTopic | ||
|
||
class EventSubTopicSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = EventSubTopic | ||
fields = '__all__' |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,9 @@ | ||
from django.urls import path | ||
|
||
from .views import EventSubTopicPost, EventSubTopicList,EventSubTopicRetrieveUpdateDestroy | ||
|
||
urlpatterns = [ | ||
path("event-sub-topics/", EventSubTopicPost.as_view(), name="event_sub_topic_list_create"), | ||
path("event-sub-topics/<int:pk>/", EventSubTopicRetrieveUpdateDestroy.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"), | ||
] |
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,67 @@ | ||
from rest_framework import generics | ||
|
||
from open_event_api.permissions import IsSuperAdminForUpdate | ||
from rest_framework.exceptions import PermissionDenied | ||
|
||
from .serializer import EventSubTopicSerializer | ||
from .models import EventSubTopic,EventTopic | ||
|
||
class EventSubTopicPost(generics.CreateAPIView): | ||
""" | ||
Create event sub topics | ||
""" | ||
serializer_class = EventSubTopicSerializer | ||
|
||
def perform_create(self, serializer): | ||
""" | ||
Custom method to perform additional actions on object creation | ||
""" | ||
event_topic = self.request.data.get('event_topic') | ||
if not event_topic: | ||
raise serializer.ValidationError({'event_topic': 'This field is required.'}) | ||
serializer.save() | ||
|
||
|
||
class EventSubTopicList(generics.ListAPIView): | ||
""" | ||
List event sub topics | ||
""" | ||
serializer_class = EventSubTopicSerializer | ||
|
||
def get_queryset(self): | ||
queryset = EventSubTopic.objects.all() | ||
|
||
event_topic_id = self.kwargs.get('event_topic_id') | ||
if event_topic_id: | ||
event_topic = EventTopic.objects.all() | ||
if event_topic: | ||
queryset = queryset.all() | ||
|
||
return queryset | ||
|
||
class EventSubTopicRetrieveUpdateDestroy(generics.RetrieveUpdateDestroyAPIView): | ||
""" | ||
Retrieve, update or delete event sub topics | ||
""" | ||
queryset = EventSubTopic.objects.all() | ||
serializer_class = EventSubTopicSerializer | ||
permission_classes = [IsSuperAdminForUpdate] | ||
|
||
def put(self, request, *args, **kwargs): | ||
if not self.request.user.is_staff: | ||
raise PermissionDenied(detail='Admin access is required.') | ||
|
||
return super().put(request, *args, **kwargs) | ||
|
||
def patch(self, request, *args, **kwargs): | ||
if not self.request.user.is_staff: | ||
raise PermissionDenied(detail='Admin access is required.') | ||
|
||
return super().patch(request, *args, **kwargs) | ||
|
||
def delete(self, request, *args, **kwargs): | ||
if not self.request.user.is_staff: | ||
raise PermissionDenied(detail='Admin access is required.') | ||
|
||
return super().delete(request, *args, **kwargs) | ||
|
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