More banners admin.
[wolnelektury.git] / src / club / models.py
index a8b4089..ede1a8d 100644 (file)
@@ -31,7 +31,7 @@ class Plan(models.Model):
         verbose_name = _('plan')
         verbose_name_plural = _('plans')
 
         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:
         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')
 
         verbose_name = _('schedule')
         verbose_name_plural = _('schedules')
 
-    def __unicode__(self):
+    def __str__(self):
         return self.key
 
     def save(self, *args, **kwargs):
         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 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()
 
     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')
 
         verbose_name = _('payment')
         verbose_name_plural = _('payments')
 
-    def __unicode__(self):
+    def __str__(self):
         return "%s %s" % (self.schedule, self.payed_at)
 
 
         return "%s %s" % (self.schedule, self.payed_at)
 
 
@@ -122,8 +121,18 @@ class Membership(models.Model):
         verbose_name = _('membership')
         verbose_name_plural = _('memberships')
 
         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):
 
 
 class ReminderEmail(models.Model):
@@ -136,7 +145,7 @@ class ReminderEmail(models.Model):
         verbose_name_plural = _('reminder emails')
         ordering = ['days_before']
 
         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:
         if self.days_before >= 0:
             return ungettext('a day before expiration', '%d days before expiration', n=self.days_before)
         else: