1. /BlogVenv/Lib/site-packages/tagging/templatetags/tagging_tags.py
...
class TagCloudForModelNode(Node):
def __init__(self, model, context_var, **kwargs):
self.model = model
self.context_var = context_var
self.kwargs = kwargs
def render(self, context):
model = apps.get_model(*self.model.split('.'))
if model is None:
raise TemplateSyntaxError(
_('tag_cloud_for_model tag was given an invalid model: %s') %
self.model)
self.kwargs["user"] = context["user"] # 1. add user object
context[self.context_var] = Tag.objects.cloud_for_model(
model, **self.kwargs)
return ''
...
2. /BlogVenv/Lib/site-packages/tagging/models.py
...
from django.db.models import Q # 2. add Q function
...
def cloud_for_model(self, model, steps=4, distribution=LOGARITHMIC,
filters=None, min_count=None, user=None): # 3. add user parameter
...
tags = list(self.usage_for_model(model, counts=True, filters=filters,
min_count=min_count, user=user)) # 4. add user parameter
return calculate_cloud(tags, steps, distribution)
...
def usage_for_model(self, model, counts=False, min_count=None,
filters=None, user=None): # 5. add user parameter
...
if filters is None:
filters = {}
queryset = model._default_manager.filter()
# 6. add authentication related queryset
if not user.is_superuser:
queryset = queryset.filter(menu__menu_isEnabled=True).filter(post_isEnabled=True)
if user.is_authenticated:
queryset = queryset.filter(Q(menu__groups__user=user) | Q(menu__groups__user=None))
else:
queryset = queryset.filter(menu__groups__user=None)
for f in filters.items():
queryset.query.add_filter(f)
usage = self.usage_for_queryset(queryset, counts, min_count)
return usage
...