Browse Source

Highlight in members list old members we should keep data about

For legal reasons.

Fix #137 Ref #30
Jocelyn Delalande 6 years ago
parent
commit
31336cee87
3 changed files with 40 additions and 2 deletions
  1. 30 1
      coin/members/admin.py
  2. 9 1
      coin/members/models.py
  3. 1 0
      coin/templates/admin/base_site.html

+ 30 - 1
coin/members/admin.py

@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
+from datetime import date
+
 from django.shortcuts import get_object_or_404
 from django.contrib import admin
 from django.contrib import messages
@@ -11,6 +13,7 @@ from django.http import HttpResponseRedirect
 from django.conf.urls import url
 from django.conf import settings
 from django.core.urlresolvers import reverse
+from django.utils.safestring import mark_safe
 
 from coin.members.models import (
     Member, CryptoKey, LdapUser, MembershipFee, Offer, OfferSubscription, RowLevelPermission)
@@ -85,7 +88,7 @@ class MemberAdmin(UserAdmin):
     list_display = ('id', 'status', 'username', 'first_name',
                     'name_or_organization_name',
                     'nickname', 'email',
-                    'end_date_of_membership')
+                    'enhanced_end_date_of_membership')
     list_display_links = ('id', 'username', 'first_name', 'name_or_organization_name')
     list_filter = ('status', MembershipFeeFilter)
     search_fields = ['username', 'first_name', 'last_name', 'email', 'nickname']
@@ -101,6 +104,32 @@ class MemberAdmin(UserAdmin):
         return obj.organization_name or obj.last_name
     name_or_organization_name.short_description = 'Nom'
 
+    def enhanced_end_date_of_membership(self, obj):
+        membership_end = obj.end_date_of_membership()
+        active_subscriptions = obj.get_active_subscriptions()
+        recent_inactive_subscriptions = obj.get_recent_inactive_subscriptions()
+
+        note = ''
+        tooltip = ''
+
+        if (membership_end is not None and membership_end < date.today()
+            and recent_inactive_subscriptions.exists() and not active_subscriptions.exists()):
+                note = ' <i class="fa fa-question-circle"  style="color: #cccc40"></i>'
+                tooltip = (
+                    "Cet·te ancien·ne adhérent·e a un service résilié depuis moins d'un an. "
+                    "Légalement, il faut conserver sa fiche un an après la résiliation du service."
+                )
+
+        out = '{}{}'.format(
+            obj.end_date_of_membership() or "pas de cotisation", note)
+
+        if note:
+            return mark_safe('<span style="cursor: help;" title="{}">{}</span>'.format(tooltip, out))
+        else:
+            return mark_safe(out)
+        return mark_safe()
+    enhanced_end_date_of_membership.short_description = "Date de fin d'adhésion"
+
     def get_fieldsets(self, request, obj=None):
         coord_fieldset = ('Coordonnées', {'fields': (
             ('email', 'send_membership_fees_email'),

+ 9 - 1
coin/members/models.py

@@ -182,6 +182,15 @@ class Member(CoinLdapSyncMixin, AbstractUser):
             Q(subscription_date__gt=date) |
             Q(resign_date__lt=date))
 
+    def get_recent_inactive_subscriptions(self):
+        """ Does this member has subscriptions that ended less than one year ago
+
+        For French law requirements.
+        """
+        return self.get_inactive_subscriptions().filter(
+            resign_date__gte=datetime.date.today() - datetime.timedelta(days=365))
+
+
     def get_ssh_keys(self):
         # Quick & dirty, ensure that keys are unique (otherwise, LDAP complains)
         return list({k.key for k in self.cryptokey_set.filter(type='RSA')})
@@ -335,7 +344,6 @@ class Member(CoinLdapSyncMixin, AbstractUser):
 
         return False
 
-
     class Meta:
         verbose_name = 'membre'
 

+ 1 - 0
coin/templates/admin/base_site.html

@@ -6,6 +6,7 @@
 {% block extrahead %}
     <link rel="stylesheet" type="text/css" href="{% static 'hijack/hijack-styles.css' %}" />
     <script src="{% static "js/vendor/jquery.js" %}" type="text/javascript"></script>
+    <link rel="stylesheet" href="{% static "css/font-awesome.min.css"%}" />
     {% include 'autocomplete_light/static.html' %}
 {% endblock %}