本文整理汇总了Python中comperio.main.tools.MessageManager.set_notice方法的典型用法代码示例。如果您正苦于以下问题:Python MessageManager.set_notice方法的具体用法?Python MessageManager.set_notice怎么用?Python MessageManager.set_notice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comperio.main.tools.MessageManager
的用法示例。
在下文中一共展示了MessageManager.set_notice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: discussion
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
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','/'))
示例2: edit_task
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [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','/'))
示例3: admin_tools
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [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','/'))
示例4: delete_curriculum
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
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())
示例5: delete_task
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
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','/'))
示例6: delete_lesson
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
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())
示例7: confirm_delete
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [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())
示例8: create_bug
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [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)
示例9: move_link
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
def move_link(request, gid, id=None, remove=0):
"""edit a link"""
# prepare messages
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
if request.user.is_authenticated() and request.user.is_group_member(g) or request.user.is_group_manager(g):
if id:
l = get_object_or_404(Link, pk=id, user=request.user)
if remove == '1':
l.set_group(None)
else:
l.set_group(g)
links = Link.objects.select_related('group').filter(user=request.user)
return render(request, 'main/link/move.html', mm.messages(), {'group':g, 'links':links})
else:
mm.set_notice("You can't do that!")
return redirect(request.META.get('HTTP_REFERER','/'))
示例10: move_code_package
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
def move_code_package(request, gid, id=None, remove=0):
"""edit a code package"""
# prepare messages
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
if request.user.is_authenticated() and request.user.is_group_member(g) or request.user.is_group_manager(g):
if id:
cp = get_object_or_404(CodePackage, pk=id, user=request.user)
if remove == '1':
cp.set_group(None)
else:
cp.set_group(g)
codepkgs = CodePackage.objects.select_related('group').filter(user=request.user)
return render(request, 'main/code_package/move.html', mm.messages(), {'group':g, 'code_packages':codepkgs})
else:
mm.set_notice("You can't do that!")
return redirect(request.META.get('HTTP_REFERER','/'))
示例11: move_discussion
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
def move_discussion(request, gid, id=None, remove=0):
"""edit a discussion"""
# prepare messages
mm = MessageManager(request)
g = get_object_or_404(cGroup, pk=gid)
if request.user.is_authenticated() and request.user.is_group_member(g) or request.user.is_group_manager(g):
if id:
d = get_object_or_404(Discussion, pk=id, user=request.user)
if remove == '1':
d.set_group(None)
else:
d.set_group(g)
discussions = Discussion.objects.select_related('group').filter(user=request.user)
return render(request, 'main/discussion/move.html', mm.messages(), {'group':g, 'discussions':discussions})
else:
mm.set_notice("You can't do that!")
return redirect(request.META.get('HTTP_REFERER','/'))
示例12: user_metrics
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
def user_metrics(request, username):
"""display user metrics page"""
# TODO: only group administrators can view user metrics
mm = MessageManager(request)
try:
u = cUser.objects.get(username=username)
except cUser.DoesNotExist:
u = get_object_or_404(User, username=username)
has_permission_to_see_metrics = False
if request.user.is_authenticated() and request.user.username == username:
has_permission_to_see_metrics = True
elif is_manager(request.user, u):
has_permission_to_see_metrics = True
if has_permission_to_see_metrics:
return render(request, 'accounts/user/metrics.html', {'profile_user':u}, mm.messages())
else:
#raise Http404
mm.set_notice("you do not have permission to view that page")
return redirect(request.META.get('HTTP_REFERER','/'))
示例13: edit_curriculum
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
def edit_curriculum(request, id):
"""edit a curriculum"""
mm = MessageManager(request)
c = get_object_or_404(Curriculum, pk=id)
if request.user.is_authenticated() and request.user.username == c.user.username:
if request.POST:
form = CreateCurriculumForm(request.POST)
if form.is_valid():
# update it
c = form.update(request, c)
mm.set_success('"%s" has been updated' % c.title)
return redirect(c.get_absolute_url())
else:
mm.set_error("the form has errors")
pass
else:
form = CreateCurriculumForm(initial={'title':c.title, 'description':c.description})
return render(request, 'curricula/edit_curriculum.html', {'form':form, 'curriculum':c}, mm.messages())
else:
mm.set_notice('You are not authorized to edit that curriculum')
return redirect(request.META.get('HTTP_REFERER','/'))
示例14: confirm
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
def confirm(request, activation_key):
"""confirm a user registration"""
# prepare messages
mm = MessageManager(request)
if request.user.is_active and request.user.activation_key == activation_key:
raise Http404()
user = get_object_or_404(cUser, activation_key=activation_key)
if user.key_expires < datetime.datetime.today():
mm.set_notice("This activation code as expired. Try creating a new account")
# TODO: completely remove accounts that have expired
return render(request, 'accounts/confirm.html', mm.messages(), {'expired':True})
user.key_expires = datetime.datetime.today() - datetime.timedelta(days=1)
mm.set_success("Congratulations! You just activated your account!")
request.session.set_test_cookie()
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
# cookies are enabled
# we need to call authenticate to set some varibles before calling login()
auth_user = None
try:
auth_user = authenticate(username=user.username, password=user.activation_key)
# activate the user after authentication so we can't
# login with the activation key anymore
#auth_user.is_active = True
#auth_user.save()
except NameError:
pass
if auth_user is not None:
if auth_user.is_active:
login(request, auth_user)
# TODO: we don't cover all our bases here. we need to be more thorough with error checking
if auth_user:
return redirect(auth_user.get_absolute_url())
else:
return redirect('/')
示例15: delete_code_package
# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_notice [as 别名]
def delete_code_package(request):
"""delete a code package from a user account"""
mm = MessageManager(request)
if request.POST:
form = DeleteCodePackageForm(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:
p = form.cleaned_data['packageName']
try:
# TODO: can we match the package field instead?
# TODO: catch multiple items returned
p = CodePackage.objects.get(user=user, title=p)
p.delete()
mm.set_success("package deleted")
form = DeleteCodePackageForm()
except CodePackage.DoesNotExist:
mm.set_notice('package could not be found')
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/delete_code_package.html', {'form':form}, mm.messages())
else:
# return form errors to user
return render(request, 'api/delete_code_package.html', {'form':form}, mm.messages())
else:
form = DeleteCodePackageForm()
return render(request, 'api/delete_code_package.html', {'form':form}, mm.messages())