Permalink
Browse files

Like list tag defaults to all registerd models

{% likes user as like_list %} defaults to using all registered models
when no models are specified, to allow easy listing of all likes in an
application - which is probably the main use case for this.
  • Loading branch information...
1 parent 21fdf91 commit 1193aaa44bd3a618f722dc9057391c46d4e7ee1a Tim Heap committed Nov 28, 2011
Showing with 16 additions and 4 deletions.
  1. +3 −0 phileo/handlers.py
  2. +13 −4 phileo/templatetags/phileo_tags.py
View
@@ -15,5 +15,8 @@ def register(self, models):
def is_registered(self, model):
return not (model in self._registry)
+ def get_list(self):
+ return self._registry[:]
+
library = Registry()
@@ -6,6 +6,7 @@
from django.contrib.contenttypes.models import ContentType
from phileo.models import Like
+from phileo.handlers import library
register = template.Library()
@@ -20,14 +21,21 @@ def __init__(self, user, model_list, varname):
def render(self, context):
user = self.user.resolve(context)
content_types = []
- for model_name in self.model_list:
- app, model = model_name.resolve(context).split(".")
- content_type = ContentType.objects.get(app_label=app, model__iexact=model)
- content_types.append(content_type)
+
+
+ if len(self.model_list) == 0:
+ content_types = [ContentType.objects.get_for_model(model) for model in library.get_list()]
+ else:
+ for model_name in self.model_list:
+ app, model = model_name.resolve(context).split(".")
+ content_type = ContentType.objects.get(app_label=app, model__iexact=model)
+ content_types.append(content_type)
+
context[self.varname] = Like.objects.filter(
sender=user,
receiver_content_type__in=content_types
)
+
return ""
@@ -40,6 +48,7 @@ def likes(parser, token):
user = tokens[1]
varname = tokens[-1]
model_list = tokens[2:-2]
+
return LikesNode(user, model_list, varname)

0 comments on commit 1193aaa

Please sign in to comment.