+ @property
+ def suspension(self):
+ if self.__dict__.get('_suspension_dencache_', False) != None:
+ try:
+ self.__dict__['_suspension_dencache_'] = self.actions.get(action_type="suspend", canceled=False)
+ except ObjectDoesNotExist:
+ self.__dict__['_suspension_dencache_'] = None
+ except MultipleObjectsReturned:
+ logging.error("Multiple suspension actions found for user %s (%s)" % (self.username, self.id))
+ self.__dict__['_suspension_dencache_'] = self.actions.filter(action_type="suspend", canceled=False
+ ).order_by('-action_date')[0]
+
+ return self.__dict__['_suspension_dencache_']
+
+ def _pop_suspension_cache(self):
+ self.__dict__.pop('_suspension_dencache_', None)
+
+ def is_suspended(self):
+ if not self.is_active:
+ suspension = self.suspension
+
+ if suspension and suspension.extra.get('bantype', None) == 'forxdays' and (
+ datetime.datetime.now() > suspension.action_date + datetime.timedelta(
+ days=int(suspension.extra.get('forxdays', 365)))):
+ suspension.cancel()
+ else:
+ return True
+
+ return False