mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
Election bdd + first view
This commit is contained in:
parent
0280a65623
commit
d685e9ba29
@ -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])
|
||||
@ -330,4 +348,11 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
|
||||
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()
|
||||
|
||||
|
0
election/__init__.py
Normal file
0
election/__init__.py
Normal file
3
election/admin.py
Normal file
3
election/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
51
election/migrations/0001_initial.py
Normal file
51
election/migrations/0001_initial.py
Normal file
@ -0,0 +1,51 @@
|
||||
# -*- 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'),
|
||||
),
|
||||
]
|
19
election/migrations/0002_candidate_program.py
Normal file
19
election/migrations/0002_candidate_program.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- 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),
|
||||
),
|
||||
]
|
0
election/migrations/__init__.py
Normal file
0
election/migrations/__init__.py
Normal file
54
election/models.py
Normal file
54
election/models.py
Normal file
@ -0,0 +1,54 @@
|
||||
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())
|
13
election/templates/election/election_list.jinja
Normal file
13
election/templates/election/election_list.jinja
Normal file
@ -0,0 +1,13 @@
|
||||
{% 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 %}
|
3
election/tests.py
Normal file
3
election/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
7
election/urls.py
Normal file
7
election/urls.py
Normal file
@ -0,0 +1,7 @@
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from election.views import *
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', ElectionsListView.as_view(), name='election_list'),
|
||||
]
|
19
election/views.py
Normal file
19
election/views.py
Normal file
@ -0,0 +1,19 @@
|
||||
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')),
|
||||
|
Loading…
Reference in New Issue
Block a user