Commit 9ac1cab9 authored by Sli's avatar Sli
Browse files

Add vote in database

parent 97f835eb
......@@ -11,9 +11,10 @@ from django.conf import settings
from django import forms
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
from django.db.models.query import QuerySet
from django.views.generic.edit import FormMixin
from core.views.forms import SelectDateTime
from election.models import Election, Role, Candidature, ElectionList
from election.models import Election, Role, Candidature, ElectionList, Vote
from ajax_select.fields import AutoCompleteSelectField
......@@ -28,13 +29,14 @@ class VoteCheckbox(forms.ModelMultipleChoiceField):
def __init__(self, queryset, max_choice, required=True, widget=None, label=None,
initial=None, help_text='', *args, **kwargs):
self.max_choice = max_choice
widget = forms.CheckboxSelectMultiple
widget = forms.CheckboxSelectMultiple()
super(VoteCheckbox, self).__init__(queryset, None, required, widget, label,
initial, help_text, *args, **kwargs)
def clean(self, value):
qs = super(VoteCheckbox, self).clean(value)
return qs
def validate(self, qs):
if qs.count() > self.max_choice:
......@@ -157,7 +159,18 @@ class VoteFormView(CanCreateMixin, FormView):
return super(VoteFormView, self).dispatch(request, *arg, **kwargs)
def vote(self, data):
for key in data.keys():
if isinstance(data[key], QuerySet):
if data[key].count() > 0:
vote = Vote(role=data[key].first().role)
for el in data[key]:
elif data[key] is not None:
vote = Vote(role=data[key].role)
def get_form_kwargs(self):
kwargs = super(VoteFormView, self).get_form_kwargs()
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