Skip to content

Commit

Permalink
Merge pull request EGCETSII#58 from Full-Tortuga/feature/EGCETSII#13-…
Browse files Browse the repository at this point in the history
…Votings-API

Feature/EGCETSII#13 votings api
  • Loading branch information
JSnow11 authored Jan 3, 2022
2 parents 43136b6 + 963416e commit d9b3c6d
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 114 deletions.
20 changes: 15 additions & 5 deletions decide/administration/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from census.models import Census
from voting.models import Question, QuestionOption, Voting
from rest_framework import serializers
from base.serializers import AuthSerializer


class UserAdminSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
Expand All @@ -20,6 +22,7 @@ class Meta:
model = QuestionOption
fields = ('id', 'number', 'option')


class UserUpdateSerializer(serializers.Serializer):
username = serializers.CharField(max_length=150, min_length=1)
first_name = serializers.CharField(max_length=30, allow_blank=True)
Expand All @@ -29,10 +32,11 @@ class UserUpdateSerializer(serializers.Serializer):

class AdminQuestionSerializer(serializers.ModelSerializer):
options = AdminQuestionOptionSerializer(many=True)

class Meta:
model = Question
fields = ('id','desc', 'options')
depht=1
fields = ('id', 'desc', 'options')
depth = 1

def create(self, validated_data):
options_data = validated_data.pop("options")
Expand All @@ -50,14 +54,20 @@ def update(self, instance, validated_data):
for option_data in options_data:
option = options.pop(0)
option.number = option_data.get("number", option.number)
option.option = option_data.get("option",option.option)
option.option = option_data.get("option", option.option)
option.save()
return instance




class CensusSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Census
fields = ('id', 'voting_id', 'voter_id')


class AdminVotingSerializer(serializers.Serializer):
question = AdminQuestionSerializer(many=False)
auth = serializers.URLField()
name = serializers.CharField(max_length=200)
desc = serializers.CharField(max_length=1000, allow_blank=True, allow_null=True)
census = serializers.ListField(allow_null=True)
8 changes: 4 additions & 4 deletions decide/administration/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.urls.conf import re_path

from . import views
from .views import QuestionsAPI, QuestionAPI

urlpatterns = [
# API
Expand All @@ -18,9 +17,10 @@
path('api/census', views.CensussAPI.as_view()),
path('api/census/<int:census_id>', views.CensusAPI.as_view()),
path('api/users/state', views.UpdateUserStateAPI.as_view()),
path('api/votings/question', QuestionsAPI.as_view()),
path('api/votings/question/<int:question_id>/', QuestionAPI.as_view()),

path('api/votings/question', views.QuestionsAPI.as_view()),
path('api/votings/question/<int:question_id>/', views.QuestionAPI.as_view()),
path('api/votings', views.VotingAPI.as_view()),
path('api/votings/<int:voting_id>/', views.VotingsAPI.as_view()),
# react-app
url('', views.index)
]
Loading

0 comments on commit d9b3c6d

Please sign in to comment.