• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python middleware.get_current_group函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sphene.community.middleware.get_current_group函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_group函数的具体用法?Python get_current_group怎么用?Python get_current_group使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_current_group函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: sortblocks

def sortblocks(request, group):
    if request.method != 'POST' or not request.user.is_authenticated:
        raise Exception

    # Now resort it ..
    print(str(request.POST))
    #return HttpResponse('')
    for blockregion in request.POST.getlist('block_region'):
        sortorder = request.POST[blockregion]
        print("sortorder for %s: %s" % (blockregion, str(sortorder)))


        region = get_or_create_region(get_current_group(),
                                      request.user,
                                      blockregion)

        block_instances = BlockInstancePosition.objects.filter(region = region,)
        block_instances.delete()

        if not sortorder:
            continue

        idorder = [e.split('=')[1] for e in sortorder.split('&')]

        pos=1
        for id in idorder:
            # TODO add permission checking ?
            block_config = BlockConfiguration.objects.get( pk = id )
            BlockInstancePosition(region = region,
                                  block_configuration = block_config,
                                  sortorder = pos).save()
            pos+=1

    return HttpResponse('')

    blockregion = request.POST['block_region']
    sortorder = request.POST['sortorder']
    idorder = [e.split('=')[1] for e in sortorder.split('&')]
    region = get_or_create_region(get_current_group(),
                                  request.user,
                                  blockregion)

    block_instances = BlockInstancePosition.objects.filter(region = region,)
    block_instances.delete()

    pos=1
    for id in idorder:
        # TODO add permission checking ?
        block_config = BlockConfiguration.objects.get( pk = id )
        BlockInstancePosition(region = region,
                              block_configuration = block_config,
                              sortorder = pos).save()
        pos+=1
    return HttpResponse( 'Sorted all blocks.' )
开发者ID:hpoul,项目名称:sct-communitytools,代码行数:54,代码来源:views.py


示例2: show_active_monitors

def show_active_monitors(context, profile_user):
    user = context["user"]
    request = context["request"]

    if user == profile_user:
        monitors = Monitor.objects.filter(
            Q(thread=None) | Q(thread__is_hidden=0), user=profile_user, group=get_current_group()
        )
    else:
        if not has_permission_flag(request.user, "community_manage_users"):
            raise PermissionDenied()
        monitors = Monitor.objects.filter(
            Q(thread=None) | Q(thread__is_hidden=0), user=profile_user, group=get_current_group()
        )
    return {"monitors": monitors, "request": request, "is_current_user": user == profile_user}
开发者ID:ExAgiliaLinux,项目名称:sct-communitytools,代码行数:15,代码来源:sphboard_extras.py


示例3: authorinfo_cachekey

def authorinfo_cachekey(user_id, group_id = None, language_code = None):
    if group_id is None:
        group_id = get_current_group().id
    if language_code is None:
        language_code = getattr(get_current_request(), 'LANGUAGE_CODE', '')
    return '%s_sphboard_authorinfo_%s_%s_%s' % \
        (settings.CACHE_MIDDLEWARE_KEY_PREFIX, str(group_id), str(user_id), language_code)
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:7,代码来源:sphboard_extras.py


示例4: navigation

def navigation(request):
    if hasattr(request, 'attributes') and 'group' in request.attributes:
        group = request.attributes['group']
    else:
        group = get_current_group()
    sphdata = get_current_sphdata()

    sph_settings = getattr( settings, 'SPH_SETTINGS', None )
    sphdata['installed_apps'] = settings.INSTALLED_APPS
    sphdata['current_url'] = request.path
    querystring = request.META.get('QUERY_STRING', None)
    if querystring:
        sphdata['current_url'] += '?'+querystring
    # urlPrefix is deprecated, don't use it.
    urlPrefix = ''
    if hasattr(request, 'attributes'):
        urlPrefix = request.attributes.get('urlPrefix', '')
    if group:
        return { 'navigation_left': Navigation.objects.filter( group = group,
                                                               navigationType = 0 ),
                 'navigation_top': Navigation.objects.filter( group = group,
                                                               navigationType = 1 ),
                 'urlPrefix': urlPrefix,
                 'group': group,
                 'sph': sphdata,
                 'sph_settings': SphSettings(),
                 'sph_perms': PermissionFlagLookup(),
                 }
    return { 'sph': sphdata,
             'sph_settings': SphSettings(),
             'sph_perms': PermissionFlagLookup(),
             }
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:32,代码来源:context_processors.py


示例5: recursive_render

    def recursive_render(self, context, parent, depth = 0):
        filter = Category.objects.filter(
            group = get_current_group(),)

        if self.categorytypevar is not None:
            categorytype = self.categorytypevar.resolve(context)

            filter = filter.filter(category_type__in = categorytype.split(','))
            #(TaskCategoryType.name, DivisionCategoryType.name),)
        if parent is None:
            filter = filter.filter(parent__isnull = True)
        else:
            filter = filter.filter(parent = parent)

        output = []

        for category in filter:
            if not category.has_view_permission():
                continue
            # render children first
            children = self.recursive_render(context, category, depth + 1)

            # render the current category
            context.push()
            context['category'] = category
            context['children'] = mark_safe(children)
            context['depth'] = depth
            context['depthrange'] = xrange(depth)
            output.append(self.nodelist.render(context))
            context.pop()

        return ''.join(output)
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:32,代码来源:sphboard_extras.py


示例6: sphboard_post_authorinfo

def sphboard_post_authorinfo(user_id):
    if user_id is None:
        user = None
    else:
        user = User.objects.get(pk=user_id)

    return {"author": user, "post_count": UserPostCount.objects.get_post_count(user, get_current_group())}
开发者ID:sunilpatelmca,项目名称:dishnine,代码行数:7,代码来源:sphboard_extras.py


示例7: authorinfo_cachekey

def authorinfo_cachekey(user_id, group_id = None, language_code = None):
    if group_id is None:
        group_id = get_current_group().id
    if language_code is None:
        language_code = getattr(get_current_request(), 'LANGUAGE_CODE', '')
    return 'sphboard_authorinfo_%s_%s_%s' % \
        (str(group_id),str(user_id), language_code)
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:7,代码来源:sphboard_extras.py


示例8: get_blocks

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
开发者ID:hpoul,项目名称:sct-communitytools,代码行数:7,代码来源:sphblockframework_extras.py


示例9: get_or_create_for_object

    def get_or_create_for_object(self, model_instance):
        # Find a category associated with the given object
        model_type = ContentType.objects.get_for_model(model_instance)
        try:
            return self.filter(object_type__pk = model_type.id,
                               object_id = model_instance.pk).get()
        except CommentsCategoryConfig.DoesNotExist:
            # Find root category
            group = get_current_group()
            from sphene.sphcomments.categorytypes import CommentsCategoryType, CommentsOnObjectCategoryType
            if not group.id in root_category_id:
                try:
                    root_category_id[group.id] = Category.objects.get(
                        group = group,
                        category_type = CommentsCategoryType.name, ).id
                except Category.DoesNotExist:
                    raise Exception('Please create a category of type "%s" (%s).' % (CommentsCategoryType.label, CommentsCategoryType.name))

            # create a new category ...
            # to copy preferences we need the root category ..
            root_category = Category.objects.get(pk = root_category_id[group.id])
            # TODO role permissions are currently not copied ..
            category = Category(
                name = 'comment category for "%s"' % unicode(model_instance),
                parent = root_category,
                group = group,
                category_type = CommentsOnObjectCategoryType.name,
                allowview = root_category.allowview,
                allowthreads = root_category.allowthreads,
                allowreplies = root_category.allowreplies, )
            category.save()
            config = CommentsCategoryConfig(category = category,
                                            content_object = model_instance)
            config.save()
            return config
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:35,代码来源:models.py


示例10: has_permission_flag

def has_permission_flag(user, flag, contentobject=None, group=None):
    """
    Checks if the given user has the given flag for the given model instance
    (object).
    If object is not given, it checks if the user has the flag globally
    assigned.
    """
    # Anonymous users won't have flags ...
    if user is None or not user.is_authenticated():
        return False

    # Super users have all flags anyway ..
    if user.is_superuser:
        return True

    if group is None:
        group = get_current_group()

    # group cache entries by user
    cache_group_id = get_cache_group_id('has_permission_flag_%s' % (user.pk))
    key = '%s_%s_has_perm_flag_%s_%s_%s_%s' % (settings.CACHE_MIDDLEWARE_KEY_PREFIX, cache_group_id, user.pk, flag,
                                            contentobject and contentobject.pk or '0', group.pk)

    res = cache.get(key, False)
    if res:
        return res

    # TODO cache rolegroup_ids for user ?
    rolegroup_ids = RoleGroupMember.objects.filter(rolegroup__group = group, user = user).values_list('id',flat=True)

    # Check if the user has a global flag ...
    userselect = (Q(user = user) & Q(rolegroup__isnull = True)) \
        | (Q(rolegroup__in = rolegroup_ids) & Q(user__isnull = True))
    matches = RoleMember.objects.filter(
        userselect,
        role__permission_flags__name__exact = flag, has_limitations = False ).count()

    if matches > 0:
        res = True
    else:
        # if it wasn't found ...
        # ... lookup flag for the given model:
        if contentobject is not None:
            content_type = ContentType.objects.get_for_model(contentobject)
            rolemembers = RoleMember.objects.filter( userselect,
                                                     role__permission_flags__name__exact = flag,
                                                     has_limitations = True,

                                                     rolememberlimitation__object_type = content_type,
                                                     rolememberlimitation__object_id = contentobject.id,
                                                     ).count()
            if rolemembers > 0:
                res = True

        # ... lookup the group_administrator flag:
        if not res and flag != 'group_administrator':
            res = has_permission_flag(user, 'group_administrator')
    cache.set(key, res, 86400)
    return res
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:59,代码来源:permissionutils.py


示例11: sph_reverse

def sph_reverse(viewname, args=(), kwargs={}):
    req = get_current_request()
    urlconf = getattr(req, "urlconf", None)
    sphdata = get_current_sphdata()
    if "group_fromhost" in sphdata and not sphdata.get("group_fromhost", False):
        kwargs["groupName"] = get_current_group().name
    elif "groupName" in kwargs:
        del kwargs["groupName"]
    return reverse(viewname, urlconf, args, kwargs)
开发者ID:snavien,项目名称:sct-communitytools,代码行数:9,代码来源:sphutils.py


示例12: sphboard_post_authorinfo

def sphboard_post_authorinfo(user_id):
    if user_id is None:
        user = None
    else:
        user = User.objects.get(pk = user_id)

    return {'author': user,
            'STATIC_URL': settings.STATIC_URL,
            'post_count': UserPostCount.objects.get_post_count(user, get_current_group())}
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:9,代码来源:sphboard_extras.py


示例13: sph_reverse

def sph_reverse( viewname, args=(), kwargs={} ):
    req = get_current_request()
    urlconf = getattr(req, 'urlconf', None)
    sphdata = get_current_sphdata()
    if 'group_fromhost' in sphdata and \
            not sphdata.get('group_fromhost', False):
        kwargs['groupName'] = get_current_group().name
    elif 'groupName' in kwargs:
        del kwargs['groupName']
    return reverse( viewname, urlconf, args, kwargs )
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:10,代码来源:sphutils.py


示例14: show_active_monitors

def show_active_monitors(context, profile_user):
    user = context['user']
    request = context['request']

    if user==profile_user:
        monitors = Monitor.objects.filter(Q(thread=None)|Q(thread__is_hidden=0),
                                          user = profile_user,
                                          group = get_current_group()
                                          )
    else:
        if not has_permission_flag(request.user, 'community_manage_users'):
            raise PermissionDenied()
        monitors = Monitor.objects.filter(Q(thread=None)|Q(thread__is_hidden=0),
                                          user = profile_user,
                                          group = get_current_group()
                                          )
    return {'monitors':monitors,
            'request':request,
            'is_current_user':user==profile_user}
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:19,代码来源:sphboard_extras.py


示例15: get_object

 def get_object(self, request, category_id = None):
     group = get_current_group()
     categories = get_board_categories(group)
     if not category_id:
         return categories
     #category_id = int(bits[0])
     categories = [category for category in categories \
                       if category.id == category_id]
     if not categories:
         raise Http404
     return categories
开发者ID:hmm,项目名称:sct-communitytools,代码行数:11,代码来源:feeds.py


示例16: clean

    def clean(self, value):
        value = super(SelectCategoryField, self).clean(value)

        if value in forms.fields.EMPTY_VALUES:
            return None
        
        category = Category.objects.get( pk = value, group = get_current_group() )

        value = category
        
        return value
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:11,代码来源:boardforms.py


示例17: items

    def items(self):
        group = get_current_group()

        ## Check permissions
        all_categories = Category.objects.filter( group = group )
        allowed_categories = ()
        for category in all_categories:
            if category.has_view_permission( ):
                allowed_categories += (category.id,)

        return Post.objects.filter( category__id__in = allowed_categories, thread__isnull = True, )
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:11,代码来源:sitemaps.py


示例18: get_object

 def get_object(self, bits):
     group = get_current_group()
     categories = get_board_categories(group)
     if len(bits) != 1:
         return categories
     category_id = int(bits[0])
     categories = [category for category in categories \
                       if category.id == category_id]
     if not categories:
         raise Http404
     return categories
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:11,代码来源:feeds.py


示例19: render

    def render(self, name, value, attrs=None):
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<select%s><option value="">%s</option>' % (forms.util.flatatt(final_attrs), _(u'-- Select Category --'))]

        # Load all root categories and iterate them...
        group = get_current_group()
        categories = Category.objects.filter( group = group, parent__isnull = True )

        self._print_category_option(output, categories)
        
        output.append(u'</select>')
        return u'\n'.join(output)
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:12,代码来源:boardforms.py


示例20: get_contents

    def get_contents(self, origin):
        group = get_current_group()
        template_name: str = origin.template_name
        if group is None:
            # If there is no current group .. we have nothing to do ..
            raise TemplateDoesNotExist(template_name)

        template_dir: str = sphsettings.get_sph_setting('community_groupaware_template_dir', None)

        if template_dir is not None:
            template_path = safe_join(os.path.join(template_dir, group.name), template_name)
            try:
                with open(template_path, encoding=self.engine.file_charset) as fp:
                    return fp.read()
            except FileNotFoundError as e:
                #logger.debug('File not found', e)
                pass

            prefix = 'groups/%s/' % group.name
            if template_name.startswith(prefix):
                template_name = template_name.replace(prefix, '')
                template_path = safe_join(os.path.join(template_dir, group.name), template_name)
                try:
                    with open(template_path, encoding=self.engine.file_charset) as fp:
                        return fp.read()
                except FileNotFoundError as e:
                    logger.warning('File no found', e)


        # Look in the cache . .so we don't have to make unnecessary database
        # queries
        cachekey = _get_cache_key(template_name, group)
        ret = cache.get( cachekey )
        if ret is not None:
            if ret == NOT_EXIST_CACHE_VALUE:
                raise TemplateDoesNotExist(template_name)

            return ret

        while group is not None:
            try:
                template = GroupTemplate.objects.get( template_name = template_name,
                                                      group = group, )
                ret = (template.source, "%s:%s" % (group.name, template.template_name))
                # Cache for two hours by default ..
                cache.set(cachekey, ret, TMPL_CACHE_EXPIRE)
                return ret
            except GroupTemplate.DoesNotExist:
                group = group.parent

        cache.set(cachekey, NOT_EXIST_CACHE_VALUE, TMPL_CACHE_EXPIRE)
        raise TemplateDoesNotExist(template_name)
开发者ID:hpoul,项目名称:sct-communitytools,代码行数:52,代码来源:groupaware_templateloader.py



注:本文中的sphene.community.middleware.get_current_group函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sphutils.get_sph_setting函数代码示例发布时间:2022-05-27
下一篇:
Python utils.newline_msg函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap