X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/4b86e623b0ff7a5a53bdb29df06eab039ebe4e1e..48a8d1d73adefae7f0c58015494ce956d7cd70df:/src/club/models.py diff --git a/src/club/models.py b/src/club/models.py index a8b4089c7..ede1a8d30 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -31,7 +31,7 @@ class Plan(models.Model): verbose_name = _('plan') verbose_name_plural = _('plans') - def __unicode__(self): + def __str__(self): return "%s %s" % (self.min_amount, self.get_interval_display()) class Meta: @@ -74,7 +74,7 @@ class Schedule(models.Model): verbose_name = _('schedule') verbose_name_plural = _('schedules') - def __unicode__(self): + def __str__(self): return self.key def save(self, *args, **kwargs): @@ -88,7 +88,6 @@ class Schedule(models.Model): def get_payment_method(self): return method_by_slug[self.method] - def is_expired(self): return self.expires_at is not None and self.expires_at < now() @@ -109,7 +108,7 @@ class Payment(models.Model): verbose_name = _('payment') verbose_name_plural = _('payments') - def __unicode__(self): + def __str__(self): return "%s %s" % (self.schedule, self.payed_at) @@ -122,8 +121,18 @@ class Membership(models.Model): verbose_name = _('membership') verbose_name_plural = _('memberships') - def __unicode__(self): - return u'tow. ' + unicode(self.user) + def __str__(self): + return u'tow. ' + str(self.user) + + @classmethod + def is_active_for(self, user): + if user.is_anonymous: + return False + return Schedule.objects.filter( + models.Q(expires_at=None) | models.Q(expires_at__lt=now()), + membership__user=user, + is_active=True, + ).exists() class ReminderEmail(models.Model): @@ -136,7 +145,7 @@ class ReminderEmail(models.Model): verbose_name_plural = _('reminder emails') ordering = ['days_before'] - def __unicode__(self): + def __str__(self): if self.days_before >= 0: return ungettext('a day before expiration', '%d days before expiration', n=self.days_before) else: