def dl_edit(request,dl_id=None): """ Create or edit an existing dynamic list in a single view. A bit verbose, but better than using two view functions for similar tasks. """ dlist = get_object_or_404(DynamicList,pk=dl_id) if dl_id else None if request.POST: form = DynamicListForm(request.POST or None, instance=dlist) if form.is_valid(): list = form.save(commit=False) list.dl_name = form.cleaned_data['dl_name'] list.description = sanitizeHtml(form.cleaned_data['description']) list.created_by = request.user if not list.created_date: list.created_date = datetime.now() list.modified_date = datetime.now() list.save() form.save_m2m() messages.success(request, "%s was changed." % list.dl_name) return HttpResponseRedirect(reverse('dynamic_lists')) # Handle both bound and unbound forms else: try: dlist form = DynamicListForm(instance=dlist) except: form = DynamicListForm() return render_to_response('worlds/dl_edit.html', locals(), context_instance=RequestContext(request))
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))
def dl_edit(request, dl_id=None): """ Create or edit an existing dynamic list in a single view. A bit verbose, but better than using two view functions for similar tasks. """ dlist = get_object_or_404(DynamicList, pk=dl_id) if dl_id else None if request.POST: form = DynamicListForm(request.POST or None, instance=dlist) if form.is_valid(): list = form.save(commit=False) list.dl_name = form.cleaned_data['dl_name'] list.description = sanitizeHtml(form.cleaned_data['description']) list.created_by = request.user if not list.created_date: list.created_date = datetime.now() list.modified_date = datetime.now() list.save() form.save_m2m() messages.success(request, "%s was changed." % list.dl_name) return HttpResponseRedirect(reverse('dynamic_lists')) # Handle both bound and unbound forms else: try: dlist form = DynamicListForm(instance=dlist) except: form = DynamicListForm() return render_to_response('worlds/dl_edit.html', locals(), context_instance=RequestContext(request))