From 95775d3b9bef34f1046ecb1dea0b09b8ad766b9c Mon Sep 17 00:00:00 2001 From: Krophil Date: Mon, 6 Feb 2017 22:18:44 +0100 Subject: [PATCH] adaptations for settings and deletion checked --- accounting/models.py | 12 ++++++------ .../templates/accounting/bank_account_details.jinja | 2 ++ .../templates/accounting/club_account_details.jinja | 2 +- core/views/__init__.py | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/accounting/models.py b/accounting/models.py index 6dbf56d8..7371bff0 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -58,7 +58,7 @@ class Company(models.Model): Method to see if that object can be edited by the given user """ for club in user.memberships.filter(end_date=None).all(): - if club and club.role == 7: + if club and club.role == settings.SITH_CLUB_ROLES_ID['Treasurer']: return True return False @@ -67,7 +67,7 @@ class Company(models.Model): Method to see if that object can be viewed by the given user """ for club in user.memberships.filter(end_date=None).all(): - if club and club.role >= 7: + if club and club.role >= settings.SITH_CLUB_ROLES_ID['Treasurer']: return True return False @@ -97,7 +97,7 @@ class BankAccount(models.Model): if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID): return True m = self.club.get_membership_for(user) - if m is not None and m.role >= 7: + if m is not None and m.role >= settings.SITH_CLUB_ROLES_ID['Treasurer']: return True return False @@ -129,7 +129,7 @@ class ClubAccount(models.Model): Method to see if that object can be edited by the given user """ m = self.club.get_membership_for(user) - if m and m.role == 7: + if m and m.role == settings.SITH_CLUB_ROLES_ID['Treasurer']: return True return False @@ -138,7 +138,7 @@ class ClubAccount(models.Model): Method to see if that object can be viewed by the given user """ m = self.club.get_membership_for(user) - if m and m.role >= 7: + if m and m.role >= settings.SITH_CLUB_ROLES_ID['Treasurer']: return True return False @@ -218,7 +218,7 @@ class Operation(models.Model): journal = models.ForeignKey(GeneralJournal, related_name="operations", null=False, verbose_name=_("journal")) amount = CurrencyField(_('amount')) date = models.DateField(_('date')) - remark = models.CharField(_('comment'), max_length=128, default="", null=True, blank=True) + remark = models.CharField(_('comment'), max_length=128, null=True, blank=True) mode = models.CharField(_('payment method'), max_length=255, choices=settings.SITH_ACCOUNTING_PAYMENT_METHOD) cheque_number = models.CharField(_('cheque number'), max_length=32, default="", null=True, blank=True) invoice = models.ForeignKey(SithFile, related_name='operations', verbose_name=_("invoice"), null=True, blank=True) diff --git a/accounting/templates/accounting/bank_account_details.jinja b/accounting/templates/accounting/bank_account_details.jinja index 95981b1b..cd968322 100644 --- a/accounting/templates/accounting/bank_account_details.jinja +++ b/accounting/templates/accounting/bank_account_details.jinja @@ -24,7 +24,9 @@ {% for c in object.club_accounts.all() %}
  • {{ c }} - {% trans %}Edit{% endtrans %} + {% if c.journals.count() == 0 %} - {% trans %}Delete{% endtrans %} + {% endif %}
  • {% endfor %} diff --git a/accounting/templates/accounting/club_account_details.jinja b/accounting/templates/accounting/club_account_details.jinja index 2b606a5f..08f22c2d 100644 --- a/accounting/templates/accounting/club_account_details.jinja +++ b/accounting/templates/accounting/club_account_details.jinja @@ -55,7 +55,7 @@ {% endif %} {% trans %}View{% endtrans %} {% trans %}Edit{% endtrans %} - {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) %} + {% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) and j.operations.count() == 0 %} {% trans %}Delete{% endtrans %} {% endif %} diff --git a/core/views/__init__.py b/core/views/__init__.py index 12c45c11..c0a613bc 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -67,7 +67,7 @@ class CanEditPropMixin(View): except: pass # If we get here, it's a ListView l_id = [o.id for o in self.get_queryset() if can_edit_prop(o, request.user)] - if not l_id: + if not l_id and self.get_queryset().count() != 0: raise PermissionDenied self._get_queryset = self.get_queryset def get_qs(self2): @@ -89,7 +89,7 @@ class CanEditMixin(View): except: pass # If we get here, it's a ListView l_id = [o.id for o in self.get_queryset() if can_edit(o, request.user)] - if not l_id: + if not l_id and self.get_queryset().count() != 0: raise PermissionDenied self._get_queryset = self.get_queryset def get_qs(self2): @@ -111,7 +111,7 @@ class CanViewMixin(View): except: pass # If we get here, it's a ListView l_id = [o.id for o in self.get_queryset() if can_view(o, request.user)] - if ((not l_id) and self.get_queryset().count() != 0): + if not l_id and self.get_queryset().count() != 0: raise PermissionDenied self._get_queryset = self.get_queryset def get_qs(self2):