Commit 8fc360a9 authored by Skia's avatar Skia

Improve subscription and add it to admin app

parent f71ce2f7
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 = [
('ae', '0001_initial'),
operations = [
field=models.CharField(verbose_name='subscription type', max_length=255, choices=[('cursus-branche', 'Cursus Branche'), ('cursus-tronc-commun', 'Cursus Tronc Commun'), ('deux-semestres', 'Deux semestres'), ('un-semestre', 'Un semestre')]),
from django.contrib import admin
from core.models import User, Page, Group
from django.contrib.auth.models import Group as AuthGroup
......@@ -38,7 +38,7 @@ INSTALLED_APPS = (
......@@ -151,19 +151,23 @@ AE_PAYMENT_METHOD = [('cheque', 'Chèque'),
# Subscription durations are in semestres (should be settingized)
'Un semestre': {
'un-semestre': {
'name': 'Un semestre',
'price': 15,
'duration': 1,
'Deux semestres': {
'deux-semestres': {
'name': 'Deux semestres',
'price': 28,
'duration': 2,
'Cursus Tronc Commun': {
'cursus-tronc-commun': {
'name': 'Cursus Tronc Commun',
'price': 45,
'duration': 4,
'Cursus Branche': {
'cursus-branche': {
'name': 'Cursus Branche',
'price': 45,
'duration': 6,
......@@ -23,6 +23,6 @@ handler404 = "core.views.not_found"
urlpatterns = [
url(r'^', include('core.urls', namespace="core", app_name="core")),
url(r'^ae/', include('ae.urls', namespace="ae", app_name="ae")),
url(r'^subscription/', include('subscription.urls', namespace="asso", app_name="subscription")),
url(r'^admin/', include(,
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!
from django.contrib import admin
from subscription.models import Member, Subscription
......@@ -8,25 +8,25 @@ from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('core', '0002_auto_20151215_0827'),
('core', '0005_auto_20160128_0842'),
operations = [
('user', models.OneToOneField(primary_key=True, to=settings.AUTH_USER_MODEL, serialize=False)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL, primary_key=True, serialize=False)),
('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')),
('subscription_type', models.CharField(choices=[('cursus branche', 'Cursus Branche'), ('cursus tronc commun', 'Cursus Tronc Commun'), ('deux semestres', 'Deux semestres'), ('un semestre', 'Un semestre')], verbose_name='subscription type', max_length=255)),
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('subscription_type', models.CharField(choices=[('cursus-branche', 'Cursus Branche'), ('cursus-tronc-commun', 'Cursus Tronc Commun'), ('deux-semestres', 'Deux semestres'), ('un-semestre', 'Un semestre')], verbose_name='subscription type', max_length=255)),
('subscription_start', models.DateField(verbose_name='subscription start')),
('subscription_end', models.DateField(verbose_name='subscription end')),
('payment_method', models.CharField(choices=[('cheque', 'Chèque'), ('cash', 'Espèce'), ('other', 'Autre')], verbose_name='payment method', max_length=255)),
('member', models.ForeignKey(related_name='subscriptions', to='ae.Member')),
('member', models.ForeignKey(to='subscription.Member', related_name='subscriptions')),
'ordering': ['subscription_start'],
......@@ -20,18 +20,39 @@ class Member(models.Model):
def is_subscribed(self):
return self.subscriptions.last().is_valid_now()
def __str__(self):
return self.user.username
class Subscription(models.Model):
member = models.ForeignKey(Member, related_name='subscriptions')
subscription_type = models.CharField(_('subscription type'),
choices=((k.lower().replace(' ', '-'), k) for k in sorted(settings.AE_SUBSCRIPTIONS.keys())))
choices=((k, v['name']) for k,v in sorted(settings.AE_SUBSCRIPTIONS.items())))
subscription_start = models.DateField(_('subscription start'))
subscription_end = models.DateField(_('subscription end'))
payment_method = models.CharField(_('payment method'), max_length=255, choices=settings.AE_PAYMENT_METHOD)
def save(self, *args, **kwargs):
This makes the Subscription to be updated with right dates with respect to each time you save the
Subscription object.
It means that you must be careful when modifying old Subscription, because you could make
someone that had no more valid subscription to get one again!
TODO: FIXME by putting it in the right function that would be triggered only when using the right Form!!!!
self.subscription_start = self.compute_start()
self.subscription_end = self.compute_end(
super(Subscription, self).save(*args, **kwargs)
class Meta:
ordering = ['subscription_start',]
def __str__(self):
return self.member.user.username+' - '+str(
def compute_start(
from django.conf.urls import url, include
from ae.views import *
from subscription.views import *
urlpatterns = [
# Subscription views
......@@ -4,7 +4,7 @@ from django import forms
from django.forms import Select
from django.conf import settings
from ae.models import Member, Subscription
from subscription.models import Member, Subscription
from core.views import CanEditMixin, CanEditPropMixin, CanViewMixin
class SubscriptionForm(forms.ModelForm):
......@@ -17,5 +17,5 @@ class SubscriptionForm(forms.ModelForm):
class NewSubscription(CanEditMixin, CreateView):
template_name = 'ae/subscription.html'
template_name = 'subscription/subscription.html'
form_class = SubscriptionForm
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