本文整理汇总了Python中comperio.main.tools.MessageManager.messages方法的典型用法代码示例。如果您正苦于以下问题:Python MessageManager.messages方法的具体用法?Python MessageManager.messages怎么用?Python MessageManager.messages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comperio.main.tools.MessageManager
的用法示例。
在下文中一共展示了MessageManager.messages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_code_package
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def edit_code_package(request, id):
"""edit a code package"""
# prepare messages
mm = MessageManager(request)
cp = get_object_or_404(CodePackage, pk=id)
if request.user.is_authenticated() and request.user.username == cp.user.username:
if request.POST:
form = EditCodePackageForm(request.POST, user=request.user)
if form.is_valid():
form.save(request, cp)
mm.set_success("Your code package has been updated")
return redirect(cp.get_absolute_url())
else:
# form had errors
return render(request, 'main/code_package/edit.html', mm.messages(), {'form':form, 'code_package':cp})
else:
# prepare new form for user
cpk = None
if cp.group():
cpk = cp.group().pk
term_str = delim_list(object_taxon(cp), ',')
form = EditCodePackageForm(user=request.user, initial={'group': cpk, 'title':cp.title, 'description':cp.description, 'terms':term_str})
return render(request, 'main/code_package/edit.html', mm.messages(), {'form':form, 'code_package':cp})
else:
return redirect(request.META.get('HTTP_REFERER','/'))
示例2: edit_account
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def edit_account(request, username):
"""edit a user's account details"""
# prepare messages
mm = MessageManager(request)
try:
u = cUser.objects.get(username=username)
except cUser.DoesNotExist:
u = get_object_or_404(User, username=username)
# must be an authenticated user and own the profile in order to get the form.
if request.user.is_authenticated() and request.user == u:
if request.POST:
# collect form
form = EditAccountForm(request.POST)
if form.is_valid():
form.update(request, u)
mm.set_success("Your account has been updated")
return redirect(request.user.get_absolute_url())
else:
return render(request, 'accounts/user/edit.html', {'form':form}, mm.messages())
else:
# prepare form
form = EditAccountForm(initial={'username':u.username, 'email':u.email})
return render(request, 'accounts/user/edit.html', {'form':form}, mm.messages())
else:
return redirect(u.get_absolute_url())
示例3: edit_link
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def edit_link(request, id):
"""edit a link"""
# prepare messages
mm = MessageManager(request)
link = get_object_or_404(Link, pk=id)
if request.user.is_authenticated() and request.user.username == link.user.username:
if request.POST:
form = CreateLinkForm(request.POST, request.FILES, user=request.user)
if form.is_valid():
form.update(request, link)
mm.set_success("Your link has been updated")
return redirect(link.get_absolute_url())
else:
# form had errors
return render(request, 'main/link/edit.html', mm.messages(), {'form':form, 'link':link})
else:
# prepare new form for user
lpk = None
if link.group():
lpk = link.group().pk
term_str = delim_list(object_taxon(link), ',')
form = CreateLinkForm(user=request.user, initial={'group': lpk, 'title':link.title, 'url':link.url, 'terms':term_str})
return render(request, 'main/link/edit.html', mm.messages(), {'form':form, 'link':link})
else:
return redirect(request.META.get('HTTP_REFERER','/'))
示例4: edit_discussion
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def edit_discussion(request, id):
"""edit a discussion"""
# prepare messages
mm = MessageManager(request)
d = get_object_or_404(Discussion, pk=id)
if request.user.is_authenticated() and request.user.username == d.user.username:
if request.POST:
form = CreateDiscussionForm(request.POST, request.FILES, user=request.user)
if form.is_valid():
form.update(request, d)
mm.set_success("Your discussion has been updated")
return redirect(d.get_absolute_url())
else:
# form had errors
return render(request, 'main/discussion/edit.html', mm.messages(), {'form':form, 'discussion':d})
else:
# prepare new form for user
dpk = None
if d.group():
dpk = d.group().pk
term_str = delim_list(object_taxon(d), ',')
form = CreateDiscussionForm(user=request.user, initial={'group': dpk, 'title':d.title, 'body':d.body, 'type':d.type, 'terms':term_str})
return render(request, 'main/discussion/edit.html', mm.messages(), {'form':form, 'discussion':d})
else:
return redirect(request.META.get('HTTP_REFERER','/'))
示例5: contact
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [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())
示例6: upload
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def upload(request):
"""upload a code package to a user profile"""
mm = MessageManager(request)
if request.POST:
form = UploadCodePackageForm(request.POST, request.FILES)
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:
if form.save(request, user):
mm.set_success("package uploaded")
form = UploadCodePackageForm()
else:
mm.set_error("package could not be uploaded")
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/upload.html', {'form':form}, mm.messages())
else:
# return form errors to user
return render(request, 'api/upload.html', {'form':form}, mm.messages())
else:
form = UploadCodePackageForm()
return render(request, 'api/upload.html', {'form':form}, mm.messages())
示例7: list_user_code
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [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())
示例8: user_account
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [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())
示例9: admin_tools
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def admin_tools(request, tool):
"""automatically provides a list of tools to the administrator from the AdminTools class"""
#
# Do not add/register new tools in this def. it handles the AdminTools automatically
#
# debug is checked in AdminTools, so this is just extra protection.
if DEBUG is False:
return redirect('/')
# prepare messages
mm = MessageManager(request)
# prepare tools
at = AdminTools()
if request.user.is_authenticated and request.user.is_superuser:
# get the tools so we can compare them with the requested tool.
tool_list = class_linker(AdminTools, '')
# display tool index
if tool == '':
return render(request, 'main/admin/tools.html', mm.messages())
# Run the tools
for t, d, u in tool_list:
if tool == t:
log_list = eval("at.%s(%s)" % (t, True))
log_message = "successfully performed \"%s\" on %s objects." % (t, len(log_list))
for log in log_list:
log_message += "<Br />%s" % log
mm.set_notice(log_message)
break
return redirect(request.META.get('HTTP_REFERER','/'))
示例10: edit_task
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [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','/'))
示例11: confirm_delete
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def confirm_delete(request, removal_key):
"""confirm a account removal"""
# prepare messages
mm = MessageManager(request)
user = get_object_or_404(cUser, removal_key=removal_key)
if user.key_expires < datetime.datetime.today():
mm.set_notice("This removal code as expired.")
return render(request, 'accounts/confirm_delete.html', mm.messages(), {'expired':True})
user.key_expires = datetime.datetime.today() - datetime.timedelta(days=1)
user.is_active = False
user.save()
logout(request)
mm.set_success("Your account has been successfully removed. Please visit us again!")
return render(request, 'main/index.html', mm.messages())
示例12: create_group
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [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','/'))
示例13: tags_page
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def tags_page(request):
"""display a page of all the tags (tag cloud)"""
# TODO: make a tag cloud. may be able to use the api from our analytics framework
mm = MessageManager(request)
return render(request, 'main/tags.html', mm.messages())
#
#def image_uploader(request):
# """uploads an image to the server"""
# return None
示例14: create_bug
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [as 别名]
def create_bug(request):
"""create a new bug report"""
# prepare messages
mm = MessageManager(request)
if request.user.is_authenticated():
if request.POST:
form = BugForm(request.POST)
if form.is_valid():
form.save(request)
mm.set_success("Thanks! We'll fix this bug as soon as possible.")
return redirect('/')
else:
return render(request, 'bugs/create.html', mm.messages(), {'form':form})
else:
form = BugForm()
return render(request, 'bugs/create.html', mm.messages(), {'form':form})
mm.set_notice("You must log in before you can report a bug")
return login_view(request)
示例15: manage_group
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import messages [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())