当前位置: 首页>>代码示例>>Python>>正文


Python messages.add_message方法代码示例

本文整理汇总了Python中django.contrib.messages.add_message方法的典型用法代码示例。如果您正苦于以下问题:Python messages.add_message方法的具体用法?Python messages.add_message怎么用?Python messages.add_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.messages的用法示例。


在下文中一共展示了messages.add_message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: form_valid

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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()) 
开发者ID:pixlie,项目名称:oxidizr,代码行数:21,代码来源:views.py

示例2: form_valid

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [as 别名]
def form_valid(self, form):
        base, created = BaseKeyword.objects.get_or_create(term=form.cleaned_data['term'])
        keyword = Keyword()
        keyword.base = base
        keyword.project = self.request.project
        try:
            keyword.save()
        except IntegrityError:
            # The unique_together constraint on Keyword model failed
            # TODO: Handle a more specific error, IntegrityError could be raised by things other than duplicate too
            messages.add_message(
                message=_('You already have that keyword for this project, so we did not add it again.'),
                level=messages.INFO,
                request=self.request,
                extra_tags='module-level'
            )
        return HttpResponseRedirect(self.get_success_url()) 
开发者ID:pixlie,项目名称:oxidizr,代码行数:19,代码来源:views.py

示例3: new_program

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py

示例4: edit_program

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:views.py

示例5: create

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:25,代码来源:views.py

示例6: delete

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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={})) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例7: question_delete

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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.') 
开发者ID:sfu-fas,项目名称:coursys,代码行数:20,代码来源:views.py

示例8: reject

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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})) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:views.py

示例9: permission_admin_add

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:views.py

示例10: new_template

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:views.py

示例11: edit_template

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:views.py

示例12: create_topic

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:views.py

示例13: edit_topic

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [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}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:26,代码来源:views.py

示例14: edit_message

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [as 别名]
def edit_message(request, course_slug, topic_slug, message_slug):
    """
    Form to edit a recently posted reply (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)
    message = get_object_or_404(DiscussionMessage, slug=message_slug, topic=topic)
    if not message.author.person.userid == request.user.username:
        return HttpResponseForbidden
    if (datetime.datetime.now() - message.created_at) > datetime.timedelta(minutes = 5):
        raise Http404
    
    if request.method == 'POST':
        form = DiscussionMessageForm(data=request.POST, instance=message)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS, 'Reply successfully edited.')
            return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic.slug}))
    else:
        form = DiscussionMessageForm(instance=message)
    return render(request, 'discuss/edit_reply.html', {'course':course, 'topic': topic, 'message': message, 'form': form}) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:26,代码来源:views.py

示例15: remove_message

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import add_message [as 别名]
def remove_message(request, course_slug, topic_slug, message_slug):
    """
    POST to remove a topic message
    """
    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':
        raise Http404
    topic = get_object_or_404(DiscussionTopic, slug=topic_slug, offering=course)
    message = get_object_or_404(DiscussionMessage, slug=message_slug, topic=topic)
    if view == 'staff' or message.author.person.userid == request.user.username:
        message.status = 'HID'
        message.save()
        messages.add_message(request, messages.SUCCESS, 'Reply successfully removed.')
        return HttpResponseRedirect(reverse('offering:discussion:view_topic', kwargs={'course_slug': course_slug, 'topic_slug': topic_slug}))
    else:
        return HttpResponseForbidden() 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:views.py


注:本文中的django.contrib.messages.add_message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。