本文整理汇总了Python中comperio.main.tools.MessageManager类的典型用法代码示例。如果您正苦于以下问题:Python MessageManager类的具体用法?Python MessageManager怎么用?Python MessageManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MessageManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_discussion
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','/'))
示例2: edit_code_package
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','/'))
示例3: edit_link
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: discussion
def discussion(request, id):
"""view a discussion"""
mm = MessageManager(request)
try:
d = Discussion.objects.select_related('user', 'group').get(pk=id)
except Discussion.DoesNotExist:
return Http404
if d.type == 0 or request.user.is_authenticated() and (request.user.is_group_member(d.group()) or request.user.is_group_manager(d.group())) or d.user.username == request.user.username:
#update metrics
try:
dmet = Metric.objects.get_metric(d, key='views')
if d.user.username != request.user.username:
dmet.value = int(dmet.value) + 1
except Metric.DoesNotExist:
dmet = Metric.objects.create(d, 'views', 1)
dmet.save()
# get user settings
try:
user = cUser.objects.all().get(username=d.user.username)
u_settings = user.settings
except cUser.DoesNotExist:
u_settings = None
return render(request, 'main/discussion/index.html', {'discussion':d, 'views':dmet.value, 'settings':u_settings}, mm.messages())
else:
mm.set_notice("you are not allowed to view that lab journal")
return redirect(request.META.get('HTTP_REFERER','/'))
示例5: edit_account
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())
示例6: delete
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','/'))
示例7: admin_tools
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','/'))
示例8: manage_group
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())
示例9: tags_page
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
示例10: delete_curriculum
def delete_curriculum(request, id):
"""delete an existing curriculum"""
mm = MessageManager(request)
c = get_object_or_404(Curriculum, pk=id)
if request.user.is_authenticated() and request.user.username == c.user.username:
c.delete()
return redirect(request.user.get_absolute_url())
else:
mm.set_notice('you are not authorized to delete this curriculum')
return redirect(c.get_absolute_url())
示例11: _survey_redirect
def _survey_redirect(
request,
survey,
group_slug=None,
group_slug_field=None,
group_qs=None,
template_name="survey/thankyou.html",
extra_context=None,
*args,
**kw
):
"""
Conditionally redirect to the appropriate page;
if there is a "next" value in the GET URL parameter,
go to the URL specified under Next.
If there is no "next" URL specified, then go to
the survey results page...but only if it is viewable
by the user.
Otherwise, only direct the user to a page showing
their own survey answers...assuming they have answered
any questions.
If all else fails, go to the Thank You page.
"""
if (
"next" in request.REQUEST
and request.REQUEST["next"].startswith("http:")
and request.REQUEST["next"] != request.path
):
return HttpResponseRedirect(request.REQUEST["next"])
if survey.answers_viewable_by(request.user):
return HttpResponseRedirect(reverse("survey-results", None, (), {"survey_slug": survey.__dict__["slug"]}))
# For this survey, have they answered any questions?
# if (hasattr(request, 'session') and Answer.objects.filter(
# session_key=request.session.session_key.lower(),
# question__survey__visible=True,
# question__survey__slug=survey.__dict__['slug']).count()):
# print "ytest4"
# return HttpResponseRedirect(
# reverse('answers-detail', None, (),
# {'survey_slug': survey.__dict__['slug'],
# 'key': request.session.session_key.lower()}))
# go to thank you page
# return render()
mm = MessageManager(request)
mm.set_success("Thank You For Participating In The Survey!")
return HttpResponseRedirect(request.user.get_absolute_url())
# return render_to_response(template_name,
# {'survey': survey, 'title': 'Thank You'},
# context_instance=RequestContext(request))
return render(request, template_name, {"survey": survey, "title": "Thank You"})
示例12: delete_group
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','/'))
示例13: group_page
def group_page(request, gid):
"""display the group page"""
mm = MessageManager(request)
group = get_object_or_404(cGroup, pk=gid)
manager = False
member = False
if request.user.is_authenticated() and request.user.__class__ == cUser:
manager = request.user.is_group_manager(group)
member = request.user.is_group_member(group)
pending = request.user in group.pending_users.all()
return render(request, 'accounts/groups/group_page.html', mm.messages(), {'group':group,'is_group_manager':manager, 'is_group_member':member, 'is_pending_member':pending})
示例14: delete_task
def delete_task(request, id):
"""delete a task"""
mm = MessageManager(request)
t = get_object_or_404(Task, pk=id)
if request.user.is_authenticated() and request.user.username == t.user.username:
t.delete()
mm.set_success("task removed")
return redirect(request.user.get_absolute_url())
else:
mm.set_notice("you are not authorized to delete that task.")
return redirect(request.META.get('HTTP_REFERER','/'))
示例15: delete_lesson
def delete_lesson(request, c_id, l_id):
"""delete an existing lesson"""
mm = MessageManager(request)
l = get_object_or_404(Lesson, pk=l_id)
c = get_object_or_404(Curriculum, pk=c_id)
if request.user.is_authenticated() and request.user.username == l.user.username:
name = l.title
l.delete()
mm.set_success('"%s" has been deleted' % name)
else:
mm.set_notice('you are not authorized to delete this lesson')
return redirect(c.get_absolute_url())