mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Club model implementation, various other changes
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from subscription.models import Member, Subscription
|
||||
from subscription.models import Subscriber, Subscription
|
||||
|
||||
|
||||
|
||||
admin.site.register(Member)
|
||||
admin.site.register(Subscriber)
|
||||
admin.site.register(Subscription)
|
||||
|
@ -2,34 +2,44 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0005_auto_20160128_0842'),
|
||||
('core', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Member',
|
||||
fields=[
|
||||
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL, primary_key=True, serialize=False)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Subscription',
|
||||
fields=[
|
||||
('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)),
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
|
||||
('subscription_type', models.CharField(choices=[('cursus-branche', 'Cursus Branche'), ('cursus-tronc-commun', 'Cursus Tronc Commun'), ('deux-semestres', 'Deux semestres'), ('un-semestre', 'Un semestre')], max_length=255, verbose_name='subscription type')),
|
||||
('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(to='subscription.Member', related_name='subscriptions')),
|
||||
('payment_method', models.CharField(choices=[('cheque', 'Chèque'), ('cash', 'Espèce'), ('other', 'Autre')], max_length=255, verbose_name='payment method')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['subscription_start'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Subscriber',
|
||||
fields=[
|
||||
],
|
||||
options={
|
||||
'proxy': True,
|
||||
},
|
||||
bases=('core.user',),
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='subscription',
|
||||
name='member',
|
||||
field=models.ForeignKey(related_name='subscriptions', to='subscription.Subscriber'),
|
||||
),
|
||||
]
|
||||
|
@ -3,6 +3,8 @@ from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from core.models import User
|
||||
|
||||
@ -14,17 +16,15 @@ def validate_payment(value):
|
||||
if value not in settings.AE_PAYMENT_METHOD:
|
||||
raise ValidationError(_('Bad payment method'))
|
||||
|
||||
class Member(models.Model):
|
||||
user = models.OneToOneField(User, primary_key=True)
|
||||
class Subscriber(User):
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
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')
|
||||
member = models.ForeignKey(Subscriber, related_name='subscriptions')
|
||||
subscription_type = models.CharField(_('subscription type'),
|
||||
max_length=255,
|
||||
choices=((k, v['name']) for k,v in sorted(settings.AE_SUBSCRIPTIONS.items())))
|
||||
@ -32,6 +32,17 @@ class Subscription(models.Model):
|
||||
subscription_end = models.DateField(_('subscription end'))
|
||||
payment_method = models.CharField(_('payment method'), max_length=255, choices=settings.AE_PAYMENT_METHOD)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
('change_subscription', 'Can make someone become a subscriber'),
|
||||
('view_subscription', 'Can view who is a subscriber'),
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
for s in Subscription.objects.filter(member=self.member).exclude(pk=self.pk).all():
|
||||
if s.is_valid_now():
|
||||
raise ValidationError(_('You can not subscribe many time for the same period'))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
This makes the Subscription to be updated with right dates with respect to date.today() each time you save the
|
||||
@ -50,8 +61,11 @@ class Subscription(models.Model):
|
||||
class Meta:
|
||||
ordering = ['subscription_start',]
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('core:user_profile', kwargs={'user_id': self.member.pk})
|
||||
|
||||
def __str__(self):
|
||||
return self.member.user.username+' - '+str(self.pk)
|
||||
return self.member.username+' - '+str(self.pk)
|
||||
|
||||
@staticmethod
|
||||
def compute_start(d=date.today()):
|
||||
|
@ -4,7 +4,7 @@ from subscription.views import *
|
||||
|
||||
urlpatterns = [
|
||||
# Subscription views
|
||||
url(r'^subscription/(?P<user_id>[0-9]+)/$', NewSubscription.as_view(), name='subscription'),
|
||||
url(r'^$', NewSubscription.as_view(), name='subscription'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -4,13 +4,13 @@ from django import forms
|
||||
from django.forms import Select
|
||||
from django.conf import settings
|
||||
|
||||
from subscription.models import Member, Subscription
|
||||
from subscription.models import Subscriber, Subscription
|
||||
from core.views import CanEditMixin, CanEditPropMixin, CanViewMixin
|
||||
|
||||
class SubscriptionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Subscription
|
||||
fields = ['subscription_type', 'payment_method']
|
||||
fields = ['member', 'subscription_type', 'payment_method']
|
||||
#widgets = {
|
||||
# 'subscription_type': Select(choices={(k.lower(), k+" - "+str(v['price'])+"€"+str(Subscription.compute_end(2))) for k,v in settings.AE_SUBSCRIPTIONS.items()}),
|
||||
#}
|
||||
|
Reference in New Issue
Block a user