Python django.contrib.messages.SUCCESS Examples
The following are 30
code examples of django.contrib.messages.SUCCESS().
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 coursys with GNU General Public License v3.0 | 6 votes |
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})
Example #2
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 #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: teaching_equivalents_inst.py From coursys with GNU General Public License v3.0 | 6 votes |
def new_teaching_equivalent_inst(request): """ Instructors form to create a new teaching equivalent """ instructor = get_object_or_404(Person, userid=request.user.username) if request.method == 'POST': form = TeachingEquivForm(request.POST) if form.is_valid(): equivalent = form.save(commit=False) equivalent.credits_numerator = form.cleaned_data['credits_numerator'] equivalent.credits_denominator = form.cleaned_data['credits_denominator'] equivalent.instructor = instructor equivalent.status = 'UNCO' equivalent.save() messages.add_message(request, messages.SUCCESS, "Teaching Equivalent successfully created") return HttpResponseRedirect(reverse('planning.views.view_teaching_credits_inst')) else: form = TeachingEquivForm(initial={'semester': Semester.current().next_semester()}) return render(request, 'planning/new_teaching_equiv_inst.html', {'form': form})
Example #5
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 #6
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: create_course.py From coursys with GNU General Public License v3.0 | 6 votes |
def create_course(request): units = [(u.id, str(u)) for u in request.units] if request.method == 'POST': form = CourseForm(request.POST) form.fields['owner'].choices = units if form.is_valid(): course = form.save() #LOG EVENT# l = LogEntry(userid=request.user.username, description=("added course %s %s") % (course.subject, course.number), related_object=course) l.save() messages.add_message(request, messages.SUCCESS, 'Added course %s.' % (course)) return HttpResponseRedirect(reverse('planning.views.manage_courses', kwargs={})) else: form = CourseForm() form.fields['owner'].choices = units return render(request, "planning/create_course.html", {'form': form})
Example #8
Source File: edit_plan.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_plan(request, semester, plan_slug): plan = get_object_or_404(SemesterPlan, semester__name=semester, slug=plan_slug) if request.method == 'POST': form = PlanBasicsForm(request.POST, instance=plan) if form.is_valid(): plan = form.save() #LOG EVENT# l = LogEntry(userid=request.user.username, description=("Modified course plan %s in %s") % (plan.name, plan.semester), related_object=plan) l.save() messages.add_message(request, messages.SUCCESS, 'Plan "%s" updated.' % (plan.name)) return HttpResponseRedirect(reverse('planning.views.admin_index', kwargs={})) else: form = PlanBasicsForm(instance=plan) return render(request, "planning/edit_plan.html", {'form': form, 'plan': plan})
Example #9
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 #10
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 #11
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 #12
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def edit_room_safety_item(request, safety_item_slug): safety_item = get_object_or_404(RoomSafetyItem, unit__in=Unit.sub_units(request.units), slug=safety_item_slug) if request.method == 'POST': form = RoomSafetyItemForm(request, request.POST, instance=safety_item) if form.is_valid(): item = form.save() messages.add_message(request, messages.SUCCESS, 'Safety item was saved') l = LogEntry(userid=request.user.username, description="Edited safety item %s" % item, related_object=item) l.save() return HttpResponseRedirect(reverse('space:manage_safety_items')) else: form = RoomSafetyItemForm(request, instance=safety_item) return render(request, 'space/edit_safety_item.html', {'form': form, 'safety_item_slug': safety_item_slug})
Example #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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)
Example #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
Source File: views.py From coursys with GNU General Public License v3.0 | 6 votes |
def add_location(request): if request.method == 'POST': form = LocationForm(request, request.POST) if form.is_valid(): location = form.save() messages.add_message(request, messages.SUCCESS, 'Location was created') l = LogEntry(userid=request.user.username, description="Added location %s" % location, related_object=location) l.save() return HttpResponseRedirect(reverse('space:index')) else: form = LocationForm(request) return render(request, 'space/new_location.html', {'form': form})