本文整理匯總了Python中comperio.main.tools.MessageManager.set_error方法的典型用法代碼示例。如果您正苦於以下問題:Python MessageManager.set_error方法的具體用法?Python MessageManager.set_error怎麽用?Python MessageManager.set_error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類comperio.main.tools.MessageManager
的用法示例。
在下文中一共展示了MessageManager.set_error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: user_account
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def user_account(request, username):
"""display user account details page"""
mm = MessageManager(request)
# must be an authenticated user and own the profile in order to get the form.
if request.user.is_authenticated() and request.user.username == username:
# must also be of type cUser. since the super is default to a User.
if request.user.__class__ == cUser:
if request.POST:
# collect form
form = SettingsForm(request.POST)
if form.is_valid():
s = request.user.settings
s.public_comments = form.cleaned_data['public_comments']
s.code_pkg_updates = form.cleaned_data['code_pkg_updates']
s.save()
mm.set_success("Your settings have been saved")
return render(request, 'accounts/user/account.html', {'form':form}, mm.messages())
else:
mm.set_error("Sorry! We encountered an error and were unable to save your settings")
form = SettingsForm(instance=request.user.settings)
return render(request, 'accounts/user/account.html', {'form':form}, mm.messages())
else:
# prepare form
form = SettingsForm(instance=request.user.settings)
return render(request, 'accounts/user/account.html', {'form':form}, mm.messages())
return render(request, 'accounts/user/account.html', mm.messages())
示例2: delete
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def delete(request, username):
"""delete a user account"""
# prepare messages
mm = MessageManager(request)
if request.user.is_active and request.user.username == username:
if request.user.is_superuser:
mm.set_error("um... you can't delete a super user silly.")
return redirect(request.META.get('HTTP_REFERER','/'))
# Build the removal key for account
salt = sha.new(str(random.random())).hexdigest()[:5]
removal_key = sha.new(salt+username).hexdigest()
key_expires = datetime.datetime.today() + datetime.timedelta(2)
request.user.removal_key = removal_key
request.user.key_expires = key_expires
request.user.save()
# prepare email
email_subject = 'Confirm account deletion'
email_body =\
"We just received a request to delete your Comperio account.\
\n\nTo delete your account, click this link within 48 hours:\
\n%s/users/delete/confirm/%s" % (
SITE_URL,
request.user.removal_key)
send_mail(email_subject,
email_body,
'[email protected]',
[request.user.email])
mm.set_success("We just sent you an email to verify your account removal.")
return redirect(request.META.get('HTTP_REFERER','/'))
示例3: contact
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def contact(request):
"""contact page"""
# prepare messages
mm = MessageManager(request)
if request.POST:
form = ContactForm(request.POST)
if form.is_valid():
data = request.POST.copy()
# make sure we have a human
if not form.isValidHuman(data):
mm.set_error('Sorry only humans can contact us. Try reloading the page.')
return render(request, 'main/contact.html', mm.messages(), {'form':form})
# prepare email
email_subject = 'Comperio Form Submission'
email_body =\
"Form submission from %s\n\nName: %s\nEmail: %s\n\n%s" % (
SITE_URL,
data['name'],
data['email'],
data['message'])
emails = [x[1] for x in ADMINS]
send_mail(email_subject,
email_body,
'[email protected]',
emails)
mm.set_success("Thank you! We received your message.")
return redirect('/')
else:
return render(request, 'main/contact.html', {'form':form}, mm.messages())
else:
form = ContactForm()
return render(request, 'main/contact.html', {'form':form}, mm.messages())
示例4: list_user_code
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def list_user_code(request):
"""return a list of code packages uploaded by a user"""
mm = MessageManager(request)
if request.GET:
form = LoginForm(request.GET)
if form.is_valid():
e = form.cleaned_data['username']
p = form.cleaned_data['password']
try:
user = authenticate(username=e, password=p)
except NameError:
user = None
if user is not None:
if user.is_active:
packages = CodePackage.objects.filter(user=user)
results = ''
for p in packages:
results += p.title + "\n"
return render_to_response('api/serve.html', {'result':results.rstrip('\n')})
else:
# account is disabled
mm.set_error('This account has been disabled, or has not been activated.')
else:
# invalid login
mm.set_error('Invalid credentials.')
return render(request, 'api/list_user_code.html', {'form':form}, mm.messages())
else:
# return form errors to user
return render(request, 'api/list_user_code.html', {'form':form}, mm.messages())
else:
form = DeleteCodePackageForm()
return render(request, 'api/list_user_code.html', {'form':form}, mm.messages())
示例5: edit_task
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def edit_task(request, id):
"""edit and existing task"""
mm = MessageManager(request)
t = get_object_or_404(Task, pk=id)
if request.user.is_authenticated() and request.user.username == t.user.username:
if request.POST:
# receive sent form
form = NewTaskForm(request.POST)
if form.is_valid():
mm.set_success("task updated")
t.due_date = form.cleaned_data['due_date']
t.description = form.cleaned_data['description']
notify = form.cleaned_data['notify']
if notify is False:
t.notify = False
else:
t.notify = True
t.save()
return redirect(t.get_absolute_url())
else:
mm.set_error("error")
# error
pass
else:
# setup new form
form = NewTaskForm(initial={'due_date':t.due_date, 'description':t.description, 'notify':t.notify})
return render(request, 'tasks/edit.html', {'form':form, 'task':t}, mm.messages())
else:
mm.set_notice("you are not authorized to edit that task.")
return redirect(request.META.get('HTTP_REFERER','/'))
示例6: manage_group
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def manage_group(request, gid):
"""manage a group"""
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
if request.user.is_authenticated() and request.user.is_group_manager(g):
return render(request, 'accounts/groups/manage.html', mm.messages(), {'group':g})
else:
mm.set_error("you are not allowed to manage this group")
return redirect(g.get_absolute_url())
示例7: delete_group
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def delete_group(request, gid):
"""delete a group"""
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
if request.user.is_authenticated() and request.user.is_group_manager(g):
# TODO: do we need to remove group reference from users?
g.delete()
return redirect(request.user.get_absolute_url() + "#groups")
else:
mm.set_error("you are not allowed to delete this group")
return redirect(request.META.get('HTTP_REFERER','/'))
示例8: delete_group_invitation
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def delete_group_invitation(request, gid):
"""delete the current group invitation key so that it cannot be used"""
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
if request.user.is_authenticated() and request.user.is_group_manager(g):
g.invitation_key = None
g.key_expires = None
g.save()
return redirect(g.get_absolute_url() + "/manage")
else:
mm.set_error("you are not authorized to perform this action")
return redirect(g.get_absolute_url())
示例9: group_invitation
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def group_invitation(request, gid):
"""generate an invitation url for a group"""
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
if request.user.is_authenticated() and request.user.is_group_manager(g):
# Build the invitation key
salt = sha.new(str(random.random())).hexdigest()[:5]
g.invitation_key = sha.new(salt+g.name).hexdigest()[:13]
g.key_expires = datetime.datetime.today() + datetime.timedelta(2)
g.save()
return redirect(g.get_absolute_url() + "/manage")
else:
mm.set_error("you are not authorized to perform this action")
return redirect(g.get_absolute_url())
示例10: reject_from_group
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def reject_from_group(request, gid, uid):
"""reject a pending membership request"""
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
u = get_object_or_404(cUser, pk=uid)
if request.user.is_authenticated() and request.user.is_group_manager(g):
if u in g.pending_users.all():
mm.set_success("membership refused for %s" % u.username)
g.pending_users.remove(u)
g.save()
else:
mm.set_error("you can't just reject whomever you want!")
return redirect(reverse('manage-group', None, (), {'gid':g.pk}))
return redirect(g.get_absolute_url())
示例11: create_curriculum
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def create_curriculum(request):
"""create a new curriculum container"""
mm = MessageManager(request)
if request.POST:
form = CreateCurriculumForm(request.POST)
if form.is_valid():
# save it
c = form.save(request)
mm.set_success("the curriculum was saved")
return redirect(c.get_absolute_url())
else:
mm.set_error("the form has errors")
pass
else:
form = CreateCurriculumForm()
return render(request, 'curricula/create_curriculum.html', {'form':form}, mm.messages())
示例12: admit_to_group
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def admit_to_group(request, gid, uid):
"""admit a user into a group"""
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
u = get_object_or_404(cUser, pk=uid)
if request.user.is_authenticated() and request.user.is_group_manager(g):
if u in g.pending_users.all():
mm.set_success("%s has been admitted" % u.username)
g.pending_users.remove(u)
u.groups.add(g)
g.members.add(u)
u.save()
g.save()
else:
mm.set_error("you can't just add whomever you want to your group!")
return redirect(reverse('manage-group', None, (), {'gid':g.pk}))
return redirect(g.get_absolute_url())
示例13: create_group
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def create_group(request):
"""create a new user group"""
mm = MessageManager(request)
if request.user.is_authenticated() and request.user.__class__ is cUser:
if request.POST:
form = CreateGroupForm(request.POST)
if form.is_valid():
data = request.POST.copy()
# make sure the group name is unique
try:
cGroup.objects.get(name=data["title"])
mm.set_error("that group name is already taken")
return render(request,'accounts/groups/create.html', mm.messages(), {'form':form})
except cGroup.DoesNotExist:
# create group
g = cGroup()
g.name = data["title"]
g.description = data["description"]
g.type = data["type"]
g.visibility = data["visibility"]
g.open_registration = data.has_key("open_registration")
g.save()
# add user to group
request.user.groups.add(g)
g.managers.add(request.user)
# Build the invitation key
salt = sha.new(str(random.random())).hexdigest()[:5]
g.invitation_key = sha.new(salt+g.name).hexdigest()[:13]
g.key_expires = datetime.datetime.today() + datetime.timedelta(2)
g.save()
manage_url = reverse('manage-group', None, (), {'gid':g.pk})
invite_url = "%s%s/%s" % (SITE_URL, reverse('join-group', None, (), {'gid':g.pk}), g.invitation_key)
mm.set_success("Successfully Created Group \"%s\"!<p> We automatically generated an invitation url that you can share with your friends. For more information check out the <a href=\"%s\">Administration Page</a>.</p><p>Invitation Url: <a href=\"%s\">%s</a></p>" % (g.name, manage_url, invite_url, invite_url))
# TODO: take to new group page
return redirect(g.get_absolute_url())
else:
return render(request,'accounts/groups/create.html', mm.messages(), {'form':form})
else:
# prepare new form for user
form = CreateGroupForm(initial={'open_registration':True})
return render(request,'accounts/groups/create.html', mm.messages(), {'form':form})
else:
mm.set_error("you are not allowed to create a group")
return redirect(request.META.get('HTTP_REFERER','/'))
示例14: create_lesson
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def create_lesson(request, c_id):
"""create a new lesson"""
c = get_object_or_404(Curriculum, pk=c_id)
mm = MessageManager(request)
if request.POST:
form = CreateLessonForm(request.POST)
if form.is_valid():
# save it
l = form.save(request, c)
mm.set_success("the lesson was saved")
return redirect(c.get_absolute_url())
else:
mm.set_error("the form has errors")
pass
else:
form = CreateLessonForm()
return render(request, 'curricula/create_lesson.html', {'form':form, 'curriculum':c}, mm.messages())
示例15: kick_from_group
# 需要導入模塊: from comperio.main.tools import MessageManager [as 別名]
# 或者: from comperio.main.tools.MessageManager import set_error [as 別名]
def kick_from_group(request, gid, uid):
"""kick a user out of a group"""
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
u = get_object_or_404(cUser, pk=uid)
if request.user.is_authenticated() and request.user.is_group_manager(g):
# can only kick normal users, not managers
if u in g.users():
u.groups.remove(g)
g.members.remove(u)
u.save()
g.save()
mm.set_success("%s has been kicked" % u.username)
else:
mm.set_error("you can only kick existing members")
return redirect(reverse('manage-group', None, (), {'gid':g.pk}))
return redirect(g.get_absolute_url())