def edit(request,notif_id): """ Edit an existing individual notification. """ notification = get_object_or_404(Notification,pk=notif_id) if request.POST: form = NotificationForm(request.POST, instance=notification,user=request.user) if form.is_valid(): item = form.save(commit=False) item.title = form.cleaned_data['title'] item.description = sanitizeHtml(form.cleaned_data['description']) item.author = request.user item.state = 'draft' item.save() # Also move to queue or drafts if that submit button was clicked. # enqueue() and endraft() take lists, not a single item, hence list notation if 'enqueue' in request.POST: enqueue(request,[notification,]) return HttpResponseRedirect(reverse('notifications_queue')) if 'endraft' in request.POST: endraft(request,[notification,]) return HttpResponseRedirect(reverse('notifications')) if 'trash' in request.POST: trash(request,[notification,]) return HttpResponseRedirect(reverse('notifications_trash')) messages.success(request, "%s was changed." % item.title) return HttpResponseRedirect(reverse('notifications')) else: form = NotificationForm(instance=notification,user=request.user) return render_to_response('notifications/edit.html', locals(), context_instance=RequestContext(request))
def create(request): """ Create a new notification """ if request.POST: form = NotificationForm(request.POST,user=request.user) if form.is_valid(): item = form.save(commit=False) item.title = form.cleaned_data['title'] item.description = sanitizeHtml(form.cleaned_data['description']) item.author = request.user item.state = 'draft' item.save() messages.success(request, "Notification draft added.") return HttpResponseRedirect(reverse('notifications')) else: form = NotificationForm(user=request.user) return render_to_response('notifications/edit.html', locals(), context_instance=RequestContext(request))