Python django.contrib.messages.add_message() Examples
The following are 30
code examples of django.contrib.messages.add_message().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.messages
, or try the search function
.
Example #1
Source File: views.py From oxidizr with GNU General Public License v2.0 | 7 votes |
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())
Example #2
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #4
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def add_category(request): if request.method == 'POST': form = AdvisorVisitCategoryForm(request, request.POST) if form.is_valid(): category = form.save() messages.add_message(request, messages.SUCCESS, 'Added category %s' % category) l = LogEntry(userid=request.user.username, description="Added category %s" % category, related_object=category) l.save() return HttpResponseRedirect(reverse('advising:manage_categories')) else: form = AdvisorVisitCategoryForm(request) return render(request, 'advisornotes/add_category.html', {'form': form})
Example #5
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_category(request, category_slug): category = get_object_or_404(AdvisorVisitCategory, slug=category_slug, unit__in=request.units) if request.method == 'POST': form = AdvisorVisitCategoryForm(request, request.POST, instance=category) if form.is_valid(): category = form.save() messages.add_message(request, messages.SUCCESS, 'Edited category %s' % category) l = LogEntry(userid=request.user.username, description="Edited category %s" % category, related_object=category) l.save() return HttpResponseRedirect(reverse('advisornotes:manage_categories')) else: form = AdvisorVisitCategoryForm(request, instance=category) return render(request, 'advisornotes/edit_category.html', {'form': form, 'category_slug': category.slug})
Example #6
Source File: views.py From oxidizr with GNU General Public License v2.0 | 6 votes |
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())
Example #7
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def sims_add_person(request): if request.method == 'POST': emplid = request.POST.get('emplid', None) if emplid: try: p = add_person(emplid.strip()) except SIMSProblem: p = None if isinstance(p, Person): #LOG EVENT# l = LogEntry(userid=request.user.username, description=("added %s (%s) from SIMS") % (p.name(), p.emplid), related_object=p) l.save() messages.add_message(request, messages.SUCCESS, 'Record for %s created.' % (p.name())) return _redirect_to_notes(p) return HttpResponseRedirect(reverse('advising:advising', kwargs={}))
Example #8
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def add_room_safety_item(request): if request.method == 'POST': form = RoomSafetyItemForm(request, request.POST) if form.is_valid(): item = form.save() messages.add_message(request, messages.SUCCESS, 'Safety item was created') l = LogEntry(userid=request.user.username, description="Added safety item %s" % item, related_object=item) l.save() return HttpResponseRedirect(reverse('space:manage_safety_items')) else: form = RoomSafetyItemForm(request) return render(request, 'space/add_safety_item.html', {'form': form})
Example #9
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def send_memo(request, booking_slug, from_index=0): booking = get_object_or_404(BookingRecord, slug=booking_slug, location__unit__in=Unit.sub_units(request.units)) editor = get_object_or_404(Person, userid=request.user.username) if request.method == 'POST': booking_memo = BookingMemo(booking_record=booking, created_by=editor) booking_memo.email_memo() booking_memo.save() messages.add_message(request, messages.SUCCESS, 'Memo was sent') l = LogEntry(userid=request.user.username, description="Send memo to %s" % booking.person, related_object=booking_memo) l.save() if from_index == '1': return HttpResponseRedirect(reverse('space:view_location', kwargs={'location_slug': booking.location.slug})) return HttpResponseRedirect(reverse('space:view_booking', kwargs={'booking_slug': booking.slug}))
Example #10
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #11
Source File: views.py From oxidizr with GNU General Public License v2.0 | 6 votes |
def form_valid(self, form): email_address = form.cleaned_data['email'] try: user = User.objects.get(email=email_address) except User.DoesNotExist: form._errors['email'] = ErrorList([_('This email is not registered with us.')]) context = self.get_context_data(form=form) return self.render_to_response(context) password_token = PasswordResetCode() password_token.owner = user password_token.save() password_token.send_email() self.password_token = password_token messages.add_message( request=self.request, level=messages.SUCCESS, message=_('An Email has been sent to your email address (%s) with ' 'verification code to reset the password.' % email_address), extra_tags='page-level' ) return redirect(self.get_success_url())
Example #12
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_roomtype(request, roomtype_slug): roomtype = get_object_or_404(RoomType, slug=roomtype_slug, unit__in=Unit.sub_units(request.units)) if request.method == 'POST': form = RoomTypeForm(request, request.POST, instance=roomtype) if form.is_valid(): roomtype = form.save() messages.add_message(request, messages.SUCCESS, 'Room type was edited') l = LogEntry(userid=request.user.username, description="Edited roomtype %s" % roomtype, related_object=roomtype) l.save() return HttpResponseRedirect(reverse('space:list_roomtypes')) else: form = RoomTypeForm(request, instance=roomtype) return render(request, 'space/edit_roomtype.html', {'form': form, 'roomtype': roomtype})
Example #13
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def add_roomtype(request): if request.method == 'POST': form = RoomTypeForm(request, request.POST) if form.is_valid(): roomtype = form.save() messages.add_message(request, messages.SUCCESS, 'Room type was created') l = LogEntry(userid=request.user.username, description="Added roomtype %s" % roomtype, related_object=roomtype) l.save() return HttpResponseRedirect(reverse('space:list_roomtypes')) else: form = RoomTypeForm(request) return render(request, 'space/new_roomtype.html', {'form': form})
Example #14
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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}))
Example #15
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_visa(request, visa_id): visa = get_object_or_404(Visa, pk=visa_id) if request.method == 'POST': form = VisaForm(request, request.POST, instance=visa) if form.is_valid(): visa = form.save(commit=False) visa.save() messages.add_message(request, messages.SUCCESS, 'Visa was successfully modified.' ) l = LogEntry(userid=request.user.username, description="edited visa: %s" % (visa), related_object=visa.person ) l.save() return HttpResponseRedirect(reverse('visas:list_all_visas')) else: # The initial value needs to be the person's emplid in the form. # Django defaults to the pk, which is not human readable. form = VisaForm(request, instance=visa, initial={'person': visa.person.emplid}) return render(request, 'visas/edit_visa.html', {'form': form, 'visa_id': visa_id})
Example #16
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def new_visa(request, emplid=None): if request.method == 'POST': form = VisaForm(request, request.POST) if form.is_valid(): visa = form.save(commit=False) visa.save() messages.add_message(request, messages.SUCCESS, 'Visa was created.' ) l = LogEntry(userid=request.user.username, description="added visa: %s" % (visa), related_object=visa.person ) l.save() return HttpResponseRedirect(reverse('visas:list_all_visas')) else: if emplid: person = Person.objects.get(find_userid_or_emplid(emplid)) form = VisaForm(request, initial={'person': person}) else: form = VisaForm(request) return render(request, 'visas/new_visa.html', {'form': form})
Example #17
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_location(request, location_slug, from_index=0): location = get_object_or_404(Location, slug=location_slug, unit__in=Unit.sub_units(request.units)) if request.method == 'POST': form = LocationForm(request, request.POST, instance=location) if form.is_valid(): location = form.save() messages.add_message(request, messages.SUCCESS, 'Location was edited') l = LogEntry(userid=request.user.username, description="Edited location %s" % location, related_object=location) l.save() if from_index == '1': return HttpResponseRedirect(reverse('space:index')) return view_location(request, location.slug) else: form = LocationForm(request, instance=location) return render(request, 'space/edit_location.html', {'form': form, 'location': location, 'from_index': from_index})
Example #18
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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)
Example #19
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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)
Example #20
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_event(request, event_slug): event = get_object_or_404(OutreachEvent, slug=event_slug, unit__in=request.units) if request.method == 'POST': form = OutreachEventForm(request, request.POST, instance=event) if form.is_valid(): event = form.save() messages.add_message(request, messages.SUCCESS, 'Event was saved') l = LogEntry(userid=request.user.username, description="Edited event %s" % event, related_object=event) l.save() return HttpResponseRedirect(reverse('outreach:outreach_index')) else: form = OutreachEventForm(request, instance=event) return render(request, 'outreach/edit_event.html', {'form': form, 'event_slug': event.slug})
Example #21
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def new_event(request): if request.method == 'POST': form = OutreachEventForm(request, request.POST) if form.is_valid(): event = form.save() messages.add_message(request, messages.SUCCESS, 'Event was created') l = LogEntry(userid=request.user.username, description="Added event %s" % event, related_object=event) l.save() return HttpResponseRedirect(reverse('outreach:outreach_index')) else: form = OutreachEventForm(request) return render(request, 'outreach/new_event.html', {'form': form})
Example #22
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #23
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #24
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #25
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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()
Example #26
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def manage_discussion_subscription(request, course_slug): course, view = _get_course_and_view(request, course_slug) if view is None: # course is an HttpResponse in this case return course member = get_object_or_404(Member, offering=course, person__userid=request.user.username) sub, _ = DiscussionSubscription.objects.get_or_create(member=member) if request.method == 'POST': form = DiscussionSubscriptionForm(request.POST, instance=sub) if form.is_valid(): sub = form.save(commit=False) sub.member = member sub.save() messages.add_message(request, messages.SUCCESS, 'Updated your discussion subscription.') return HttpResponseRedirect(reverse('offering:discussion:discussion_index', kwargs={'course_slug': course_slug})) else: form = DiscussionSubscriptionForm(instance=sub) context = {'course':course, 'form': form} return render(request, 'discuss/manage_discussion_subscription.html', context)
Example #27
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def disable_calendar_url(request): user = get_object_or_404(Person, userid=request.user.username) config = _get_calendar_config(user) if request.method == 'POST': form = FeedSetupForm(request.POST) if form.is_valid(): if 'token' in config: del config['token'] uc = UserConfig.objects.filter(user=user, key="calendar-config") if uc: uc = uc[0] uc.value = config uc.save() messages.add_message(request, messages.SUCCESS, 'External calendar disabled.') return HttpResponseRedirect(reverse('config:config')) else: form = FeedSetupForm({'agree': True}) context = {'form': form} return render(request, "dashboard/disable_calendar_url.html", context)
Example #28
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def create_news_url(request): user = get_object_or_404(Person, userid=request.user.username) configs = UserConfig.objects.filter(user=user, key="feed-token") if request.method == 'POST': form = FeedSetupForm(request.POST) if form.is_valid(): token = new_feed_token() if configs: c = configs[0] c.value = {'token':token} else: c = UserConfig(user=user, key="feed-token", value={'token':token}) c.save() messages.add_message(request, messages.SUCCESS, 'Feed URL configured.') return HttpResponseRedirect(reverse('config:config')) else: if configs: # pre-check if we're changing the token form = FeedSetupForm({'agree': True}) else: form = FeedSetupForm() context = {'form': form} return render(request, "dashboard/news_url.html", context)
Example #29
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def disable_news_url(request): user = get_object_or_404(Person, userid=request.user.username) if request.method == 'POST': form = FeedSetupForm(request.POST) if form.is_valid(): configs = UserConfig.objects.filter(user=user, key="feed-token") configs.delete() messages.add_message(request, messages.SUCCESS, 'External feed disabled.') return HttpResponseRedirect(reverse('config:config')) else: form = FeedSetupForm({'agree': True}) context = {'form': form} return render(request, "dashboard/disable_news_url.html", context) # management of Signature objects by manager
Example #30
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def new_signature(request): roles = Role.objects_fresh.filter(unit__in=request.units).select_related('person') people = set((p.person for p in roles)) people = sorted(list(people)) person_choices = [(p.id, p.sortname()) for p in people] if request.method == 'POST': form = SignatureForm(request.POST, request.FILES) form.fields['person'].choices = person_choices if form.is_valid(): person = Person.objects.get(id=form.cleaned_data['person']) sig, created = Signature.objects.get_or_create(user=person) if not created: sig.sig.delete(save=False) sig.sig = form.cleaned_data['signature'] sig.save() messages.add_message(request, messages.SUCCESS, 'Created signature for %s.' % (sig.user.name())) return HttpResponseRedirect(reverse('admin:signatures')) else: form = SignatureForm() form.fields['person'].choices = person_choices context = {'form': form} return render(request, "dashboard/new_signature.html", context)