def get_blocks(blockregion, context): region = get_region(get_current_group(), get_current_user(), blockregion) block_instances = BlockInstancePosition.objects.filter(region = region,) context['blocks'] = block_instances
def __init__(self, *args, **kwargs): super(WikiSnipForm, self).__init__(*args, **kwargs) self.fields['body'].widget.attrs['cols'] = 80 self.fields['body'].widget.attrs['rows'] = 30 if not sphutils.has_captcha_support() or get_current_user( ).is_authenticated(): del self.fields['captcha']
def render(self, context): # TODO check permissions category_id = None if self.categoryvar: category_id = self.categoryvar.resolve(context) if not category_id: # if no category id is given simply display all categories # of the current group. category = None categories = get_all_viewable_categories(get_current_group(), get_current_user()) threads = Post.objects.filter( category__id__in=categories, thread__isnull=True, ).order_by('-postdate') else: category = Category.objects.get(pk=category_id) threads = Post.objects.filter( category=category, thread__isnull=True, ).order_by('-postdate') context.push() context['threads'] = threads context['category'] = category output = self.nodelist.render(context) context.pop() return output
def sph_publicemailaddress(value): if get_sph_setting('community_email_anonymous_require_captcha'): # as a security constraint we don't return the public email # address if the user is not logged in. if not get_current_user().is_authenticated: validated = get_current_request().session.get('sph_email_captcha_validated', 0) # if the timeout is reached or the captcha was never entered # provide a link for the user to enter the captcha. if validated < time() - get_sph_setting('community_email_anonymous_require_captcha_timeout'): return mark_safe('<a href="%s">%s</a>' % ( sph_reverse('sph_reveal_emailaddress', kwargs={'user_id': value.id, }), _('Reveal this emailaddress'))) if get_sph_setting('community_email_show_only_public'): try: return CommunityUserProfile.objects.get(user=value, ).public_emailaddress except CommunityUserProfile.DoesNotExist: pass return '' try: profile = CommunityUserProfile.objects.get(user=value, ) except CommunityUserProfile.DoesNotExist: return "n/a" # value.email return profile.public_emailaddress or value.email
def sph_publicemailaddress(value): if get_sph_setting('community_email_anonymous_require_captcha'): # as a security constraint we don't return the public email # address if the user is not logged in. if not get_current_user().is_authenticated(): validated = get_current_request().session.get( 'sph_email_captcha_validated', 0) # if the timeout is reached or the captcha was never entered # provide a link for the user to enter the captcha. if validated < time() - get_sph_setting( 'community_email_anonymous_require_captcha_timeout'): return mark_safe('<a href="%s">%s</a>' % (sph_reverse('sph_reveal_emailaddress', (), { 'user_id': value.id, }), ugettext('Reveal this emailaddress'))) if get_sph_setting('community_email_show_only_public'): try: return CommunityUserProfile.objects.get( user=value, ).public_emailaddress except CommunityUserProfile.DoesNotExist: pass return '' try: profile = CommunityUserProfile.objects.get(user=value, ) except CommunityUserProfile.DoesNotExist: return "n/a" #value.email return profile.public_emailaddress or value.email
def sphquestions_answervoting(qext, reply): user = get_current_user() if not qext or not qext.is_question or reply.thread is None: return { 'hidden': True } question = reply.thread # don't diplay answer voting if user is not logged in # or if the post is not a question or not a reply. if user is None \ or not user.is_authenticated \ or (reply.author == user and reply.author != question.author): allowvoting = False else: allowvoting = True votes = AnswerVoting.objects.filter( answer = reply ) uservoted = False authorvoted = False for vote in votes: if vote.user == user: uservoted = True allowvoting = False if vote.user == question.author: authorvoted = True return { 'qext' : qext, 'post' : reply, 'user' : user, 'uservoted' : uservoted, 'authorvoted': authorvoted, 'votecount' : len(votes), 'STATIC_URL' : settings.STATIC_URL, 'allowvoting': allowvoting, }
def pdf_enabled(self): """ Checks if PDF generation is 1. enabled and 2. the current user has permission. (E.g. setting 'wiki_pdf_generation' to 'loggedin' would only allow loggedin users to view PDF versions.) This method is ment to be used in templates. """ setting = get_sph_setting("wiki_pdf_generation") if setting == True: return True if setting == "loggedin": return get_current_user() and get_current_user().is_authenticated() if setting == "staff": return get_current_user() and get_current_user().is_authenticated() and get_current_user().is_staff return False
def __init__(self, *args, **kwargs): super(PostForm, self).__init__(*args, **kwargs) if not sphutils.has_captcha_support() or get_current_user( ).is_authenticated(): del self.fields['captcha'] if len(POST_MARKUP_CHOICES) == 1: del self.fields['markup']
def sphquestions_answervoting(qext, reply): user = get_current_user() if not qext or not qext.is_question or reply.thread is None: return {"hidden": True} # don't diplay answer voting if user is not logged in # or if the post is not a question or not a reply. if user is None or not user.is_authenticated() or reply.author == user: allowvoting = False else: allowvoting = True question = reply.thread votes = AnswerVoting.objects.filter(answer=reply) uservoted = False authorvoted = False for vote in votes: if vote.user == user: uservoted = True allowvoting = False if vote.user == question.author: authorvoted = True return { "qext": qext, "post": reply, "user": user, "uservoted": uservoted, "authorvoted": authorvoted, "votecount": len(votes), "MEDIA_URL": settings.MEDIA_URL, "allowvoting": allowvoting, }
def pdf_enabled(self): """ Checks if PDF generation is 1. enabled and 2. the current user has permission. (E.g. setting 'wiki_pdf_generation' to 'loggedin' would only allow loggedin users to view PDF versions.) This method is ment to be used in templates. """ setting = get_sph_setting('wiki_pdf_generation') if setting == True: return True if setting == 'loggedin': return get_current_user() and get_current_user().is_authenticated() if setting == 'staff': return get_current_user() and get_current_user().is_authenticated( ) and get_current_user().is_staff return False
def __init__(self, *args, **kwargs): super(CaptchaEditBaseForm, self).__init__(*args, **kwargs) if sphutils.has_captcha_support() and not get_current_user().is_authenticated(): self.fields['captcha'] = sphutils.CaptchaField(widget=sphutils.CaptchaWidget, help_text = ugettext('Please enter the result of the above calculation.'), ) self.fields['tags'] = TagField(model = WikiSnip, required = False)
def __init__(self, *args, **kwargs): super(CaptchaEditBaseForm, self).__init__(*args, **kwargs) if sphutils.has_captcha_support() and not get_current_user().is_authenticated: self.fields['captcha'] = sphutils.CaptchaField(widget=sphutils.CaptchaWidget, help_text=ugettext( 'Please enter the result of the above calculation.'), ) self.fields['tags'] = TagField(model=WikiSnip, required=False)
def has_edit_permission(self): user = get_current_user() pref = self.get_wiki_preference() if pref == None: # By default only members of the group are allowed to edit posts # TODO don't hardcode this, but make it configurable .. # (it actually is.. by creating a 'ROOT' wiki snip) permission = 1 else: permission = pref.edit return self.__has_permission(user, pref, permission)
def search_posts(query, category = None): group = get_current_group() user = get_current_user() #if group: # query = u''.join((u'+', u'group_id:', unicode(group.id), ' ', query)) categories = get_all_viewable_categories(group, user) if category is not None: prefix = u'category_id:%d' % category.id else: prefix = u' OR '.join([u'category_id:%d' % category for category in categories]) query = u'(%s) AND (%s)' % (prefix, query) logger.debug('Searching for: %s' % query) ret = PostFilter(post_index.search(query=query), categories) logger.debug('Searching done.') return ret
def search_posts(query, category=None): group = get_current_group() user = get_current_user() #if group: # query = u''.join((u'+', u'group_id:', unicode(group.id), ' ', query)) categories = get_all_viewable_categories(group, user) if category is not None: prefix = u'category_id:%d' % category.id else: prefix = u' OR '.join( [u'category_id:%d' % category for category in categories]) query = u'(%s) AND (%s)' % (prefix, query) logger.debug('Searching for: %s' % query) ret = PostFilter(post_index.search(query=query), categories) logger.debug('Searching done.') return ret
def render(self, context): # TODO check permissions category_id = None if self.categoryvar: category_id = self.categoryvar.resolve(context) if not category_id: # if no category id is given simply display all categories # of the current group. category = None categories = get_all_viewable_categories(get_current_group(), get_current_user()) threads = Post.objects.filter(category__id__in=categories, thread__isnull=True).order_by("-postdate") else: category = Category.objects.get(pk=category_id) threads = Post.objects.filter(category=category, thread__isnull=True).order_by("-postdate") context.push() context["threads"] = threads context["category"] = category output = self.nodelist.render(context) context.pop() return output
def has_view_permission(self): user = get_current_user() pref = self.get_wiki_preference() return pref == None or self.__has_permission(user, pref, pref.view)
def __getitem__(self, flag_name): return has_permission_flag(get_current_user(), flag_name)
def __init__(self, *args, **kwargs): super(WikiSnipForm, self).__init__(*args, **kwargs) self.fields['body'].widget.attrs['cols'] = 80; self.fields['body'].widget.attrs['rows'] = 30; if not sphutils.has_captcha_support() or get_current_user().is_authenticated(): del self.fields['captcha']
def get_user(self): return get_current_user()
def get_blocks(blockregion, context): print "for region %s" % blockregion region = get_region(get_current_group(), get_current_user(), blockregion) block_instances = BlockInstancePosition.objects.filter(region=region, ) context['blocks'] = block_instances
def get_blocks(blockregion, context): print "for region %s" % blockregion region = get_region(get_current_group(), get_current_user(), blockregion) block_instances = BlockInstancePosition.objects.filter(region=region) context["blocks"] = block_instances
def __init__(self, *args, **kwargs): super(PostForm, self).__init__(*args, **kwargs) if not sphutils.has_captcha_support() or get_current_user().is_authenticated(): del self.fields['captcha'] if len( POST_MARKUP_CHOICES ) == 1: del self.fields['markup']