mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Small subscription fix
This commit is contained in:
parent
5355492c76
commit
bab3a38a2e
@ -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',]
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user