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

Python utils.get_query_filters函数代码示例

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

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



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

示例1: 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:BIGGANI,项目名称:tendenci,代码行数:32,代码来源:nav_tags.py


示例2: __init__

    def __init__(self, *args, **kwargs):
        super(FileForm, self).__init__(*args, **kwargs)
        default_groups = Group.objects.filter(status=True, status_detail="active")

        if args:
            post_data = args[0]
        else:
            post_data = None

        if self.user and not self.user.profile.is_superuser:
            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

        if self.instance and self.instance.pk:
            self.fields['file_sub_cat'].queryset = FilesCategory.objects.filter(
                                                        parent=self.instance.file_cat)

        if post_data:
            file_cat = post_data.get('file_cat', '0')
            if file_cat and file_cat != '0' and file_cat != u'':
                file_cat = FilesCategory.objects.get(pk=int(file_cat))
                self.fields['file_sub_cat'].queryset = FilesCategory.objects.filter(parent=file_cat)
        if 'file' in self.fields:
            self.fields['file'].validators = [FileValidator()]
开发者ID:tendenci,项目名称:tendenci,代码行数:34,代码来源:forms.py


示例3: __init__

    def __init__(self, *args, **kwargs):
        mts = kwargs.pop('mts')
        self.user = kwargs.pop('user')
        super(ProfileSearchForm, self).__init__(*args, **kwargs)
        self.fields['first_name'].widget.attrs.update({'placeholder': _('Exact Match Search')})
        self.fields['last_name'].widget.attrs.update({'placeholder': _('Exact Match Search')})
        self.fields['email'].widget.attrs.update({'placeholder': _('Exact Match Search')})

        if not mts:
            del self.fields['membership_type']
            del self.fields['member_only']
        else:
            choices = [(0, _('SELECT ONE'))]
            choices += [(mt.id, mt.name) for mt in mts]
            self.fields['membership_type'].widget = forms.widgets.Select(
                                    choices=choices)
            
        # group choices
        filters = get_query_filters(self.user, 'user_groups.view_group', **{'perms_field': False})
        group_choices = [(0, _('SELECT ONE'))] + list(Group.objects.filter(
                            status=True, status_detail="active"
                             ).filter(filters).distinct().order_by('name'
                            ).values_list('pk', 'name'))
        self.fields['group'].widget = forms.widgets.Select(
                                    choices=group_choices)
开发者ID:goetzk,项目名称:tendenci,代码行数:25,代码来源:forms.py


示例4: __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)
        self.fields['timezone'].initial = settings.TIME_ZONE
开发者ID:RMUCapstone-MIS590,项目名称:tendenci,代码行数:27,代码来源:forms.py


示例5: search

def search(request, template_name="news/search.html"):
    query = request.GET.get('q', None)
    form = NewsSearchForm(request.GET)

    if form.is_valid():
        try:
            news_group = int(form.cleaned_data.get('news_group', None))
        except:
            news_group = None

        if get_setting('site', 'global', 'searchindex') and query:
            news = News.objects.search(query, user=request.user)
            # use order (existing for all modules) for sorting cause the current
            # haystack + whoosh cannot sort by release_dt correctly
            news = news.order_by('-order')
        else:
            filters = get_query_filters(request.user, 'news.view_news')
            news = News.objects.filter(filters).distinct()
            news = news.order_by('-release_dt')
        if news_group:
            news = news.filter(groups__in=[news_group])
    
        if not has_perm(request.user, 'news.view_news'):
            news = news.filter(release_dt_local__lte=datetime.now())

    EventLog.objects.log()

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


示例6: __init__

    def __init__(self, *args, **kwargs):
        super(NewsForm, 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 not self.user.profile.is_superuser:
        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)
        self.fields['timezone'].initial = settings.TIME_ZONE

        # only show the remove photo checkbox if there is already a thumbnail
        if self.instance.thumbnail:
            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.thumbnail.pk, basename(self.instance.thumbnail.file.name))
        else:
            self.fields.pop('remove_photo')
开发者ID:BIGGANI,项目名称:tendenci,代码行数:35,代码来源:forms.py


示例7: detail

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

    if has_perm(request.user, 'committees.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:BIGGANI,项目名称:tendenci,代码行数:33,代码来源:views.py


示例8: __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:ZHW123,项目名称:tendenci,代码行数:28,代码来源:forms.py


示例9: 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:jiwonlee777,项目名称:tendenci,代码行数:28,代码来源:views.py


示例10: category

def category(request, template_name="projects/category.html"):
    query = request.GET.get('q', None)

    if get_setting('site', 'global', 'searchindex') and query:
        projects = Project.objects.search(query, user=request.user)
    else:
        filters = get_query_filters(request.user, 'projects.search')
        projects = Project.objects.filter(filters).distinct()

    categories = Category.objects.all()
    category_id = request.GET.get('category', None)

    if category_id:
        try:
            category = Category.objects.get(pk=category_id)
        except:
            category = None

        if category:
            projects = projects.filter(category=category)

    log_defaults = {
        'event_id' : 1180400,
        'event_data': '%s searched by %s' % ('Project', request.user),
        'description': '%s searched' % 'Project',
        'user': request.user,
        'request': request,
        'source': 'projects'
    }

    EventLog.objects.log(**log_defaults)

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


示例11: 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 is not None:
                locations.append(location)
            locations.sort(key=lambda x: x.distance)

    EventLog.objects.log()

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


示例12: filter_categories

    def filter_categories(self, user, qs):
        """ return a queryset with categories `user` is allowed to see """
        if not user.is_staff:
            filters = get_query_filters(user, 'forums.view_category')
            qs = qs.filter(Q(hidden=False) & filters).distinct()

        return qs
开发者ID:goetzk,项目名称:tendenci,代码行数:7,代码来源:permissions.py


示例13: 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:goetzk,项目名称:tendenci,代码行数:29,代码来源:box_tags.py


示例14: 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:BIGGANI,项目名称:tendenci,代码行数:25,代码来源:nav_tags.py


示例15: 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:goetzk,项目名称:tendenci,代码行数:29,代码来源:views.py


示例16: search

def search(request, template_name="entities/search.html"):
    filters = get_query_filters(request.user, 'entities.view_entity')
    entities = Entity.objects.filter(filters).distinct()

    EventLog.objects.log()

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


示例17: search

def search(request, template_name="entities/search.html"):
    filters = get_query_filters(request.user, 'entities.view_entity')
    entities = Entity.objects.filter(filters).distinct()

    EventLog.objects.log()

    return render_to_resp(request=request, template_name=template_name,
        context={'entities':entities})
开发者ID:tendenci,项目名称:tendenci,代码行数:8,代码来源:views.py


示例18: render

    def render(self, context):

        request = context.get('request', None)

        # make sure data in query and cat are valid
        form = EventSimpleSearchForm(request.GET)
        if form.is_valid():
            cat = form.cleaned_data.get('search_category', None)
            query = form.cleaned_data.get('q', None)
        else:
            cat = None
            query = ''

        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().extra(select={'hour': 'extract( hour from start_dt )'}).extra(select={'minute': 'extract( minute from start_dt )'})
        events = events.filter(enable_private_slug=False)

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

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

        if self.ordering == "single_day":
            events = events.order_by('-priority', 'hour', 'minute')
        else:
            if self.ordering:
                events = events.order_by(self.ordering)
            else:
                events = events.order_by('-priority', 'start_dt')

        if cat == 'priority':
            events = events.filter(**{cat : True })
        elif query and cat:
            events = events.filter(**{cat : query})

        context[self.context_var] = events
        return ''
开发者ID:goetzk,项目名称:tendenci,代码行数:56,代码来源:event_tags.py


示例19: emergency_announcement

def emergency_announcement(context, user):

    filters = get_query_filters(user, 'announcements.view_emergencyannouncement')
    announcements = EmergencyAnnouncement.objects.filter(filters).distinct()
    announcements = announcements.filter(enabled=True).order_by('-create_dt')

    context.update({
        "user": user,
        "announcements": announcements
    })
    return context
开发者ID:tendenci,项目名称:tendenci,代码行数:11,代码来源:announcement_tags.py


示例20: topic

def topic(request, id, template_name="help_files/topic.html"):
    """ List of topic help files """
    topic = get_object_or_404(Topic, pk=id)

    filters = get_query_filters(request.user, 'help_files.view_helpfile')
    help_files = HelpFile.objects.filter(filters).filter(topics__in=[topic.pk]).distinct()
    if not request.user.is_anonymous:
        help_files = help_files.select_related()

    EventLog.objects.log(instance=topic)

    return render_to_resp(request=request, template_name=template_name,
        context={'topic':topic, 'help_files':help_files})
开发者ID:tendenci,项目名称:tendenci,代码行数:13,代码来源:views.py



注:本文中的tendenci.apps.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