Commit bab3a38a authored by Skia's avatar Skia 🤘
Browse files

Small subscription fix

parent 5355492c
Pipeline #48 failed with stage
in 4 minutes and 26 seconds
......@@ -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 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',]
......@@ -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(
return super(NewSubscription, self).form_valid(form)
Supports Markdown
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