Small subscription fix

This commit is contained in:
Skia 2016-07-06 01:32:34 +02:00
parent 5355492c76
commit bab3a38a2e
2 changed files with 9 additions and 19 deletions

View File

@ -20,9 +20,6 @@ class Subscriber(User):
class Meta: class Meta:
proxy = True proxy = True
def __init__(self, *args, **kwargs):
super(Subscriber, self).__init__(*args, **kwargs)
def is_subscribed(self): def is_subscribed(self):
s = self.subscriptions.last() s = self.subscriptions.last()
return s.is_valid_now() if s is not None else False return s.is_valid_now() if s is not None else False
@ -48,21 +45,6 @@ class Subscription(models.Model):
if s.is_valid_now(): if s.is_valid_now():
raise ValidationError(_('You can not subscribe many time for the same period')) 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
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(
duration=settings.SITH_SUBSCRIPTIONS[self.subscription_type]['duration'],
start=self.subscription_start)
super(Subscription, self).save(*args, **kwargs)
class Meta: class Meta:
ordering = ['subscription_start',] ordering = ['subscription_start',]

View File

@ -19,7 +19,7 @@ class SubscriptionForm(forms.ModelForm):
model = Subscription model = Subscription
fields = ['member', 'subscription_type', 'payment_method'] fields = ['member', 'subscription_type', 'payment_method']
class NewSubscription(CanEditMixin, CreateView): class NewSubscription(CanEditMixin, CreateView): # TODO: this must be able to create a new user if needed
template_name = 'subscription/subscription.jinja' template_name = 'subscription/subscription.jinja'
form_class = SubscriptionForm form_class = SubscriptionForm
@ -27,3 +27,11 @@ class NewSubscription(CanEditMixin, CreateView):
if 'member' in self.request.GET.keys(): if 'member' in self.request.GET.keys():
return {'member': self.request.GET['member']} return {'member': self.request.GET['member']}
return {} return {}
def form_valid(self, form):
form.instance.subscription_start = Subscription.compute_start()
form.instance.subscription_end = Subscription.compute_end(
duration=settings.SITH_SUBSCRIPTIONS[form.instance.subscription_type]['duration'],
start=form.instance.subscription_start
)
return super(NewSubscription, self).form_valid(form)