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

Python utils.get_query_filters函数代码示例

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

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



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

示例1: __init__

    def __init__(self, *args, **kwargs):
        super(ArticleForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            self.fields['body'].widget.mce_attrs['app_instance_id'] = self.instance.pk
        else:
            self.fields['body'].widget.mce_attrs['app_instance_id'] = 0
            self.fields['group'].initial = Group.objects.get_initial_group_id()

        default_groups = Group.objects.filter(status=True, status_detail="active")

        if self.user and not self.user.profile.is_superuser:
            if 'status_detail' in self.fields:
                self.fields.pop('status_detail')

            filters = get_query_filters(self.user, 'user_groups.view_group', **{'perms_field': False})
            groups = default_groups.filter(filters).distinct()
            groups_list = list(groups.values_list('pk', 'name'))

            users_groups = self.user.profile.get_groups()
            for g in users_groups:
                if [g.id, g.name] not in groups_list:
                    groups_list.append([g.id, g.name])
        else:
            groups_list = default_groups.values_list('pk', 'name')

        self.fields['group'].choices = groups_list
        self.fields['google_profile'].help_text = mark_safe(GOOGLE_PLUS_HELP_TEXT)
开发者ID:josephpaulk,项目名称:tendenci,代码行数:27,代码来源:forms.py


示例2: __init__

    def __init__(self, *args, **kwargs):
        if 'user' in kwargs:
            self.user = kwargs.pop('user', None)
        else:
            self.user = None

        data = args[0] if args else kwargs['data'] if 'data' in kwargs else None
        category = data['file_cat'] if data and 'file_cat' in data else None

        super(FileSearchForm, self).__init__(*args, **kwargs)

        user = self.user or AnonymousUser()
        filters = get_query_filters(user, 'user_groups.view_group', **{'perms_field': False})
        groups = Group.objects.filter(filters).distinct()
        groups_list = [[g.id, g.name] for g in groups]
        if user.is_authenticated():
            users_groups = self.user.profile.get_groups()
            for g in users_groups:
                if [g.id, g.name] not in groups_list:
                    groups_list.append([g.id, g.name])

        groups_list.insert(0, ['', '------------'])
        self.fields['group'].choices = tuple(groups_list)

        # Update categories and subcategories choices
        main_categories = FilesCategory.objects.filter(parent__isnull=True)
        self.fields['file_cat'].queryset = main_categories
        if category:
            sub_categories = FilesCategory.objects.filter(parent=category)
            self.fields['file_sub_cat'].empty_label = "-----------"
            self.fields['file_sub_cat'].queryset = sub_categories
开发者ID:droidterry,项目名称:tendenci,代码行数:31,代码来源:forms.py


示例3: nav

def nav(context, nav_id):
    """
    Renders the nav from cache
    if not will use the navigation tag for rendering the nav
    """
    user = AnonymousUser()

    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']
    try:
        filters = get_query_filters(user, 'navs.view_nav')
        navs = Nav.objects.filter(filters).filter(id=nav_id)
        if user.is_authenticated():
            if not user.profile.is_superuser:
                navs = navs.distinct()

        nav_object = navs[0]
        nav = get_nav(nav_object.pk)
        if not nav:
            cache_nav(nav_object)
    except:
        return None

    context.update({
        "cached": nav,
        "nav_id": nav_id,
    })
    return context
开发者ID:Spacepoints,项目名称:tendenci,代码行数:29,代码来源:nav_tags.py


示例4: search

def search(request, template_name="user_groups/search.html"):
    """
    This page lists out all user groups.  If a search index
    is available, this page also allows you to search through
    user groups.
    """
    has_index = get_setting('site', 'global', 'searchindex')
    query = request.GET.get('q', None)

    if has_index and query:
        groups = Group.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'groups.view_group', perms_field=False)
        groups = Group.objects.filter(filters).distinct()
        if request.user.is_authenticated():
            groups = groups.select_related()
        groups = groups.order_by('slug')

    log_defaults = {
        'event_id' : 164000,
        'event_data': '%s searched by %s' % ('Group', request.user),
        'description': '%s searched' % 'Group',
        'user': request.user,
        'request': request,
        'source': 'user_groups'
    }
    EventLog.objects.log(**log_defaults)

    return render_to_response(template_name, {'groups':groups}, 
        context_instance=RequestContext(request))
开发者ID:legutierr,项目名称:tendenci,代码行数:30,代码来源:views.py


示例5: __init__

    def __init__(self, *args, **kwargs):
        super(ArticleForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            self.fields["body"].widget.mce_attrs["app_instance_id"] = self.instance.pk
        else:
            self.fields["body"].widget.mce_attrs["app_instance_id"] = 0
            self.fields["group"].initial = Group.objects.get_initial_group_id()

        default_groups = Group.objects.filter(status=True, status_detail="active")

        if self.user and not self.user.profile.is_superuser:
            if "status_detail" in self.fields:
                self.fields.pop("status_detail")

            filters = get_query_filters(self.user, "user_groups.view_group", **{"perms_field": False})
            groups = default_groups.filter(filters).distinct()
            groups_list = list(groups.values_list("pk", "name"))

            users_groups = self.user.profile.get_groups()
            for g in users_groups:
                if [g.id, g.name] not in groups_list:
                    groups_list.append([g.id, g.name])
        else:
            groups_list = default_groups.values_list("pk", "name")

        self.fields["group"].choices = groups_list
开发者ID:kunthar,项目名称:tendenci,代码行数:26,代码来源:forms.py


示例6: render

    def render(self, context):
        
        day = self.day.resolve(context)
        type_slug = self.type_slug.resolve(context)

        types = Type.objects.filter(slug=type_slug)

        type = None
        if types:
            type = types[0]

        day = datetime(day.year, day.month, day.day)
        weekday = day.strftime('%a')

        #one day offset so we can get all the events on that day
        bound = timedelta(hours=23, minutes=59)

        start_dt = day+bound
        end_dt = day

        filters = get_query_filters(context['user'], 'events.view_event')
        events = Event.objects.filter(filters).filter(start_dt__lte=start_dt, end_dt__gte=end_dt).distinct()

        if type:
            events = events.filter(type=type)

        if weekday == 'Sun' or weekday == 'Sat':
            events = events.filter(on_weekend=True)

        events = events.order_by(self.ordering or 'start_dt')
        
        context[self.context_var] = events
        return ''
开发者ID:repos-python,项目名称:tendenci,代码行数:33,代码来源:event_tags.py


示例7: render

    def render(self, context):
        user = AnonymousUser()

        if 'user' in context:
            if isinstance(context['user'], User):
                user = context['user']

        try:
            pk = Variable(self.pk)
            pk = pk.resolve(context)
        except:
            pk = self.pk

        try:
            filters = get_query_filters(user, 'navs.view_nav')
            nav = Nav.objects.filter(filters).filter(pk=pk)
            if user.is_authenticated():
                if not user.profile.is_superuser:
                    nav = nav.distinct()

            context[self.context_var] = nav[0]
        except:
            pass

        return unicode()
开发者ID:warhotdog,项目名称:tendenci,代码行数:25,代码来源:nav_tags.py


示例8: search

def search(request, template_name="articles/search.html"):
    get = dict(request.GET)
    query = get.pop('q', [])
    get.pop('page', None)  # pop page query string out; page ruins pagination
    query_extra = ['%s:%s' % (k, v[0]) for k, v in get.items() if v[0].strip()]
    query = ' '.join(query)
    if query_extra:
        query = '%s %s' % (query, ' '.join(query_extra))

    if get_setting('site', 'global', 'searchindex') and query:
        articles = Article.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'articles.view_article')
        articles = Article.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            articles = articles.select_related()

    if not has_perm(request.user, 'articles.view_article'):
        articles = articles.filter(release_dt__lte=datetime.now())

    articles = articles.order_by('-release_dt')

    EventLog.objects.log()

    # Query list of category and subcategory for dropdown filters
    category = request.GET.get('category')
    try:
        category = int(category)
    except:
        category = 0
    categories, sub_categories = Article.objects.get_categories(category=category)

    return render_to_response(template_name, {'articles': articles, 'categories': categories,
        'sub_categories': sub_categories},
        context_instance=RequestContext(request))
开发者ID:repos-python,项目名称:tendenci,代码行数:35,代码来源:views.py


示例9: __init__

    def __init__(self, *args, **kwargs):
        super(StoryForm, self).__init__(*args, **kwargs)
        if self.instance.image:
            self.fields['photo_upload'].help_text = '<input name="remove_photo" id="id_remove_photo" type="checkbox"/> Remove current image: <a target="_blank" href="/files/%s/">%s</a>' % (self.instance.image.pk, basename(self.instance.image.file.name))
        else:
            self.fields.pop('remove_photo')

        default_groups = Group.objects.filter(status=True, status_detail="active")

        if self.user and not self.user.profile.is_superuser:
            if 'status_detail' in self.fields:
                self.fields.pop('status_detail')

            filters = get_query_filters(self.user, 'user_groups.view_group', **{'perms_field': False})
            groups = default_groups.filter(filters).distinct()
            groups_list = list(groups.values_list('pk', 'name'))

            users_groups = self.user.profile.get_groups()
            for g in users_groups:
                if [g.id, g.name] not in groups_list:
                    groups_list.append([g.id, g.name])
        else:
            groups_list = default_groups.values_list('pk', 'name')

        self.fields['group'].choices = groups_list
开发者ID:jkimma,项目名称:tendenci,代码行数:25,代码来源:forms.py


示例10: search

def search(request, template_name="jobs/search.html"):
    query = request.GET.get('q', None)
    my_jobs = request.GET.get('my_jobs', False)
    my_pending_jobs = request.GET.get('my_pending_jobs', False)

    if get_setting('site', 'global', 'searchindex') and query:
        jobs = Job.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'jobs.view_job')
        jobs = Job.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            jobs = jobs.select_related()

    jobs = jobs.order_by('status_detail', 'list_type', '-post_dt')

    # filter for "my jobs"
    if my_jobs and not request.user.is_anonymous():
        template_name = "jobs/my_jobs.html"
        jobs = jobs.filter(creator_username=request.user.username)

    # filter for "my pending jobs"
    if my_pending_jobs and not request.user.is_anonymous():
        template_name = "jobs/my_pending_jobs.html"
        jobs = jobs.filter(
            creator_username=request.user.username,
            status_detail__contains='pending'
            )

    EventLog.objects.log()

    return render_to_response(template_name, {'jobs': jobs},
        context_instance=RequestContext(request))
开发者ID:eloyz,项目名称:tendenci,代码行数:32,代码来源:views.py


示例11: navigation

def navigation(context, nav_id):
    """
    Renders the nav and its nav items.
    This will call nav_item that will call itself recursively nesting
    the subnavs
    """
    user = AnonymousUser()

    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']

    try:
        nav_id = Variable(nav_id)
        nav_id = nav_id.resolve(context)
    except:
        pass

    try:
        filters = get_query_filters(user, 'navs.view_nav')
        navs = Nav.objects.filter(filters).filter(id=nav_id)
        if user.is_authenticated():
            if not user.profile.is_superuser:
                navs = navs.distinct()
        nav = navs[0]
    except:
        return None
    context.update({
        "nav": nav,
        "items": nav.top_items,
    })
    return context
开发者ID:warhotdog,项目名称:tendenci,代码行数:32,代码来源:nav_tags.py


示例12: detail

def detail(request, slug, template_name="committees/detail.html"):
    committee = get_object_or_404(Committee, slug=slug)

    if has_perm(request.user, "committee.view_committee", committee):
        EventLog.objects.log(instance=committee)
        officers = committee.officers()

        # has_group_view_permission is True if there is at least one
        # group where the user is a member that has a view_committee permission.
        has_group_view_permission = False
        # Check user for group view permissions
        if request.user.is_authenticated():
            groups = request.user.group_set.all()
            perms = has_groups_perms(committee).filter(group__in=groups)
            for perm in perms:
                # Check if permission has view committee permission
                has_group_view_permission |= perm.codename == "view_committee"
                if has_group_view_permission:
                    break

        filters = get_query_filters(request.user, "files.view_file")
        files = File.objects.filter(filters).filter(group=committee.group).distinct()

        return render_to_response(
            template_name,
            {
                "committee": committee,
                "officers": officers,
                "files": files,
                "has_group_view_permission": has_group_view_permission,
            },
            context_instance=RequestContext(request),
        )
    else:
        raise Http403
开发者ID:fbates,项目名称:tendenci-site,代码行数:35,代码来源:views.py


示例13: search

def search(request, cat_slug=None, template_name="videos/list.html"):
    """
    This page lists out all videos. The order can be customized.
    If a search index is available, this page will also
    have the option to search through videos.
    """
    has_index = get_setting('site', 'global', 'searchindex')
    query = request.GET.get('q', None)

    categories = Category.objects.all()
    cat = request.GET.get('cat', cat_slug)

    if has_index and query:
        if cat:
            cat_query = 'cat:%s' % cat
            query = ' '.join([query, cat_query])
            categories = Category.objects.filter(slug=cat)
            category = None
            if categories:
                category = category[0]
        videos = Video.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'videos.view_video')
        videos = Video.objects.filter(filters).distinct()
        if request.user.is_authenticated():
            videos = videos.select_related()
        videos = videos.order_by('-ordering', '-create_dt')

    EventLog.objects.log()

    return render_to_response(template_name, locals(), 
        context_instance=RequestContext(request))
开发者ID:jkimma,项目名称:tendenci-videos,代码行数:32,代码来源:views.py


示例14: membership_search

def membership_search(request, template_name="memberships/search.html"):
    membership_view_perms = get_setting('module', 'memberships', 'memberprotection')

    if not membership_view_perms == "public":
        return HttpResponseRedirect(reverse('profile.search') + "?members=on")

    query = request.GET.get('q')
    mem_type = request.GET.get('type')
    total_count = Membership.objects.all().count()
    if get_setting('site', 'global', 'searchindex') and (total_count > 1000 or query):
        members = Membership.objects.search(query, user=request.user)
        if mem_type:
            members = members.filter(mem_type=mem_type)
        members = members.order_by('last_name')
    else:
        filters = get_query_filters(request.user, 'memberships.view_membership')
        members = Membership.objects.filter(filters).distinct()
        if mem_type:
            members = members.filter(membership_type__pk=mem_type)
        members = members.exclude(status_detail='expired')
        members = members.order_by('user__last_name')
    types = MembershipType.objects.all()

    EventLog.objects.log()

    return render_to_response(template_name, {'members': members, 'types': types},
        context_instance=RequestContext(request))
开发者ID:repos-python,项目名称:tendenci,代码行数:27,代码来源:views.py


示例15: search

def search(request, template_name="directories/search.html"):
    get = dict(request.GET)
    query = get.pop('q', [])
    get.pop('page', None)  # pop page query string out; page ruins pagination
    query_extra = ['%s:%s' % (k,v[0]) for k,v in get.items() if v[0].strip()]
    query = ' '.join(query)
    if query_extra:
        query = '%s %s' % (''.join(query), ' '.join(query_extra))

    if get_setting('site', 'global', 'searchindex') and query:
        directories = Directory.objects.search(query, user=request.user).order_by('headline_exact')
    else:
        filters = get_query_filters(request.user, 'directories.view_directory')
        directories = Directory.objects.filter(filters).distinct()
        if not request.user.is_anonymous():
            directories = directories.select_related()
    
        directories = directories.order_by('headline')


    EventLog.objects.log()
    category = request.GET.get('category')
    try:
        category = int(category)
    except:
        category = 0
    categories, sub_categories = Directory.objects.get_categories(category=category)

    return render_to_response(template_name, {
        'directories':directories,
        'categories':categories,
        'sub_categories':sub_categories,
        }, 
        context_instance=RequestContext(request))
开发者ID:Spacepoints,项目名称:tendenci,代码行数:34,代码来源:views.py


示例16: nearest

def nearest(request, template_name="locations/nearest.html"):
    locations = []
    lat, lng = None, None
    query = request.GET.get('q')
    filters = get_query_filters(request.user, 'locations.view_location')

    if query:
        lat, lng = get_coordinates(address=query)

    all_locations = Location.objects.filter(filters).distinct()
    if not request.user.is_anonymous():
        all_locations = all_locations.select_related()

    if all((lat,lng)):
        for location in all_locations:
            location.distance = location.get_distance2(lat, lng)
            if location.distance != None:
                locations.append(location)
            locations.sort(key=lambda x: x.distance)

    EventLog.objects.log()

    return render_to_response(template_name, {
        'locations':locations,
        'origin': {'lat':lat,'lng':lng},
        }, context_instance=RequestContext(request))
开发者ID:Spacepoints,项目名称:tendenci,代码行数:26,代码来源:views.py


示例17: render

    def render(self, context):
        user = AnonymousUser()

        if 'user' in context:
            if isinstance(context['user'], User):
                user = context['user']

        try:
            pk = Variable(self.pk)
            pk = pk.resolve(context)
        except:
            pk = self.pk

        try:
            filters = get_query_filters(user, 'boxes.view_box')
            box = Box.objects.filter(filters).filter(pk=pk)
            if user.is_authenticated():
                if not user.profile.is_superuser:
                    box = box.distinct()
            context['box'] = box[0]
            template = get_template('boxes/edit-link.html')
            output = '<div id="box-%s" class="boxes">%s %s</div>' % (
                box[0].pk,
                box[0].content,
                template.render(context),
            )
            return output
        except:
            return unicode()
开发者ID:DeepInTheCode,项目名称:tendenci,代码行数:29,代码来源:box_tags.py


示例18: search

def search(request, template_name="resumes/search.html"):
    """
    This page lists out all resumes from newest to oldest.
    If a search index is available, this page will also
    have the option to search through resumes.
    """
    has_index = get_setting('site', 'global', 'searchindex')
    query = request.GET.get('q', None)

    if has_index and query:
        resumes = Resume.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'resumes.view_resume')
        resumes = Resume.objects.filter(filters).distinct()
        if request.user.is_authenticated():
            resumes = resumes.select_related()
    resumes = resumes.order_by('-create_dt')

    EventLog.objects.log(**{
        'event_id' : 354000,
        'event_data': '%s searched by %s' % ('Resume', request.user),
        'description': '%s searched' % 'Resume',
        'user': request.user,
        'request': request,
        'source': 'resumes'
    })

    return render_to_response(template_name, {'resumes':resumes},
        context_instance=RequestContext(request))
开发者ID:warhotdog,项目名称:tendenci,代码行数:29,代码来源:views.py


示例19: search

def search(request, template_name="user_groups/search.html"):
    """
    This page lists out all user groups.  If a search index
    is available, this page also allows you to search through
    user groups.
    """
    query = request.GET.get('q', None)
    form = GroupSearchForm(request.GET)
    cat = None

    filters = get_query_filters(request.user, 'groups.view_group', perms_field=False)
    groups = Group.objects.filter(filters).distinct()

    if request.user.is_authenticated():
        groups = groups.select_related()

    if form.is_valid():
        cat = form.cleaned_data['search_category']

        if query and cat:
            groups = groups.filter(**{cat: query} )

    groups = groups.order_by('slug')

    EventLog.objects.log()

    return render_to_response(template_name, {'groups':groups, 'form': form},
        context_instance=RequestContext(request))
开发者ID:jkimma,项目名称:tendenci,代码行数:28,代码来源:views.py


示例20: index

def index(request, template_name="help_files/index.html"):
    """List all topics and all links"""
    topic_pks = []
    filters = get_query_filters(request.user, 'help_files.view_helpfile')

    # Access the join table and iterate over a dict to avoid
    # n+1 queries to get all of the correct topics.
    byhelpfile = {}
    for tp in HelpFile_Topics.objects.select_related('helpfile', 'topic').all():
        byhelpfile.setdefault(tp.helpfile.id, []).append(tp.topic)
    # Use stored lists
    for hf in HelpFile.objects.filter(filters).distinct():
        if byhelpfile.get(hf.id, ''):
            for topic in byhelpfile[hf.id]:
                topic_pks.append(topic.pk)

    topic_pks = sorted(list(set(topic_pks)))

    topics = Topic.objects.filter(pk__in=topic_pks)
    m = len(topics) / 2
    topics = topics[:m], topics[m:] # two columns
    most_viewed = HelpFile.objects.filter(filters).order_by('-view_totals').distinct()[:5]
    featured = HelpFile.objects.filter(filters).filter(is_featured=True).distinct()[:5]
    faq = HelpFile.objects.filter(filters).filter(is_faq=True).distinct()[:3]

    EventLog.objects.log()

    return render_to_response(template_name, locals(), 
        context_instance=RequestContext(request))
开发者ID:DeepInTheCode,项目名称:tendenci,代码行数:29,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.has_perm函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_notice_recipients函数代码示例发布时间: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