diff options
| -rw-r--r-- | ishtar_common/forms_common.py | 10 | ||||
| -rw-r--r-- | ishtar_common/models.py | 32 | ||||
| -rw-r--r-- | ishtar_common/views.py | 2 | 
3 files changed, 33 insertions, 11 deletions
| diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 06debe9ce..72b33b4c4 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -25,6 +25,7 @@ from django import forms  from django.conf import settings  from django.contrib.auth.models import User  from django.core import validators +from django.core.cache import cache  from django.core.exceptions import ObjectDoesNotExist  from django.forms.formsets import formset_factory  from django.forms.models import BaseModelFormSet, BaseFormSet @@ -746,7 +747,7 @@ class ProfilePersonForm(forms.Form):          super(ProfilePersonForm, self).__init__(*args, **kwargs)          self.fields['current_profile'].choices = choices -    def save(self, *args, **kwargs): +    def save(self, session):          q = models.UserProfile.objects.filter(              person__ishtaruser=self.user.ishtaruser, current=True)          for profile in q.all(): @@ -763,6 +764,13 @@ class ProfilePersonForm(forms.Form):          profile.current = True          profile.save() +        # clean session cache +        cache_key_list = 'sessionlist-{}'.format(session.session_key) +        key_list = cache.get(cache_key_list, []) +        for key in key_list: +            cache.set(key, None, settings.CACHE_TIMEOUT) +        cache.set(cache_key_list, [], settings.CACHE_TIMEOUT) +  class TownForm(forms.Form):      form_label = _("Towns") diff --git a/ishtar_common/models.py b/ishtar_common/models.py index a6fc8722d..3eceb8df0 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2558,28 +2558,42 @@ class Person(Address, Merge, OwnPerms, ValueGetter):              res = cache.get(cache_key)              if res in (True, False):                  return res +            # list all cache key in order to clean them on profiel change +            cache_key_list = 'sessionlist-{}'.format(session.session_key) +            key_list = cache.get(cache_key_list, []) +            key_list.append(cache_key) +            cache.set(cache_key_list, key_list, settings.CACHE_TIMEOUT)          if type(right_name) in (list, tuple): -            res = bool(self.person_types.filter( -                txt_idx__in=right_name).count()) or \ -                bool(self.person_types.filter( -                     groups__permissions__codename__in=right_name).count()) or\ +            res = bool( +                self.profiles.filter( +                    current=True, +                    profile_type__txt_idx__in=right_name +                ).count()) or \ +                bool(self.profiles.filter( +                    current=True, +                    profile_type__groups__permissions__codename__in=right_name +                ).count()) or \                  bool(self.ishtaruser.user_ptr.groups.filter(                       permissions__codename__in=right_name                       ).count()) or\                  bool(self.ishtaruser.user_ptr.user_permissions.filter(                       codename__in=right_name).count()) -        # or self.person_types.filter(wizard__url_name__in=right_name).count())          else: -            res = bool(self.person_types.filter(txt_idx=right_name).count()) or\ -                bool(self.person_types.filter( -                     groups__permissions__codename=right_name).count()) or \ +            res = bool( +                self.profiles.filter( +                    current=True, +                    profile_type__txt_idx__in=right_name +                ).count()) or \ +                bool(self.profiles.filter( +                    current=True, +                    profile_type__groups__permissions__codename=right_name +                ).count()) or \                  bool(self.ishtaruser.user_ptr.groups.filter(                       permissions__codename__in=[right_name]                       ).count()) or \                  bool(self.ishtaruser.user_ptr.user_permissions.filter(                       codename__in=[right_name]).count()) -        # or self.person_types.filter(wizard__url_name=right_name).count())          if session:              cache.set(cache_key, res, settings.CACHE_TIMEOUT)          return res diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 0e53e7d1f..863722ac8 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1756,7 +1756,7 @@ class ProfileEdit(LoginRequiredMixin, FormView):          return kwargs      def form_valid(self, form): -        form.save() +        form.save(self.request.session)          return HttpResponseRedirect(self.get_success_url()) | 
