diff --git a/api/event/serializers.py b/api/event/serializers.py new file mode 100644 index 0000000..18bc74d --- /dev/null +++ b/api/event/serializers.py @@ -0,0 +1,12 @@ +from rest_framework import serializers +from event.models import Event +from django.contrib.auth import get_user_model + + +class EventSerializer(serializers.HyperlinkedModelSerializer): + created_by = serializers.ReadOnlyField(source='created_by.username') + + class Meta: + model = Event + fields = ('url', 'id', 'title', 'slug', 'created_by', 'creation_date', + 'description', 'begining_date', 'ending_date') diff --git a/api/event/views.py b/api/event/views.py new file mode 100644 index 0000000..0b05eb7 --- /dev/null +++ b/api/event/views.py @@ -0,0 +1,19 @@ +from django.contrib.auth import get_user_model + +from rest_framework.viewsets import ModelViewSet + +from api.event.serializers import EventSerializer +from event.models import Event + +User = get_user_model() + + +class EventViewSet(ModelViewSet): + """ + This viewset automatically provides `list` and `detail` actions. + """ + queryset = Event.objects.all() + serializer_class = EventSerializer + + def perform_create(self, serializer): + serializer.save(created_by=self.request.user) diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..660569c --- /dev/null +++ b/api/urls.py @@ -0,0 +1,15 @@ +from django.conf.urls import url, include +from rest_framework.routers import DefaultRouter +from api.event.views import EventViewSet + +# Create a router and register our viewsets with it. +router = DefaultRouter() +router.register(r'event', EventViewSet) + +# The API URLs are now determined automatically by the router. +# Additionally, we include the login URLs for the browsable API. +urlpatterns = [ + url(r'^', include(router.urls)), + url(r'^api-auth/', include('rest_framework.urls', + namespace='rest_framework')) +] diff --git a/api/user/serializers.py b/api/user/serializers.py new file mode 100644 index 0000000..8b83167 --- /dev/null +++ b/api/user/serializers.py @@ -0,0 +1,38 @@ +from rest_framework import serializers +from django.contrib.auth import get_user_model + +User = get_user_model() + + +class UserMinimalSerializer(serializers.HyperlinkedModelSerializer): + """ + Déstiné à tout le monde (de connecté) + """ + + class Meta: + model = User + fields = ('url', 'id', 'first_name', 'last_name',) + + +class UserAdminSerializer(serializers.HyperlinkedModelSerializer): + """ + Déstiné à l'utilisat-rice-eur et aux administrat-rice-eur-s + """ + + class Meta: + model = User + fields = ('url', 'id', 'username', 'first_name', 'last_name', + 'email', 'phone', 'last_login', 'date_joined',) + + +class UserSerializer(serializers.HyperlinkedModelSerializer): + """ + Déstiné aux utilisat-rice-eur-s dont l'utilisait-rice-eur-s en question + a laissé le droit d'y accéder, par exemple les participant-e-s + au même `event` que l'utilisat-rice-eur en question + """ + + class Meta: + model = User + fields = ('url', 'id', 'first_name', 'last_name', + 'email', 'phone',) diff --git a/api/user/views.py b/api/user/views.py new file mode 100644 index 0000000..e69de29 diff --git a/evenementiel/settings/devlocal.py b/evenementiel/settings/devlocal.py new file mode 100644 index 0000000..e420dda --- /dev/null +++ b/evenementiel/settings/devlocal.py @@ -0,0 +1,23 @@ +""" +Django development settings for GestionÉvénementiel +The settings that are not listed here are imported from .common +""" + +import os +from .dev import * # NOQA + + +# SQLite +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + +CHANNEL_LAYERS = { + "default": { + "BACKEND": "asgiref.inmemory.ChannelLayer", + "ROUTING": "evenementiel.routing.channel_routing", + }, +} diff --git a/evenementiel/urls.py b/evenementiel/urls.py index d83241d..3098985 100644 --- a/evenementiel/urls.py +++ b/evenementiel/urls.py @@ -9,6 +9,7 @@ urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^event/', include('event.urls')), url(r'^user/', include('users.urls')), + url(r'^api/', include('api.urls')), url(r'^', include('shared.urls')), ] diff --git a/requirements.txt b/requirements.txt index 54d9b30..9313a53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ Pillow channels django-bootstrap-form==3.2.1 django-widget-tweaks +djangorestframework==3.6.3 # Production specific daphne