本文整理汇总了Python中django.contrib.messages.SUCCESS属性的典型用法代码示例。如果您正苦于以下问题:Python messages.SUCCESS属性的具体用法?Python messages.SUCCESS怎么用?Python messages.SUCCESS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.contrib.messages
的用法示例。
在下文中一共展示了messages.SUCCESS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_valid
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def form_valid(self, form):
user = self.user
user.backend = 'django.contrib.auth.backends.ModelBackend'
user.is_email_verified = True
user.is_active = True
user.save()
email_token = self.email_token
email_token.verified_from_ip = get_client_ip(self.request)
email_token.verified_at = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
email_token.save()
login(self.request, user)
messages.add_message(
message=_('Thank you for verifying your Email address, you are now logged in.'),
request=self.request,
level=messages.SUCCESS
)
return redirect(self.get_success_url())
示例2: new_program
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def new_program(request):
if request.method == 'POST':
form = ProgramForm(request.POST)
if form.is_valid():
program = form.save()
messages.add_message(request,
messages.SUCCESS,
'Program was created')
l = LogEntry(userid=request.user.username,
description="Added program %s" % program,
related_object=program)
l.save()
return HttpResponseRedirect(reverse('ra:programs_index'))
else:
form = ProgramForm()
form.fields['unit'].choices = [(u.id, u.name) for u in request.units]
return render(request, 'ra/new_program.html', {'form': form})
示例3: edit_program
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def edit_program(request, program_slug):
program = get_object_or_404(Program, slug=program_slug, unit__in=request.units)
if request.method == 'POST':
form = ProgramForm(request.POST, instance=program)
if form.is_valid():
program = form.save()
messages.add_message(request,
messages.SUCCESS,
'Program was created')
l = LogEntry(userid=request.user.username,
description="Added program %s" % program,
related_object=program)
l.save()
return HttpResponseRedirect(reverse('ra:programs_index'))
else:
form = ProgramForm(instance=program)
form.fields['unit'].choices = [(u.id, u.name) for u in request.units]
return render(request, 'ra/edit_program.html', {'form': form, 'program': program})
示例4: create
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def create(request):
person = get_person(request.user)
if request.method == 'POST':
form = ReminderForm(data=request.POST, person=person)
if form.is_valid():
reminder = form.save(commit=False)
reminder.person = person
reminder.save()
l = LogEntry(userid=request.user.username,
description="created reminder %s" % (reminder.slug,),
related_object=reminder
)
l.save()
messages.add_message(request, messages.SUCCESS, 'Reminder created.')
return HttpResponseRedirect(reverse('reminders:view', kwargs={'reminder_slug': reminder.slug}))
else:
form = ReminderForm(person=person)
context = {
'form': form,
}
return render(request, 'reminders/create.html', context)
示例5: delete
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def delete(request, reminder_slug):
if request.method != 'POST':
return HttpError(request, status=405, title="Method not allowed", error="This URL accepts only POST requests", errormsg=None)
reminder, person = _get_reminder_or_404(request, reminder_slug)
reminder.person = person
reminder.status = 'D'
reminder.save()
l = LogEntry(userid=request.user.username,
description="deleted reminder %s" % (reminder.slug,),
related_object=reminder
)
l.save()
messages.add_message(request, messages.SUCCESS, 'Reminder deleted.')
return HttpResponseRedirect(reverse('reminders:index', kwargs={}))
示例6: question_delete
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def question_delete(request: HttpRequest, course_slug: str, activity_slug: str, question_id: str) -> HttpResponse:
if request.method in ['POST', 'DELETE']:
quiz = get_object_or_404(Quiz, activity__slug=activity_slug, activity__offering__slug=course_slug)
if quiz.completed():
return ForbiddenResponse(request, 'Quiz is completed. You cannot modify questions after the end of the quiz time')
question = get_object_or_404(Question, quiz=quiz, id=question_id)
question.status = 'D'
question.save()
if quiz.activity.quiz_marking():
# configured for quiz-based marking: update that so the order matches
quiz.configure_marking(delete_others=False)
messages.add_message(request, messages.INFO, 'Updated marking rubric to match quiz questions.')
messages.add_message(request, messages.SUCCESS, 'Question deleted.')
LogEntry(userid=request.user.username, description='deleted quiz question id=%i' % (question.id,),
related_object=question).save()
return redirect('offering:quiz:index', course_slug=course_slug, activity_slug=activity_slug)
else:
return HttpError(request, status=405, title="Method Not Allowed", error='POST or DELETE requests only.')
示例7: version_delete
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def version_delete(request: HttpRequest, course_slug: str, activity_slug: str, question_id: str, version_id: str) -> HttpResponse:
if request.method in ['POST', 'DELETE']:
quiz = get_object_or_404(Quiz, activity__slug=activity_slug, activity__offering__slug=course_slug)
if quiz.completed():
return ForbiddenResponse(request, 'Quiz is completed. You cannot modify questions after the end of the quiz time')
question = get_object_or_404(Question, quiz=quiz, id=question_id)
version = get_object_or_404(QuestionVersion, question=question, id=version_id)
other_versions = QuestionVersion.objects.filter(question=question).exclude(id=version_id)
if not other_versions.exists():
messages.add_message(request, messages.ERROR, 'Cannot delete the only version of a question.')
return redirect('offering:quiz:question_edit', course_slug=course_slug, activity_slug=activity_slug, question_id=question_id, version_id=version_id)
version.status = 'D'
version.save()
messages.add_message(request, messages.SUCCESS, 'Question version deleted.')
LogEntry(userid=request.user.username, description='deleted quiz question version id=%i' % (question.id,),
related_object=question).save()
return redirect('offering:quiz:index', course_slug=course_slug, activity_slug=activity_slug)
else:
return HttpError(request, status=405, title="Method Not Allowed", error='POST or DELETE requests only.')
示例8: join
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def join(request, course_slug, group_slug):
course = get_object_or_404(CourseOffering, slug=course_slug)
group = get_object_or_404(Group, courseoffering = course, slug = group_slug)
person = get_object_or_404(Person, userid = request.user.username)
member = get_object_or_404(Member, person = person, offering=course)
if request.method != "POST":
return HttpResponseForbidden()
for groupMember in GroupMember.objects.filter(group = group, student = member):
groupMember.confirmed = True
groupMember.save()
#LOG EVENT#
l = LogEntry(userid=request.user.username,
description="joined group %s." % (group.name,),
related_object=group )
l.save()
messages.add_message(request, messages.SUCCESS, 'You have joined the group "%s".' % (group.name))
return HttpResponseRedirect(reverse('offering:groups:groupmanage', kwargs={'course_slug': course_slug}))
示例9: reject
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def reject(request, course_slug, group_slug):
course = get_object_or_404(CourseOffering, slug=course_slug)
group = get_object_or_404(Group, courseoffering = course, slug = group_slug)
person = get_object_or_404(Person, userid = request.user.username)
member = get_object_or_404(Member, person = person, offering=course)
if request.method != "POST":
return HttpResponseForbidden()
# delete membership on reject
GroupMember.objects.filter(group = group, student = member).delete()
#LOG EVENT#
l = LogEntry(userid=request.user.username,
description="rejected membership in group %s." % (group.name,),
related_object=group )
l.save()
messages.add_message(request, messages.SUCCESS, 'You have left the group "%s".' % (group.name))
return HttpResponseRedirect(reverse('offering:groups:groupmanage', kwargs={'course_slug': course_slug}))
示例10: permission_admin_add
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def permission_admin_add(request):
if request.method == 'POST':
form = DisciplineRoleForm(request.POST)
if form.is_valid():
r = form.save()
l = LogEntry(userid=request.user.username,
description=("added discipline role %s for %s") % (r.role, r.person.name()),
related_object=r)
l.save()
messages.add_message(request, messages.SUCCESS, 'Added role for %s.' % (r.person.name(),))
return HttpResponseRedirect(reverse('discipline:permission_admin'))
else:
form = DisciplineRoleForm()
context = {'form': form}
return render(request, "discipline/permission_admin_add.html", context)
# Template editing views for sysadmin interface
示例11: new_template
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def new_template(request):
if request.method == 'POST':
form = TemplateForm(request.POST)
if form.is_valid():
t = form.save()
#LOG EVENT#
l = LogEntry(userid=request.user.username,
description=("create discipline template %i") % (t.id),
related_object=t)
l.save()
messages.add_message(request, messages.SUCCESS, 'Created template "%s".' % (t.label))
return HttpResponseRedirect(reverse('sysadmin:show_templates'))
else:
form = TemplateForm()
context = {'form': form}
return render(request, "discipline/new_template.html", context)
示例12: edit_template
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def edit_template(request, template_id):
template = get_object_or_404(DisciplineTemplate, id=template_id)
if request.method == 'POST':
form = TemplateForm(request.POST, instance=template)
if form.is_valid():
t = form.save()
#LOG EVENT#
l = LogEntry(userid=request.user.username,
description=("edit discipline template %i") % (t.id),
related_object=t)
l.save()
messages.add_message(request, messages.SUCCESS, 'Edited template "%s".' % (t.label))
return HttpResponseRedirect(reverse('sysadmin:show_templates'))
else:
form = TemplateForm(instance=template)
context = {'template': template, 'form': form}
return render(request, "discipline/edit_template.html", context)
示例13: create_topic
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def create_topic(request, course_slug):
"""
Form to create a new discussion topic
"""
course, view = _get_course_and_view(request, course_slug)
if view is None:
# course is an HttpResponse in this case
return course
if request.method == 'POST':
form = discussion_topic_form_factory(view, data=request.POST)
if form.is_valid():
topic = form.save(commit=False)
topic.offering = course
topic.author = _get_member(request.user.username, view, course_slug)
topic.save()
messages.add_message(request, messages.SUCCESS, 'Discussion topic created successfully.')
return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic.slug}))
else:
form = discussion_topic_form_factory(view)
return render(request, 'discuss/create_topic.html', {'course': course, 'form': form})
示例14: edit_topic
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def edit_topic(request, course_slug, topic_slug):
"""
Form to edit a recently posted discussion topic (5 min window)
"""
course, view = _get_course_and_view(request, course_slug)
if view is None:
# course is an HttpResponse in this case
return course
topic = get_object_or_404(DiscussionTopic, slug=topic_slug, offering=course)
if topic.author.person.userid != request.user.username:
return HttpResponseForbidden()
if (datetime.datetime.now() - topic.created_at) > datetime.timedelta(minutes = 5):
raise Http404
if request.method == 'POST':
form = discussion_topic_form_factory(view, data=request.POST, instance=topic)
if form.is_valid():
form.save()
messages.add_message(request, messages.SUCCESS, 'Discussion topic edited successfully.')
return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic.slug}))
else:
form = discussion_topic_form_factory(view, instance=topic)
return render(request, 'discuss/edit_topic.html', {'course': course, 'topic': topic, 'form': form})
示例15: change_topic_status
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import SUCCESS [as 别名]
def change_topic_status(request, course_slug, topic_slug):
"""
Form to change the status of a topic
"""
course, view = _get_course_and_view(request, course_slug)
if view is None:
# course is an HttpResponse in this case
return course
topic = get_object_or_404(DiscussionTopic, slug=topic_slug, offering=course)
if view is not 'staff':
return HttpResponseForbidden()
if request.method == 'POST':
form = DiscussionTopicStatusForm(request.POST, instance=topic)
if form.is_valid():
form.save()
messages.add_message(request, messages.SUCCESS, 'Discussion topic has been successfully changed.')
return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic.slug}))
else:
form = DiscussionTopicStatusForm(instance=topic)
return render(request, 'discuss/change_topic.html', {'course': course, 'topic': topic, 'form': form})