本文整理汇总了Python中tendenci.apps.perms.utils.get_query_filters函数的典型用法代码示例。如果您正苦于以下问题:Python get_query_filters函数的具体用法?Python get_query_filters怎么用?Python get_query_filters使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_query_filters函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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()]
示例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)
示例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
示例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))
示例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')
示例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
示例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
示例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))
示例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))
示例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},
})
示例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
示例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()
示例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()
示例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))