Commit d685e9ba authored by Sli's avatar Sli

Election bdd + first view

parent 0280a656
......@@ -15,6 +15,8 @@ from club.models import Club, Membership
from subscription.models import Subscription
from counter.models import Customer, ProductType, Product, Counter
from com.models import Sith
from election.models import Election, Responsability, Candidate
class Command(BaseCommand):
help = "Populate a new instance of the Sith AE"
......@@ -122,6 +124,14 @@ Welcome to the wiki page!
skia.save()
skia.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
skia.save()
# Adding user sli
sli = User(username='sli', last_name="Li", first_name="S",
email="sli@git.an",
date_of_birth="1942-06-12")
sli.set_password("plop")
sli.save()
skia.view_groups=[Group.objects.filter(name=settings.SITH_MAIN_MEMBERS_GROUP).first().id]
sli.save()
# Adding user public
public = User(username='public', last_name="Not subscribed", first_name="Public",
email="public@git.an",
......@@ -219,6 +229,14 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
start=s.subscription_start)
s.save()
## Sli
s = Subscription(member=Subscriber.objects.filter(pk=sli.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end(
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
start=s.subscription_start)
s.save()
## Comptable
s = Subscription(member=User.objects.filter(pk=comptable.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
......@@ -329,5 +347,12 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
target_label=op[7], cheque_number=op[8])
operation.clean()
operation.save()
# Create an election
el = Election(title="Élection 2017", description="La roue tourne", start_date='1942-06-12 10:28:45', end_date='7942-06-12 10:28:45')
el.save()
resp = Responsability(election=el, title="Co Respo Info", description="Ghetto++")
resp.save()
cand = Candidate(responsability=resp, subscriber=skia)
cand.save()
from django.contrib import admin
# Register your models here.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('subscription', '0003_auto_20160902_1914'),
]
operations = [
migrations.CreateModel(
name='Candidate',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('votes', models.IntegerField(default=0, verbose_name='votes')),
],
),
migrations.CreateModel(
name='Election',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('title', models.CharField(verbose_name='title', max_length=255)),
('description', models.TextField(blank=True, null=True, verbose_name='description')),
('start_date', models.DateTimeField(verbose_name='start date')),
('end_date', models.DateTimeField(verbose_name='end date')),
],
),
migrations.CreateModel(
name='Responsability',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('title', models.CharField(verbose_name='title', max_length=255)),
('description', models.TextField(blank=True, null=True, verbose_name='description')),
('blank_votes', models.IntegerField(default=0, verbose_name='blank votes')),
('election', models.ForeignKey(to='election.Election', related_name='election', verbose_name='election')),
],
),
migrations.AddField(
model_name='candidate',
name='responsability',
field=models.ForeignKey(to='election.Responsability', related_name='responsability', verbose_name='responsability'),
),
migrations.AddField(
model_name='candidate',
name='subscriber',
field=models.ForeignKey(related_name='candidate', to='subscription.Subscriber', blank=True, verbose_name='user'),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('election', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='candidate',
name='program',
field=models.TextField(verbose_name='description', null=True, blank=True),
),
]
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django.conf import settings
from datetime import timedelta
from core.models import User
from subscription.models import Subscriber
from subscription.views import get_subscriber
class Election(models.Model):
"""
This class allow to create a new election
"""
title = models.CharField(_('title'), max_length=255)
description = models.TextField(_('description'), null=True, blank=True)
start_date = models.DateTimeField(_('start date'), blank=False)
end_date = models.DateTimeField(_('end date'), blank=False)
def __str__(self):
return self.title
@property
def is_active(self):
now = timezone.now()
return bool(now <= self.end_date and now >= self.start_date)
def get_results(self):
pass
class Responsability(models.Model):
"""
"""
election = models.ForeignKey(Election, related_name='election', verbose_name=_("election"))
title = models.CharField(_('title'), max_length=255)
description = models.TextField(_('description'), null=True, blank=True)
blank_votes = models.IntegerField(_('blank votes'), default=0)
def __str__(self):
return ("%s : %s") % (self.election.title, self.title)
class Candidate(models.Model):
"""
"""
responsability = models.ForeignKey(Responsability, related_name='responsability', verbose_name=_("responsability"))
subscriber = models.ForeignKey(Subscriber, verbose_name=_('user'), related_name='candidate', blank=True)
program = models.TextField(_('description'), null=True, blank=True)
votes = models.IntegerField(_('votes'), default=0)
def __str__(self):
return ("%s : %s -> %s") % (self.election.title, self.title, self.subscriber.get_full_name())
{% extends "core/base.jinja" %}
{% block title %}
{% trans %}Election list{% endtrans %}
{% endblock %}
{% block content %}
{% for el in object_list %}
{% if el.is_active %}
<p>{{el}}</p>
{% endif %}
{% endfor %}
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url, include
from election.views import *
urlpatterns = [
url(r'^$', ElectionsListView.as_view(), name='election_list'),
]
\ No newline at end of file
from django.shortcuts import render
from django.views.generic import ListView, DetailView, RedirectView
from django.views.generic.edit import UpdateView, CreateView, DeleteView, FormView
from django.core.urlresolvers import reverse_lazy, reverse
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
from election.models import Election, Responsability, Candidate
# Display elections
class ElectionsListView(CanViewMixin, ListView):
"""
A list with all responsabilities and their candidates
"""
model = Election
template_name = 'election/election_list.jinja'
......@@ -58,6 +58,7 @@ INSTALLED_APPS = (
'rootplace',
'sas',
'com',
'election',
)
MIDDLEWARE_CLASSES = (
......
......@@ -39,6 +39,7 @@ urlpatterns = [
url(r'^launderette/', include('launderette.urls', namespace="launderette", app_name="launderette")),
url(r'^sas/', include('sas.urls', namespace="sas", app_name="sas")),
url(r'^api/v1/', include('api.urls', namespace="api", app_name="api")),
url(r'^election/', include('election.urls', namespace="election", app_name="election")),
url(r'^admin/', include(admin.site.urls)),
url(r'^ajax_select/', include(ajax_select_urls)),
url(r'^i18n/', include('django.conf.urls.i18n')),
......
Markdown is supported
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