from base import *\r
import re\r
\r
+class ActionQuerySet(models.query.QuerySet):\r
+ def get(self, *args, **kwargs):\r
+ action = super(ActionQuerySet, self).get(*args, **kwargs)\r
+ if self.model == Action:\r
+ return action.leaf()\r
+ return action\r
+\r
class ActionManager(models.Manager):\r
use_for_related_fields = True\r
\r
def get_query_set(self):\r
- qs = super(ActionManager, self).get_query_set().filter(canceled=False)\r
+ qs = ActionQuerySet(self.model).filter(canceled=False)\r
\r
if self.model is not Action:\r
return qs.filter(action_type=self.model.get_type())\r
else:\r
return qs\r
\r
- def get(self, *args, **kwargs):\r
- action = super(ActionManager, self).get(*args, **kwargs)\r
- if self.model == Action:\r
- return action.leaf()\r
- return action\r
-\r
def get_for_types(self, types, *args, **kwargs):\r
kwargs['action_type__in'] = [t.get_type() for t in types]\r
return self.get(*args, **kwargs)\r
\r
- \r
-\r
class Action(models.Model):\r
user = models.ForeignKey('User', related_name="actions")\r
ip = models.CharField(max_length=16)\r
else:
return self
+ def get(self, *args, **kwargs):
+ try:
+ pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact'
+ ) or k.endswith('_ptr__pk') or k.endswith('_ptr__id')][0]
+ except:
+ pk = None
+
+ if pk is not None:
+ key = self.model.cache_key(pk)
+ obj = cache.get(key)
+
+ if obj is None:
+ obj = super(CachedQuerySet, self).get(*args, **kwargs)
+ obj.__class__.objects.cache_obj(obj)
+ else:
+ d = obj.__dict__
+
+ return obj
+
+ return super(CachedQuerySet, self).get(*args, **kwargs)
+
from action import Action
class CachedManager(models.Manager):
cache.set(self.model.cache_key(obj.id), obj, 60 * 60)
- def get(self, *args, **kwargs):
- try:
- pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact'
- ) or k.endswith('_ptr__pk') or k.endswith('_ptr__id')][0]
- except:
- pk = None
-
- if pk is not None:
- key = self.model.cache_key(pk)
- obj = cache.get(key)
-
- if obj is None:
- obj = super(CachedManager, self).get(*args, **kwargs)
- self.cache_obj(obj)
- else:
- d = obj.__dict__
-
- return obj
-
- return super(CachedManager, self).get(*args, **kwargs)
-
def get_or_create(self, *args, **kwargs):
try:
return self.get(*args, **kwargs)
app_label = 'forum'\r
unique_together = ('user', 'node')\r
\r
-class BadgeManager(models.Manager):\r
- use_for_related_fields = True\r
- \r
+class BadgesQuerySet(models.query.QuerySet):\r
def get(self, *args, **kwargs):\r
try:\r
pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact')][0]\r
except:\r
- return super(BadgeManager, self).get(*args, **kwargs)\r
+ return super(BadgesQuerySet, self).get(*args, **kwargs)\r
\r
from forum.badges.base import BadgesMeta\r
badge = BadgesMeta.by_id.get(int(pk), None)\r
if not badge:\r
- return super(BadgeManager, self).get(*args, **kwargs)\r
+ return super(BadgesQuerySet, self).get(*args, **kwargs)\r
return badge.ondb\r
\r
+\r
+class BadgeManager(models.Manager):\r
+ use_for_related_fields = True\r
+\r
+ def get_query_set(self):\r
+ return BadgesQuerySet(self.model)\r
+\r
class Badge(models.Model):\r
GOLD = 1\r
SILVER = 2\r