Commit c31d0ed8 authored by nachtgold's avatar nachtgold
Browse files

code upload is working

parent c3337f63
......@@ -22,5 +22,5 @@ urlpatterns = [
path('docs/', include('docs.urls')),
path('api/v1/', include('api.urls')),
path('api/v2/', include('apiv2.urls')),
path('api/v2/docs/', get_swagger_view(title='Snake REST API')),
path('api/v2/docs/', get_swagger_view(title='Snake v2 REST API beta')),
]
from core.models import SnakeVersion, UserProfile
from rest_framework.serializers import ModelSerializer
class SnakeVersionSerializer(ModelSerializer):
class Meta:
model = SnakeVersion
fields = ('id', 'parent', 'version', 'created',
'comment', 'server_error_message')
'comment', 'server_error_message', 'code')
extra_kwargs = {'id': {'read_only': True},
'parent': {'read_only': True},
'version': {'read_only': True},
'created': {'read_only': True},
'server_error_message': {'read_only': True},
'code': {'write_only': True}}
class UserProfileKeySerializer(ModelSerializer):
class Meta:
model = UserProfile
fields = ('viewer_key',)
\ No newline at end of file
fields = ('viewer_key',)
......@@ -4,7 +4,7 @@ from rest_framework.decorators import api_view
from rest_framework.routers import DefaultRouter
from rest_framework.response import Response
from rest_framework.reverse import reverse
from .viewsets import SnakeVersionViewSet, UserProfileKeyView
from .views import SnakeVersionViewSet, UserProfileKeyView
router = DefaultRouter()
router.register(r'version', SnakeVersionViewSet)
......
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from rest_framework import viewsets, generics
from rest_framework import viewsets, generics, mixins
from rest_framework.request import Request
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
......@@ -9,19 +10,24 @@ from rest_framework.serializers import BaseSerializer
from core.models import SnakeVersion, UserProfile, ServerCommand
from .serializer import SnakeVersionSerializer, UserProfileKeySerializer
class SnakeVersionViewSet(viewsets.ReadOnlyModelViewSet):
class SnakeVersionViewSet(mixins.CreateModelMixin,
mixins.ListModelMixin,
viewsets.GenericViewSet):
permission_classes = (IsAuthenticated,)
serializer_class = SnakeVersionSerializer
queryset = SnakeVersion.objects.none() # Required for DjangoModelPermissions
def get_serializer_class(self):
if self.request.method == 'POST':
if self.action == 'activate' and self.request.method == 'POST':
return BaseSerializer
return SnakeVersionSerializer
def get_queryset(self, *args, **kwargs):
return SnakeVersion.objects.all().filter(user=self.request.user)
def perform_create(self, serializer):
serializer.save(user=self.request.user)
@action(detail=False)
def active(self, request, *args, **kwargs):
snake_version = UserProfile.objects.all().filter(user=self.request.user).first().active_snake
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment