当前位置: 首页>>代码示例>>Python>>正文


Python middleware.get_current_group函数代码示例

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


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


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