some cleanup

This commit is contained in:
Sayyid Hamid Mahdavi 2025-12-03 10:52:57 +03:30
parent 89768fa02e
commit 7eff9739fd
4 changed files with 20 additions and 5 deletions

View file

@ -4,8 +4,11 @@ from django.contrib import admin
from .models import Promotion, Plan, Event, Recipient, EventSaver
class PromotionAdmin(admin.ModelAdmin):
list_display = ['user_uuid', 'plan', 'promotion_amount', 'recipient', 'event', 'created_at']
admin.site.register(Plan)
admin.site.register(Promotion)
admin.site.register(Promotion, PromotionAdmin)
admin.site.register(Event)
admin.site.register(EventSaver)
admin.site.register(Recipient)

View file

@ -10,9 +10,9 @@ from .views import ApplicationPromoteUserApiView, ApplicationEventSubmitAPIView,
app_name = 'promotions'
router = DefaultRouter()
router.register(r'application', views.ApplicationPromotionViewSet, basename='application_promotions')
router.register(r'events', views.ApplicationViewSet, basename='application-events')
router.register(r'plans', views.UserViewSet, basename='user')
# router.register(r'application', views.ApplicationPromotionViewSet, basename='application_promotions')
# router.register(r'events', views.ApplicationViewSet, basename='application-events')
# router.register(r'plans', views.UserViewSet, basename='user')
# urlpatterns =

View file

@ -8,6 +8,7 @@ from rest_framework.viewsets import GenericViewSet
from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
from apps.gooyal_oauth2.utils import get_application
from utils.exceptions import UnprocessableEntity
from .models import Plan, Promotion, EventSaver
from .serializers import PlanSerializer, PromotionSerializer, EventSerializer, PromoteSerializer
from .tasks import analyze_event_task
@ -225,7 +226,10 @@ class ApplicationEventSubmitAPIView(CreateAPIView):
data = serializer.validated_data
application = get_application(self.request)
event_saver: EventSaver = EventSaver.objects.filter(event_label=serializer.validated_data['label']).first()
event = event_saver.save_event(user=None, application=application, **serializer.validated_data)
try:
event = event_saver.save_event(user=None, application=application, **serializer.validated_data)
except Exception as e:
raise UnprocessableEntity(str(e))
analyze_event_task.delay(event.uuid)

View file

@ -52,3 +52,11 @@ class ErrorMiddleware:
},
status=500
)
from rest_framework.exceptions import APIException
class UnprocessableEntity(APIException):
status_code = 422
default_detail = 'The request was well-formed but cannot be processed due to semantic errors.'
default_code = 'unprocessable_entity'