fogot a file

This commit is contained in:
Qwann 2017-07-18 17:48:59 +02:00
parent c8483ca7fb
commit 1924d9b81a
8 changed files with 109 additions and 0 deletions

12
api/event/serializers.py Normal file
View file

@ -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')

19
api/event/views.py Normal file
View file

@ -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)

15
api/urls.py Normal file
View file

@ -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'))
]

38
api/user/serializers.py Normal file
View file

@ -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',)

0
api/user/views.py Normal file
View file

View file

@ -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",
},
}

View file

@ -9,6 +9,7 @@ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^event/', include('event.urls')), url(r'^event/', include('event.urls')),
url(r'^user/', include('users.urls')), url(r'^user/', include('users.urls')),
url(r'^api/', include('api.urls')),
url(r'^', include('shared.urls')), url(r'^', include('shared.urls')),
] ]

View file

@ -5,6 +5,7 @@ Pillow
channels channels
django-bootstrap-form==3.2.1 django-bootstrap-form==3.2.1
django-widget-tweaks django-widget-tweaks
djangorestframework==3.6.3
# Production specific # Production specific
daphne daphne