From 9b0eeff865bb39454f201eb82b460fdc27899a90 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 29 Nov 2018 12:27:07 -0800 Subject: Django - Add Infractions API (#149) * add Infraction model and serialiser The model in not finalised. * fix mix up of serialiser fields * remove explicit id field and add foreign keys * remove unused import * disallow null for user * add view set and route * fix model and create migration * fix typo choice => choices * specify names for reverse accessors for User FKs * add django-filter * add filters to view set * add string dunder method to model * add list/retrieve tests * make reason nullable * add creation tests * remove support for PUT and DELETE * add support for PATCH * assert timestamps using strings rather than datetimes This is done to keep 3.6 support; datetime.fromisoformat() is 3.7+ * assert inserted_at * add unauthenticated tests * add bad value tests for list filters and retrieve * remove prefetch cache invalidation * make __str__ more descriptive * add field validation & remove note type * add tests for field validation * fix coverage for Infraction string dunder test * fix coverage (for sure this time) * return 400 for partial updates with frozen fields * add expanded serialiser and endpoints * test expanded endpoints * remove extra retrieve call * remove unnecessary try-finally blocks * remove extra blank line * document endpoints (except expanded) * document expanded routes * fix wrong routes in docstring (/infraction -> /infractions) * make merge migration --- api/urls.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'api/urls.py') diff --git a/api/urls.py b/api/urls.py index 59853934..af275381 100644 --- a/api/urls.py +++ b/api/urls.py @@ -3,7 +3,7 @@ from rest_framework.routers import DefaultRouter from .views import HealthcheckView from .viewsets import ( - DocumentationLinkViewSet, + DocumentationLinkViewSet, InfractionViewSet, OffTopicChannelNameViewSet, SnakeFactViewSet, SnakeIdiomViewSet, SnakeNameViewSet, SpecialSnakeViewSet, @@ -17,15 +17,15 @@ bot_router.register( 'documentation-links', DocumentationLinkViewSet ) +bot_router.register( + 'infractions', + InfractionViewSet +) bot_router.register( 'off-topic-channel-names', OffTopicChannelNameViewSet, base_name='offtopicchannelname' ) -bot_router.register( - 'users', - UserViewSet -) bot_router.register( 'snake-facts', SnakeFactViewSet @@ -47,6 +47,10 @@ bot_router.register( 'tags', TagViewSet ) +bot_router.register( + 'users', + UserViewSet +) app_name = 'api' urlpatterns = ( -- cgit v1.2.3