本文整理汇总了Python中tendenci.core.perms.utils.update_perms_and_save函数的典型用法代码示例。如果您正苦于以下问题:Python update_perms_and_save函数的具体用法?Python update_perms_and_save怎么用?Python update_perms_and_save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_perms_and_save函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add
def add(request, form_class=ArticleForm, template_name="articles/add.html"):
if has_perm(request.user, 'articles.add_article'):
if request.method == "POST":
form = form_class(request.POST, user=request.user)
if form.is_valid():
article = form.save(commit=False)
# add all permissions and save the model
update_perms_and_save(request, form, article)
messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % article)
# send notification to administrator(s) and module recipient(s)
recipients = get_notice_recipients('module', 'articles', 'articlerecipients')
if recipients and notification:
notification.send_emails(recipients, 'article_added', {
'object': article,
'request': request,
})
return HttpResponseRedirect(reverse('article', args=[article.slug]))
else:
form = form_class(user=request.user)
return render_to_response(template_name, {'form': form},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:repos-python,项目名称:tendenci,代码行数:28,代码来源:views.py
示例2: add
def add(request, form_class=ArticleForm,
category_form_class=CategoryForm,
template_name="articles/add.html"):
content_type = get_object_or_404(ContentType,
app_label='articles',
model='article')
if has_perm(request.user, 'articles.add_article'):
if request.method == "POST":
form = form_class(request.POST, user=request.user)
categoryform = category_form_class(content_type,
request.POST,
prefix='category')
if form.is_valid() and categoryform.is_valid():
article = form.save()
article.update_category_subcategory(
categoryform.cleaned_data['category'],
categoryform.cleaned_data['sub_category']
)
# add all permissions and save the model
update_perms_and_save(request, form, article)
messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % article)
# send notification to administrator(s) and module recipient(s)
recipients = get_notice_recipients('module', 'articles', 'articlerecipients')
if recipients and notification:
notification.send_emails(recipients, 'article_added', {
'object': article,
'request': request,
})
return HttpResponseRedirect(reverse('article', args=[article.slug]))
else:
form = form_class(user=request.user)
initial_category_form_data = {
'app_label': 'articles',
'model': 'article',
'pk': 0,
}
categoryform = category_form_class(content_type,
initial=initial_category_form_data,
prefix='category')
return render_to_response(template_name, {'form': form,
'categoryform': categoryform,},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:jkimma,项目名称:tendenci,代码行数:50,代码来源:views.py
示例3: edit
def edit(request, id, form_class=ArticleForm,
category_form_class=CategoryForm,
template_name="articles/edit.html"):
article = get_object_or_404(Article, pk=id)
content_type = get_object_or_404(ContentType, app_label='articles',
model='article')
if has_perm(request.user, 'articles.change_article', article):
if request.method == "POST":
form = form_class(request.POST, instance=article, user=request.user)
categoryform = category_form_class(content_type,
request.POST,
prefix='category')
if form.is_valid() and categoryform.is_valid():
article = form.save()
article.update_category_subcategory(
categoryform.cleaned_data['category'],
categoryform.cleaned_data['sub_category']
)
# update all permissions and save the model
update_perms_and_save(request, form, article)
messages.add_message(request, messages.SUCCESS, 'Successfully updated %s' % article)
return HttpResponseRedirect(reverse('article', args=[article.slug]))
else:
form = form_class(instance=article, user=request.user)
category = Category.objects.get_for_object(article, 'category')
sub_category = Category.objects.get_for_object(article, 'sub_category')
initial_category_form_data = {
'app_label': 'articles',
'model': 'article',
'pk': article.pk,
'category': getattr(category, 'name', '0'),
'sub_category': getattr(sub_category, 'name', '0')
}
categoryform = category_form_class(content_type,
initial=initial_category_form_data,
prefix='category')
return render_to_response(template_name, {'article': article,
'form': form,
'categoryform': categoryform,},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:jkimma,项目名称:tendenci,代码行数:50,代码来源:views.py
示例4: add
def add(request, form_class=NewsForm, template_name="news/add.html"):
# check permission
if not has_perm(request.user, "news.add_news"):
raise Http403
if request.method == "POST":
form = form_class(request.POST, request.FILES, user=request.user)
if form.is_valid():
news = form.save(commit=False)
# update all permissions and save the model
news = update_perms_and_save(request, form, news)
# save photo
photo = form.cleaned_data["photo_upload"]
if photo:
news.save(photo=photo)
assign_files_perms(news, files=[news.thumbnail])
messages.add_message(request, messages.SUCCESS, "Successfully added %s" % news)
# 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_added", extra_context)
return HttpResponseRedirect(reverse("news.detail", args=[news.slug]))
else:
form = form_class(user=request.user)
return render_to_response(template_name, {"form": form}, context_instance=RequestContext(request))
开发者ID:githubber,项目名称:tendenci,代码行数:33,代码来源:views.py
示例5: 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:BillTheBest,项目名称:tendenci,代码行数:27,代码来源:views.py
示例6: add
def add(request, form_class=NewsForm, template_name="news/add.html"):
# check permission
if not has_perm(request.user, 'news.add_news'):
raise Http403
if request.method == "POST":
form = form_class(request.POST, user=request.user)
if form.is_valid():
news = form.save(commit=False)
# update all permissions and save the model
news = update_perms_and_save(request, form, news)
messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % news)
# 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_added', extra_context)
return HttpResponseRedirect(reverse('news.detail', args=[news.slug]))
else:
form = form_class(user=request.user)
return render_to_response(template_name, {'form': form},
context_instance=RequestContext(request))
开发者ID:eloyz,项目名称:tendenci,代码行数:32,代码来源:views.py
示例7: edit
def edit(request, id, form_class=ResumeForm, template_name="resumes/edit.html"):
resume = get_object_or_404(Resume, pk=id)
print request.FILES
form = form_class(request.POST or None, request.FILES or None, instance=resume, user=request.user)
if has_perm(request.user,'resumes.change_resume',resume):
if request.method == "POST":
if form.is_valid():
resume = form.save(commit=False)
if resume.resume_file:
resume.resume_file.file.seek(0)
resume = update_perms_and_save(request, form, resume)
log_defaults = {
'event_id' : 352000,
'event_data': '%s (%d) edited by %s' % (resume._meta.object_name, resume.pk, request.user),
'description': '%s edited' % resume._meta.object_name,
'user': request.user,
'request': request,
'instance': resume,
}
EventLog.objects.log(**log_defaults)
messages.add_message(request, messages.SUCCESS, 'Successfully updated %s' % resume)
return HttpResponseRedirect(reverse('resume', args=[resume.slug]))
return render_to_response(template_name, {'resume': resume, 'form':form},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:repos-python,项目名称:tendenci,代码行数:31,代码来源:views.py
示例8: user_membership_add
def user_membership_add(request, username, form_class=UserMembershipForm, template_name="profiles/add_membership.html"):
user = get_object_or_404(User, username=username)
try:
profile = Profile.objects.get(user=user)
except Profile.DoesNotExist:
profile = Profile.objects.create_profile(user=user)
if not request.user.profile.is_superuser:
raise Http403
if request.method == 'POST':
form = form_class(request.POST)
if form.is_valid():
membership = form.save(commit=False)
membership = update_perms_and_save(request, form, membership)
messages.add_message(request, messages.SUCCESS, 'Successfully updated memberships for %s' % user.get_full_name())
membership.populate_or_clear_member_id()
return HttpResponseRedirect("%s%s" % (reverse('profile', args=[user.username]),'#userview-memberships'))
else:
form = form_class(initial={'user':user})
return render_to_response(template_name, {
'form': form,
'user_this': user,
}, context_instance=RequestContext(request))
开发者ID:repos-python,项目名称:tendenci,代码行数:26,代码来源:views.py
示例9: 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 %s' % form_instance)
return HttpResponseRedirect(reverse('form_field_update', args=[form_instance.pk]))
else:
form = form_class(user=request.user)
return render_to_response(template_name, {
'form':form,
'formset':formset,
}, context_instance=RequestContext(request))
开发者ID:MariusCC,项目名称:tendenci,代码行数:30,代码来源:views.py
示例10: save_model
def save_model(self, request, object, form, change):
instance = form.save(commit=False)
instance = update_perms_and_save(request, form, instance)
if instance.meta:
meta = instance.meta
else:
meta = MetaTags()
meta.title = form.cleaned_data['meta_title']
meta.description = form.cleaned_data['meta_description']
meta.keywords = form.cleaned_data['meta_keywords']
meta.canonical_url = form.cleaned_data['meta_canonical_url']
meta.save()
instance.meta = meta
instance.save()
# notifications
if not request.user.profile.is_superuser:
# send notification to administrators
recipients = get_notice_recipients('module', 'pages', 'pagerecipients')
notice_type = 'page_added'
if change: notice_type = 'page_edited'
if recipients:
if notification:
extra_context = {
'object': instance,
'request': request,
}
notification.send_emails(recipients, notice_type, extra_context)
return instance
开发者ID:MariusCC,项目名称:tendenci,代码行数:32,代码来源:admin.py
示例11: edit
def edit(request, id=None, form_class=HelpFileForm, template_name="help_files/edit.html"):
help_file = get_object_or_404(HelpFile, pk=id)
if has_perm(request.user,'help_files.change_helpfile', help_file):
if request.method == "POST":
form = form_class(request.POST, instance=help_file, user=request.user)
if form.is_valid():
help_file = form.save(commit=False)
# add all permissions and save the model
help_file = update_perms_and_save(request, form, help_file)
form.save_m2m()
messages.add_message(request, messages.SUCCESS, 'Successfully edited %s' % help_file)
# send notification to administrator(s) and module recipient(s)
recipients = get_notice_recipients('module', 'help_files', 'helpfilerecipients')
# if recipients and notification:
# notification.send_emails(recipients,'help_file_added', {
# 'object': help_file,
# 'request': request,
# })
return HttpResponseRedirect(reverse('help_file.details', args=[help_file.slug]))
else:
form = form_class(instance=help_file, user=request.user)
return render_to_response(template_name, {'help_file': help_file, 'form':form},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:DeepInTheCode,项目名称:tendenci,代码行数:30,代码来源:views.py
示例12: add
def add(request, form_class=LocationForm, template_name="locations/add.html"):
if has_perm(request.user,'locations.add_location'):
if request.method == "POST":
form = form_class(request.POST, request.FILES, 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)
messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % location)
return HttpResponseRedirect(reverse('location', args=[location.pk]))
else:
form = form_class(user=request.user)
return render_to_response(template_name, {'form':form},
context_instance=RequestContext(request))
else:
raise Http403
开发者ID:warhotdog,项目名称:tendenci,代码行数:25,代码来源:views.py
示例13: 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:sarahmworthy,项目名称:tendenci,代码行数:34,代码来源:views.py
示例14: edit
def edit(request, id, form_class=StoryForm, template_name="stories/edit.html"):
story = get_object_or_404(Story, pk=id)
if has_perm(request.user,'stories.change_story', story):
if request.method == "POST":
form = form_class(request.POST, request.FILES,
instance=story, user=request.user)
if form.is_valid():
story = form.save(commit=False)
# save photo
photo = form.cleaned_data['photo_upload']
if photo:
story.save(photo=photo)
story = update_perms_and_save(request, form, story)
messages.add_message(request, messages.SUCCESS, _('Successfully updated %(str)s' % {'str':story}))
redirect_to = request.REQUEST.get('next', '')
if redirect_to:
return HttpResponseRedirect(redirect_to)
else:
return redirect('story', id=story.pk)
else:
form = form_class(instance=story, user=request.user)
else:
raise Http403
return render_to_response(template_name, {'story': story, 'form':form },
context_instance=RequestContext(request))
开发者ID:kaisatec,项目名称:tendenci,代码行数:32,代码来源:views.py
示例15: edit
def edit(request, id, form_class=ResumeForm, template_name="resumes/edit.html"):
resume = get_object_or_404(Resume, pk=id)
if has_perm(request.user, "resumes.change_resume", resume):
if request.method == "POST":
form = form_class(request.POST, instance=resume, user=request.user)
if form.is_valid():
resume = form.save(commit=False)
resume = update_perms_and_save(request, form, resume)
log_defaults = {
"event_id": 352000,
"event_data": "%s (%d) edited by %s" % (resume._meta.object_name, resume.pk, request.user),
"description": "%s edited" % resume._meta.object_name,
"user": request.user,
"request": request,
"instance": resume,
}
EventLog.objects.log(**log_defaults)
messages.add_message(request, messages.SUCCESS, "Successfully updated %s" % resume)
return HttpResponseRedirect(reverse("resume", args=[resume.slug]))
else:
form = form_class(instance=resume, user=request.user)
return render_to_response(
template_name, {"resume": resume, "form": form}, context_instance=RequestContext(request)
)
else:
raise Http403
开发者ID:eloyz,项目名称:tendenci,代码行数:31,代码来源:views.py
示例16: photoset_add
def photoset_add(request, form_class=PhotoSetAddForm, template_name="photos/photo-set/add.html"):
""" Add a photo set """
# if no permission; permission exception
if not has_perm(request.user,'photos.add_photoset'):
raise Http403
if request.method == "POST":
if request.POST["action"] == "add":
form = form_class(request.POST, user=request.user)
if form.is_valid():
photo_set = form.save(commit=False)
photo_set.author = request.user
# update all permissions and save the model
photo_set = update_perms_and_save(request, form, photo_set)
messages.add_message(request, messages.SUCCESS, 'Successfully added photo set!')
return HttpResponseRedirect(reverse('photos_batch_add', kwargs={'photoset_id':photo_set.id}))
else:
form = form_class(user=request.user)
return render_to_response(template_name, {
"photoset_form": form,
}, context_instance=RequestContext(request))
开发者ID:keith9raceland,项目名称:tendenci,代码行数:26,代码来源:views.py
示例17: add
def add(request, form_class=StoryForm, template_name="stories/add.html"):
if has_perm(request.user,'stories.add_story'):
if request.method == "POST":
form = form_class(request.POST, request.FILES, user=request.user)
if form.is_valid():
story = form.save(commit=False)
story = update_perms_and_save(request, form, story)
# save photo
photo = form.cleaned_data['photo_upload']
if photo:
story.save(photo=photo)
assign_files_perms(story, files=[story.image])
messages.add_message(request, messages.SUCCESS, 'Successfully added %s' % story)
return HttpResponseRedirect(reverse('story', args=[story.pk]))
else:
from pprint import pprint
pprint(form.errors.items())
else:
form = form_class(user=request.user)
tags = request.GET.get('tags', '')
if tags:
form.fields['tags'].initial = tags
else:
raise Http403
return render_to_response(template_name, {'form':form},
context_instance=RequestContext(request))
开发者ID:DeepInTheCode,项目名称:tendenci,代码行数:33,代码来源:views.py
示例18: save_model
def save_model(self, request, object, form, change):
"""
update the permissions backend
"""
print 'enter save_model'
instance = form.save(commit=False)
perms = update_perms_and_save(request, form, instance)
return instance
开发者ID:fbates,项目名称:tendenci-site,代码行数:8,代码来源:admin.py
示例19: add
def add(request, form_class=FileForm,template_name="files/add.html"):
# check permission
if not has_perm(request.user, 'files.add_file'):
raise Http403
if request.method == "POST":
form = form_class(request.POST, request.FILES, user=request.user)
if form.is_valid():
file = form.save(commit=False)
# set up the user information
file.creator = request.user
file.creator_username = request.user.username
file.owner = request.user
file.owner_username = request.user.username
file.save()
# update all permissions and save the model
file = update_perms_and_save(request, form, file)
#setup categories
category = Category.objects.get_for_object(file, 'category')
sub_category = Category.objects.get_for_object(file, 'sub_category')
## update the category of the file
category_removed = False
category = file.file_cat.name if file.file_cat else u''
if category:
Category.objects.update(file, category, 'category')
else: # remove
category_removed = True
Category.objects.remove(file, 'category')
Category.objects.remove(file, 'sub_category')
if not category_removed:
# update the sub category of the article
sub_category = file.file_sub_cat.name if file.file_sub_cat else u''
if sub_category:
Category.objects.update(file, sub_category, 'sub_category')
else: # remove
Category.objects.remove(file, 'sub_category')
#Save relationships
file.save()
# assign creator permissions
ObjectPermission.objects.assign(file.creator, file)
return HttpResponseRedirect(reverse('file.search'))
else:
form = form_class(user=request.user)
if 'group' in form.fields:
form.fields['group'].initial = Group.objects.get_initial_group_id()
return render_to_response(
template_name, {
'form': form,
}, context_instance=RequestContext(request))
开发者ID:droidterry,项目名称:tendenci,代码行数:58,代码来源:views.py
示例20: save_model
def save_model(self, request, object, form, change):
app = form.save(commit=False)
add = not change
# update all permissions and save the model
app = update_perms_and_save(request, form, app)
if add:
# default application fields
for default_field in get_default_membership_fields(use_for_corp=app.use_for_corp):
default_field.update({"app": app})
AppField.objects.create(**default_field)
if change:
edit_app_update_corp_fields(app)
form.save_m2m()
reserved_names = (
"membership_type",
"payment_method",
"first_name",
"last_name",
"email",
"corporate_membership",
)
for field in app.fields.visible():
if "membership-type" in field.field_type:
field.content_type = ContentType.objects.get_for_model(MembershipType)
choices = [item.name for item in app.membership_types.all()]
field.choices = ", ".join(choices)
elif "payment-method" in field.field_type:
field.content_type = ContentType.objects.get_for_model(PaymentMethod)
choices = [item.human_name for item in app.payment_methods.all()]
field.choices = ", ".join(choices)
if "first-name" in field.field_type:
field.content_type = ContentType.objects.get_for_model(User)
elif "last-name" in field.field_type:
field.content_type = ContentType.objects.get_for_model(User)
elif "email" in field.field_type:
field.content_type = ContentType.objects.get_for_model(User)
elif "corporate_membership_id" in field.field_type:
field.content_type = ContentType.objects.get_for_model(Membership)
if not field.field_name in reserved_names:
field.field_name = slugify(field.label).replace("-", "_")
# check field_name after slugify
if field.field_name in reserved_names:
hex_tail = uuid.uuid1().get_hex()[:3]
field.field_name = "%s_%s" % (field.field_name, hex_tail)
field.save()
return app
开发者ID:simonqiang,项目名称:tendenci,代码行数:57,代码来源:admin.py
注:本文中的tendenci.core.perms.utils.update_perms_and_save函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论