本文整理汇总了Python中tendenci.apps.perms.utils.has_perm函数的典型用法代码示例。如果您正苦于以下问题:Python has_perm函数的具体用法?Python has_perm怎么用?Python has_perm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了has_perm函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: group_add_edit
def group_add_edit(request, group_slug=None,
form_class=GroupForm,
template_name="user_groups/add_edit.html"):
add, edit = False, False
if group_slug:
group = get_object_or_404(Group, slug=group_slug)
if not has_perm(request.user,'user_groups.change_group',group):
raise Http403
title = _("Edit Group")
edit = True
else:
group = None
if not has_perm(request.user,'user_groups.add_group'):raise Http403
title = _("Add Group")
add = True
if request.method == 'POST':
if edit:
form = form_class(request.POST, instance=group, user=request.user)
else:
form = form_class(request.POST, user=request.user)
if form.is_valid():
group = form.save(commit=False)
if not group.id:
group.creator = request.user
group.creator_username = request.user.username
# set up user permission
group.allow_user_view, group.allow_user_edit = form.cleaned_data['user_perms']
group.owner = request.user
group.owner_username = request.user.username
group = form.save()
if add:
# send notification to administrators
recipients = get_notice_recipients('module', 'groups', 'grouprecipients')
if recipients:
if notification:
extra_context = {
'object': group,
'request': request,
}
notification.send_emails(recipients,'group_added', extra_context)
EventLog.objects.log(instance=group)
return HttpResponseRedirect(group.get_absolute_url())
else:
if edit:
form = form_class(instance=group, user=request.user)
else:
form = form_class(user=request.user)
return render_to_response(template_name, {'form':form, 'titie':title, 'group':group}, context_instance=RequestContext(request))
开发者ID:jiwonlee777,项目名称:tendenci,代码行数:56,代码来源:views.py
示例2: pending
def pending(request, template_name="jobs/pending.html"):
can_view_jobs = has_perm(request.user, 'jobs.view_job')
can_change_jobs = has_perm(request.user, 'jobs.change_job')
if not all([can_view_jobs, can_change_jobs]):
raise Http403
EventLog.objects.log()
jobs = Job.objects.filter(status_detail__contains='pending')
return render_to_response(template_name, {'jobs': jobs},
context_instance=RequestContext(request))
开发者ID:ediaz1,项目名称:tendenci,代码行数:11,代码来源:views.py
示例3: pending
def pending(request, template_name="directories/pending.html"):
can_view_directories = has_perm(request.user, 'directories.view_directory')
can_change_directories = has_perm(request.user, 'directories.change_directory')
if not all([can_view_directories, can_change_directories]):
raise Http403
directories = Directory.objects.filter(status_detail__contains='pending')
EventLog.objects.log()
return render_to_response(template_name, {'directories': directories},
context_instance=RequestContext(request))
开发者ID:RMUCapstone-MIS590,项目名称:tendenci,代码行数:12,代码来源:views.py
示例4: edit_meta
def edit_meta(request, id, form_class=MetaForm, template_name="news/edit-meta.html"):
# check permission
news = get_object_or_404(News, pk=id)
if not has_perm(request.user, 'news.change_news', news):
raise Http403
defaults = {
'title': news.get_title(),
'description': news.get_description(),
'keywords': news.get_keywords(),
'canonical_url': news.get_canonical_url(),
}
news.meta = MetaTags(**defaults)
if request.method == "POST":
form = form_class(request.POST, instance=news.meta)
if form.is_valid():
news.meta = form.save() # save meta
news.save() # save relationship
msg_string = 'Successfully updated meta for %s' % unicode(news)
messages.add_message(request, messages.SUCCESS, _(msg_string))
return HttpResponseRedirect(reverse('news.detail', args=[news.slug]))
else:
form = form_class(instance=news.meta)
return render_to_response(template_name, {'news': news, 'form': form},
context_instance=RequestContext(request))
开发者ID:goetzk,项目名称:tendenci,代码行数:28,代码来源:views.py
示例5: group_members_export
def group_members_export(request, group_slug, export_target='all'):
"""
Export members for a specific group
"""
group = get_object_or_404(Group, slug=group_slug)
# if they can edit it, they can export it
if not has_perm(request.user,'user_groups.change_group', group):
raise Http403
identifier = '%s_%s' % (int(ttime.time()), request.user.id)
file_dir = 'export/groups/'
temp_export_path = '%sgroup_%d_%s_%s_temp.csv' % (file_dir,
group.id,
export_target,
identifier)
default_storage.save(temp_export_path, ContentFile(''))
# start the process
subprocess.Popen(["python", "manage.py",
"group_members_export",
'--group_id=%d' % group.id,
'--export_target=%s' % export_target,
'--identifier=%s' % identifier,
'--user_id=%s' % request.user.id])
# log an event
EventLog.objects.log()
return redirect(reverse('group.members_export_status',
args=[group.slug, export_target, identifier]))
开发者ID:jiwonlee777,项目名称:tendenci,代码行数:27,代码来源:views.py
示例6: campaign_delete
def campaign_delete(request, campaign_id, template_name="campaign_monitor/campaigns/delete.html"):
campaign = get_object_or_404(Campaign, campaign_id=campaign_id)
if not has_perm(request.user,'campaign_monitor.delete_campaign'):
raise Http403
if request.method == "POST":
try:
CSC(auth=auth, campaign_id=campaign.campaign_id).delete()
except BadRequest as e:
msg_string = 'Bad Request %s: %s' % (e.data.Code, e.data.Message)
messages.add_message(request, messages.ERROR, _(msg_string))
return redirect(campaign)
except Exception as e:
msg_string = 'Error: %s' % e
messages.add_message(request, messages.ERROR, _(msg_string))
return redirect(campaign)
campaign.delete()
messages.add_message(request, messages.SUCCESS, _('Successfully deleted campaign.'))
return redirect("campaign_monitor.campaign_index")
return render_to_resp(request=request, template_name=template_name,
context={'campaign': campaign})
开发者ID:tendenci,项目名称:tendenci,代码行数:25,代码来源:views.py
示例7: delete
def delete(request, id, template_name="committees/delete.html"):
committee = get_object_or_404(Committee, pk=id)
if not has_perm(request.user, 'committees.delete_committee'):
raise Http403
if request.method == "POST":
EventLog.objects.log(instance=committee)
messages.add_message(request, messages.SUCCESS, 'Successfully deleted %s' % committee)
# send notification to administrators
recipients = get_notice_recipients('module', 'committees', 'committeerecipients')
if recipients:
if notification:
extra_context = {
'object': committee,
'request': request,
}
notification.send_emails(recipients, 'committee_deleted', extra_context)
committee.delete()
return HttpResponseRedirect(reverse('committees.search'))
return render_to_response(template_name, {'committee': committee},
context_instance=RequestContext(request))
开发者ID:BIGGANI,项目名称:tendenci,代码行数:25,代码来源:views.py
示例8: edit_meta
def edit_meta(request, id, form_class=MetaForm, template_name="pages/edit-meta.html"):
"""
Return page that allows you to edit meta-html information.
"""
# check permission
page = get_object_or_404(Page, pk=id)
if not has_perm(request.user, "pages.change_page", page):
raise Http403
defaults = {
"title": page.get_title(),
"description": page.get_description(),
"keywords": page.get_keywords(),
"canonical_url": page.get_canonical_url(),
}
page.meta = MetaTags(**defaults)
if request.method == "POST":
form = form_class(request.POST, instance=page.meta)
if form.is_valid():
page.meta = form.save() # save meta
page.save() # save relationship
messages.add_message(
request, messages.SUCCESS, _("Successfully updated meta for %(p)s" % {"p": unicode(page)})
)
return HttpResponseRedirect(reverse("page", args=[page.slug]))
else:
form = form_class(instance=page.meta)
return render_to_response(template_name, {"page": page, "form": form}, context_instance=RequestContext(request))
开发者ID:a2call,项目名称:tendenci,代码行数:32,代码来源:views.py
示例9: edit_meta
def edit_meta(request, id, form_class=MetaForm, template_name="directories/edit-meta.html"):
directory = get_object_or_404(Directory, pk=id)
if not has_perm(request.user, 'directories.change_directory', directory):
raise Http403
defaults = {
'title': directory.get_title(),
'description': directory.get_description(),
'keywords': directory.get_keywords(),
'canonical_url': directory.get_canonical_url(),
}
directory.meta = MetaTags(**defaults)
if request.method == "POST":
form = form_class(request.POST, instance=directory.meta)
if form.is_valid():
directory.meta = form.save() # save meta
directory.save() # save relationship
msg_string = 'Successfully updated meta for %s' % directory
messages.add_message(request, messages.SUCCESS, _(msg_string))
return HttpResponseRedirect(reverse('directory', args=[directory.slug]))
else:
form = form_class(instance=directory.meta)
return render_to_response(template_name, {'directory': directory, 'form':form},
context_instance=RequestContext(request))
开发者ID:RMUCapstone-MIS590,项目名称:tendenci,代码行数:28,代码来源:views.py
示例10: delete
def delete(request, id, template_name="news/delete.html"):
news = get_object_or_404(News, pk=id)
# check permission
if not has_perm(request.user, 'news.delete_news'):
raise Http403
if request.method == "POST":
msg_string = 'Successfully deleted %s' % unicode(news)
messages.add_message(request, messages.SUCCESS, _(msg_string))
# send notification to administrators
recipients = get_notice_recipients('module', 'news', 'newsrecipients')
if recipients:
if notification:
extra_context = {
'object': news,
'request': request,
}
notification.send_emails(recipients, 'news_deleted', extra_context)
news.delete()
return HttpResponseRedirect(reverse('news.search'))
return render_to_response(template_name, {'news': news},
context_instance=RequestContext(request))
开发者ID:goetzk,项目名称:tendenci,代码行数:26,代码来源:views.py
示例11: entries_export
def entries_export(request, id, include_files=False):
form_instance = get_object_or_404(Form, pk=id)
# check permission
if not has_perm(request.user,'forms.change_form',form_instance):
raise Http403
EventLog.objects.log(instance=form_instance)
entries = form_instance.entries.all()
if entries:
if not settings.CELERY_IS_ACTIVE:
task = FormEntriesExportTask()
response = task.run(form_instance, entries, include_files)
return response
else:
task = FormEntriesExportTask.delay(form_instance, entries, include_files)
task_id = task.task_id
return redirect('form_entries_export_status', task_id)
else:
# blank csv document
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="export_entries_%d.csv"' % time.time()
import six
delimiter = ','
if six.PY2:
# string required because unicode_literals is imported at top
delimiter = delimiter.encode('utf-8')
csv.writer(response, delimiter=delimiter)
return response
开发者ID:tendenci,项目名称:tendenci,代码行数:32,代码来源:views.py
示例12: upload_file
def upload_file(request):
if not has_perm(request.user, 'theme_editor.add_themefileversion'):
raise Http403
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
upload = request.FILES['upload']
file_dir = form.cleaned_data['file_dir']
overwrite = form.cleaned_data['overwrite']
full_filename = os.path.join(file_dir, upload.name)
if os.path.isfile(full_filename) and not overwrite:
msg_string = 'File %s already exists in that folder.' % (upload.name)
messages.add_message(request, messages.ERROR, _(msg_string))
return HttpResponse('invalid', content_type="text/plain")
else:
handle_uploaded_file(upload, file_dir)
msg_string = 'Successfully uploaded %s.' % (upload.name)
messages.add_message(request, messages.SUCCESS, _(msg_string))
EventLog.objects.log()
# returning a response of "ok" (flash likes this)
# response is for flash, not humans
return HttpResponse('valid', content_type="text/plain")
else: # not valid
messages.add_message(request, messages.ERROR, form.errors)
return HttpResponse('invalid', content_type="text/plain")
else:
form = UploadForm()
return HttpResponseRedirect('/theme-editor/editor/')
开发者ID:BIGGANI,项目名称:tendenci,代码行数:35,代码来源:views.py
示例13: pricing_add
def pricing_add(request, form_class=JobPricingForm,
template_name="jobs/pricing-add.html"):
if has_perm(request.user, 'jobs.add_jobpricing'):
if request.method == "POST":
form = form_class(request.POST)
if form.is_valid():
job_pricing = form.save(commit=False)
job_pricing.status = 1
job_pricing.save(request.user)
EventLog.objects.log(instance=job_pricing)
if "_popup" in request.REQUEST:
return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % (escape(job_pricing.pk), escape(job_pricing)))
return HttpResponseRedirect(
reverse('job_pricing.view', args=[job_pricing.id]))
else:
form = form_class()
if "_popup" in request.REQUEST:
template_name="jobs/pricing-add-popup.html"
return render_to_response(template_name, {'form': form},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:ediaz1,项目名称:tendenci,代码行数:28,代码来源:views.py
示例14: single_setting
def single_setting(request, scope, scope_category, name, template_name="site_settings/list.html"):
if not has_perm(request.user,'site_settings.change_setting'):
raise Http403
settings = Setting.objects.filter(scope=scope, scope_category=scope_category, name=name).order_by('label')
if not settings:
raise Http404
if request.method == 'POST':
form = build_settings_form(request.user, settings)(request.POST, request.FILES)
if form.is_valid():
# this save method is overriden in the forms.py
form.save()
try:
if form.cleaned_data['theme']:
from django.core.management import call_command
call_command('hide_settings', 'theme')
call_command('update_settings', 'themes.%s' % form.cleaned_data['theme'].lstrip())
except:
pass
EventLog.objects.log()
msg_string = 'Successfully saved %s settings' % name.replace('_',' ').title()
messages.add_message(request, messages.SUCCESS, _(msg_string))
redirect_to = request.REQUEST.get('next', '')
if redirect_to:
return HttpResponseRedirect(redirect_to)
else:
form = build_settings_form(request.user, settings)()
return render_to_response(template_name, {'form': form }, context_instance=RequestContext(request))
开发者ID:BIGGANI,项目名称:tendenci,代码行数:33,代码来源:views.py
示例15: mark_as_paid
def mark_as_paid(request, id, template_name="invoices/mark-as-paid.html"):
"""
Makes a payment-record with a specified date/time
payment method and payment amount.
"""
invoice = get_object_or_404(Invoice, pk=id)
if not has_perm(request.user, "payments.change_payment"):
raise Http403
if request.method == "POST":
form = MarkAsPaidForm(request.POST)
if form.is_valid():
# make payment record
payment = form.save(user=request.user, invoice=invoice, commit=False)
payment = update_perms_and_save(request, form, payment)
# update invoice; make accounting entries
action_taken = invoice.make_payment(payment.creator, payment.amount)
if action_taken:
EventLog.objects.log(instance=invoice)
messages.add_message(request, messages.SUCCESS, _("Payment successfully made"))
return redirect(invoice)
else:
form = MarkAsPaidForm(initial={"amount": invoice.balance, "submit_dt": datetime.now()})
return render_to_response(
template_name, {"invoice": invoice, "form": form}, context_instance=RequestContext(request)
)
开发者ID:ZHW123,项目名称:tendenci,代码行数:34,代码来源:views.py
示例16: detail
def detail(request, id, template_name="discounts/view.html"):
discount = get_object_or_404(Discount, id=id)
if not has_perm(request.user, 'discounts.view_discount', discount):
raise Http403
registrations = Registration.objects.filter(invoice__discount_code=discount.discount_code)
registrant_list = []
for registration in registrations:
registrant_list += registration.registrant_set.filter(discount_amount__gt=0)
memberships = MembershipSet.objects.filter(invoice__discount_code=discount.discount_code)
membership_list = []
for membership in memberships:
count = DiscountUse.objects.filter(invoice=membership.invoice).count()
membership_list += membership.membershipdefault_set.all()[:count]
EventLog.objects.log(instance=discount)
return render_to_resp(
request=request, template_name=template_name,
context={'discount':discount,
'registrant_list':registrant_list,
'membership_list':membership_list}
)
开发者ID:tendenci,项目名称:tendenci,代码行数:25,代码来源:views.py
示例17: edit
def edit(request, id, form_class=LocationForm, template_name="locations/edit.html"):
location = get_object_or_404(Location, pk=id)
if has_perm(request.user,'locations.change_location',location):
if request.method == "POST":
form = form_class(request.POST, request.FILES, instance=location, user=request.user)
if form.is_valid():
location = form.save(commit=False)
# update all permissions and save the model
location = update_perms_and_save(request, form, location)
if 'photo_upload' in form.cleaned_data:
photo = form.cleaned_data['photo_upload']
if photo:
location.save(photo=photo)
msg_string = 'Successfully updated %s' % location
messages.add_message(request, messages.SUCCESS, _(msg_string))
return HttpResponseRedirect(reverse('location', args=[location.slug]))
else:
form = form_class(instance=location, user=request.user)
return render_to_response(template_name, {'location': location, 'form':form},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:BIGGANI,项目名称:tendenci,代码行数:27,代码来源:views.py
示例18: detail
def detail(request, slug=None, template_name="news/view.html"):
if not slug:
return HttpResponseRedirect(reverse('news.search'))
news = get_object_or_404(News, slug=slug)
# non-admin can not view the non-active content
# status=0 has been taken care of in the has_perm function
if (news.status_detail).lower() != 'active' and (not request.user.profile.is_superuser):
raise Http403
# check permission
if not has_perm(request.user, 'news.view_news', news):
raise Http403
#check for release date if it's in the future or not
if not news.is_released:
if not request.user.is_authenticated():
raise Http404
if not request.user.profile.is_superuser:
raise Http403
EventLog.objects.log(instance=news)
return render_to_response(template_name, {'news': news},
context_instance=RequestContext(request))
开发者ID:goetzk,项目名称:tendenci,代码行数:26,代码来源:views.py
示例19: dispatch
def dispatch(self, request, *args, **kwargs):
obj = self.get_obj()
perm = self.get_newsletter_permission()
if not has_perm(request.user, perm, obj=obj):
raise Http403
return super(NewsletterPermissionMixin, self).dispatch(request, *args, **kwargs)
开发者ID:BIGGANI,项目名称:tendenci,代码行数:7,代码来源:mixins.py
示例20: add
def add(request, form_class=FormForm, template_name="forms/add.html"):
if not has_perm(request.user,'forms.add_form'):
raise Http403
PricingFormSet = inlineformset_factory(Form, Pricing, form=PricingForm, extra=2, can_delete=False)
formset = PricingFormSet()
if request.method == "POST":
form = form_class(request.POST, user=request.user)
if form.is_valid():
form_instance = form.save(commit=False)
# save form and associated pricings
form_instance = update_perms_and_save(request, form, form_instance)
formset = PricingFormSet(request.POST, instance=form_instance)
if formset.is_valid():
# update_perms_and_save does not appear to consider ManyToManyFields
for method in form.cleaned_data['payment_methods']:
form_instance.payment_methods.add(method)
formset.save()
messages.add_message(request, messages.SUCCESS, _('Successfully added %(f)s' % {'f':form_instance}))
return HttpResponseRedirect(reverse('form_field_update', args=[form_instance.pk]))
else:
form = form_class(user=request.user)
return render_to_resp(request=request, template_name=template_name, context={
'form':form,
'formset': formset,
})
开发者ID:tendenci,项目名称:tendenci,代码行数:30,代码来源:views.py
注:本文中的tendenci.apps.perms.utils.has_perm函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论