From bab3a38a2e7950b27d99fbc321e29ca295211130 Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 6 Jul 2016 01:32:34 +0200 Subject: [PATCH] Small subscription fix --- subscription/models.py | 18 ------------------ subscription/views.py | 10 +++++++++- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/subscription/models.py b/subscription/models.py index b8e624b2..63aa052a 100644 --- a/subscription/models.py +++ b/subscription/models.py @@ -20,9 +20,6 @@ class Subscriber(User): class Meta: proxy = True - def __init__(self, *args, **kwargs): - super(Subscriber, self).__init__(*args, **kwargs) - def is_subscribed(self): s = self.subscriptions.last() 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(): 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: ordering = ['subscription_start',] diff --git a/subscription/views.py b/subscription/views.py index d08bc781..4aa96c98 100644 --- a/subscription/views.py +++ b/subscription/views.py @@ -19,7 +19,7 @@ class SubscriptionForm(forms.ModelForm): model = Subscription 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' form_class = SubscriptionForm @@ -27,3 +27,11 @@ class NewSubscription(CanEditMixin, CreateView): if 'member' in self.request.GET.keys(): return {'member': self.request.GET['member']} 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)