def render(self, context): from django.conf.settings import COMMENTS_BANNED_USERS_GROUP, SITE_ID get_list_function = self.free and freecomments.get_list or comments.get_list_with_karma if self.context_var_name is not None: try: self.obj_id = template.resolve_variable(self.context_var_name, context) except template.VariableDoesNotExist: return '' kwargs = { 'object_id__exact': self.obj_id, 'content_type__package__label__exact': self.package, 'content_type__python_module_name__exact': self.module, 'site__id__exact': SITE_ID, 'select_related': True, 'order_by': (self.ordering + 'submit_date',), } kwargs.update(self.extra_kwargs) if not self.free and COMMENTS_BANNED_USERS_GROUP: kwargs['select'] = {'is_hidden': 'user_id IN (SELECT user_id FROM auth_users_groups WHERE group_id = %s)' % COMMENTS_BANNED_USERS_GROUP} comment_list = get_list_function(**kwargs) if not self.free: if context.has_key('user') and not context['user'].is_anonymous(): user_id = context['user'].id context['user_can_moderate_comments'] = comments.user_is_moderator(context['user']) else: user_id = None context['user_can_moderate_comments'] = False # Only display comments by banned users to those users themselves. if COMMENTS_BANNED_USERS_GROUP: comment_list = [c for c in comment_list if not c.is_hidden or (user_id == c.user_id)] context[self.var_name] = comment_list return ''
def dictsort(value, arg): """ Takes a list of dicts, returns that list sorted by the property given in the argument. """ decorated = [(resolve_variable('var.' + arg, {'var' : item}), item) for item in value] decorated.sort() return [item[1] for item in decorated]
def render(self, context): from django.conf.settings import SITE_ID get_count_function = self.free and freecomments.get_count or comments.get_count if self.context_var_name is not None: self.obj_id = template.resolve_variable(self.context_var_name, context) comment_count = get_count_function(object_id__exact=self.obj_id, content_type__package__label__exact=self.package, content_type__python_module_name__exact=self.module, site__id__exact=SITE_ID) context[self.var_name] = comment_count return ''
def render(self, context): from django.utils.text import normalize_newlines import base64 context.push() if self.obj_id_lookup_var is not None: try: self.obj_id = template.resolve_variable(self.obj_id_lookup_var, context) except template.VariableDoesNotExist: return '' # Validate that this object ID is valid for this content-type. # We only have to do this validation if obj_id_lookup_var is provided, # because do_comment_form() validates hard-coded object IDs. try: self.content_type.get_object_for_this_type(pk=self.obj_id) except ObjectDoesNotExist: context['display_form'] = False else: context['display_form'] = True else: context['display_form'] = True context['target'] = '%s:%s' % (self.content_type.id, self.obj_id) options = [] for var, abbr in (('photos_required', comments.PHOTOS_REQUIRED), ('photos_optional', comments.PHOTOS_OPTIONAL), ('ratings_required', comments.RATINGS_REQUIRED), ('ratings_optional', comments.RATINGS_OPTIONAL), ('is_public', comments.IS_PUBLIC)): context[var] = getattr(self, var) if getattr(self, var): options.append(abbr) context['options'] = ','.join(options) if self.free: context['hash'] = comments.get_security_hash(context['options'], '', '', context['target']) default_form = FREE_COMMENT_FORM else: context['photo_options'] = self.photo_options context['rating_options'] = normalize_newlines(base64.encodestring(self.rating_options).strip()) if self.rating_options: context['rating_range'], context['rating_choices'] = comments.get_rating_options(self.rating_options) context['hash'] = comments.get_security_hash(context['options'], context['photo_options'], context['rating_options'], context['target']) default_form = COMMENT_FORM output = template.Template(default_form).render(context) context.pop() return output
def render(self, context): value = resolve_variable(self.value, context) if self.noop: return value else: return translation.gettext(value)
def render(self, context): for var in self.vars: value = resolve_variable(var, context) if value: return str(value) return ''
def render(self, context): val1 = resolve_variable(self.var1, context) val2 = resolve_variable(self.var2, context) if (self.negate and val1 != val2) or (not self.negate and val1 == val2): return self.nodelist_true.render(context) return self.nodelist_false.render(context)