diff --git a/club/models.py b/club/models.py
index 3b02be0f..7f4de6fe 100644
--- a/club/models.py
+++ b/club/models.py
@@ -122,7 +122,7 @@ class Club(models.Model):
sub = User.objects.filter(pk=user.pk).first()
if sub is None:
return False
- return sub.is_subscribed()
+ return sub.is_subscribed
def get_membership_for(self, user):
"""
@@ -151,7 +151,7 @@ class Membership(models.Model):
def clean(self):
sub = User.objects.filter(pk=self.user.pk).first()
- if sub is None or not sub.is_subscribed():
+ if sub is None or not sub.is_subscribed:
raise ValidationError(_('User must be subscriber to take part to a club'))
if Membership.objects.filter(user=self.user).filter(club=self.club).filter(end_date=None).exists():
raise ValidationError(_('User is already member of that club'))
diff --git a/core/models.py b/core/models.py
index 0b393ba1..160a6f76 100644
--- a/core/models.py
+++ b/core/models.py
@@ -184,9 +184,11 @@ class User(AbstractBaseUser):
def to_dict(self):
return self.__dict__
+ @cached_property
def was_subscribed(self):
return self.subscriptions.exists()
+ @cached_property
def is_subscribed(self):
s = self.subscriptions.last()
return s.is_valid_now() if s is not None else False
@@ -207,11 +209,11 @@ class User(AbstractBaseUser):
if group_id == settings.SITH_GROUP_PUBLIC_ID:
return True
if group_id == settings.SITH_GROUP_SUBSCRIBERS_ID:
- return self.is_subscribed()
+ return self.is_subscribed
if group_id == settings.SITH_GROUP_OLD_SUBSCRIBERS_ID:
- return self.was_subscribed()
+ return self.was_subscribed
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
- return self.is_subscribed()
+ return self.is_subscribed
if group_name[-len(settings.SITH_BOARD_SUFFIX):] == settings.SITH_BOARD_SUFFIX:
from club.models import Club
name = group_name[:-len(settings.SITH_BOARD_SUFFIX)]
diff --git a/core/templates/core/user_detail.jinja b/core/templates/core/user_detail.jinja
index 8bc1f5f6..aa8b7e23 100644
--- a/core/templates/core/user_detail.jinja
+++ b/core/templates/core/user_detail.jinja
@@ -54,7 +54,7 @@
{% if user.memberships.filter(end_date=None).exists() or user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user == profile %}
{# if the user is member of a club, he can view the subscription state #}
-{% if profile.is_subscribed() %}
+{% if profile.is_subscribed %}
{% if user == profile or user.is_root or user.is_board_member %}
{{ user_subscription(profile) }}
{% endif %}
diff --git a/core/templates/core/user_tools.jinja b/core/templates/core/user_tools.jinja
index 278136f5..bf92bcbf 100644
--- a/core/templates/core/user_tools.jinja
+++ b/core/templates/core/user_tools.jinja
@@ -91,7 +91,7 @@
{% trans %}Elections{% endtrans %}
diff --git a/counter/models.py b/counter/models.py
index 724a3de8..cffae67e 100644
--- a/counter/models.py
+++ b/counter/models.py
@@ -347,7 +347,7 @@ class Selling(models.Model):
self.customer.save()
self.is_validated = True
u = User.objects.filter(id=self.customer.user.id).first()
- if u.was_subscribed():
+ if u.was_subscribed:
if self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER:
sub = Subscription(
member=u,
diff --git a/eboutic/views.py b/eboutic/views.py
index 87b4ce00..087b9bb4 100644
--- a/eboutic/views.py
+++ b/eboutic/views.py
@@ -80,7 +80,7 @@ class EbouticMain(TemplateView):
kwargs['basket'] = self.basket
kwargs['eboutic'] = Counter.objects.filter(type="EBOUTIC").first()
kwargs['categories'] = ProductType.objects.all()
- if not self.request.user.was_subscribed():
+ if not self.request.user.was_subscribed:
kwargs['categories'] = kwargs['categories'].exclude(id=settings.SITH_PRODUCTTYPE_SUBSCRIPTION)
return kwargs
diff --git a/election/views.py b/election/views.py
index f9091906..2c4a8821 100644
--- a/election/views.py
+++ b/election/views.py
@@ -271,7 +271,7 @@ class ElectionCreateView(CanCreateMixin, CreateView):
template_name = 'core/create.jinja'
def dispatch(self, request, *args, **kwargs):
- if not request.user.is_subscribed():
+ if not request.user.is_subscribed:
raise PermissionDenied
return super(ElectionCreateView, self).dispatch(request, *args, **kwargs)
diff --git a/launderette/views.py b/launderette/views.py
index 4c4b7102..70eb4432 100644
--- a/launderette/views.py
+++ b/launderette/views.py
@@ -60,7 +60,7 @@ class LaunderetteBookView(CanViewMixin, DetailView):
self.slot_type = request.POST['slot_type']
if 'slot' in request.POST.keys() and request.user.is_authenticated():
self.subscriber = request.user
- if self.subscriber.is_subscribed():
+ if self.subscriber.is_subscribed:
self.date = dateparse.parse_datetime(request.POST['slot']).replace(tzinfo=pytz.UTC)
if self.slot_type == "WASHING":
if self.check_slot(self.slot_type):
diff --git a/sas/models.py b/sas/models.py
index 0cd7c685..2abcce9f 100644
--- a/sas/models.py
+++ b/sas/models.py
@@ -30,7 +30,7 @@ class Picture(SithFile):
def can_be_viewed_by(self, user):
# file = SithFile.objects.filter(id=self.id).first()
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
- user.was_subscribed())# or user.can_view(file)
+ user.was_subscribed)# or user.can_view(file)
def get_download_url(self):
return reverse('sas:download', kwargs={'picture_id': self.id})
@@ -107,7 +107,7 @@ class Album(SithFile):
def can_be_viewed_by(self, user):
# file = SithFile.objects.filter(id=self.id).first()
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
- user.was_subscribed())# or user.can_view(file)
+ user.was_subscribed)# or user.can_view(file)
def get_absolute_url(self):
return reverse('sas:album', kwargs={'album_id': self.id})
diff --git a/sas/views.py b/sas/views.py
index 5f510b3a..580c9f53 100644
--- a/sas/views.py
+++ b/sas/views.py
@@ -160,7 +160,7 @@ class AlbumUploadView(CanViewMixin, DetailView, FormMixin):
self.form = self.get_form()
parent = SithFile.objects.filter(id=self.object.id).first()
files = request.FILES.getlist('images')
- if request.user.is_authenticated() and request.user.is_subscribed():
+ if request.user.is_authenticated() and request.user.is_subscribed:
if self.form.is_valid():
self.form.process(parent=parent, owner=request.user, files=files,
automodere=request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID))
@@ -192,7 +192,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
FileView.handle_clipboard(request, self.object)
parent = SithFile.objects.filter(id=self.object.id).first()
files = request.FILES.getlist('images')
- if request.user.is_authenticated() and request.user.is_subscribed():
+ if request.user.is_authenticated() and request.user.is_subscribed:
if self.form.is_valid():
self.form.process(parent=parent, owner=request.user, files=files,
automodere=request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID))