def add_new(request, nparent=None, form_class=None, success_url=None, template_name='convo/add_new.html', extra_context=None): """ Create a new Entry """ if form_class is None: form_class = Convo.getForm(request.user) if success_url is None: success_url = "/" if request.method == 'POST': form = form_class(data=request.POST) if form.is_valid(): en = form.save(commit=False) if request.user.is_authenticated(): en.owner = request.user en.parent = nparent if nparent is None: en.original = None else: if nparent.original is None: en.original = nparent else: en.original = nparent.original en.save() return HttpResponseRedirect(success_url) else: form = form_class() if nparent is None: action_url = reverse('add_new_convo_entry') else: action_url = reverse('add_child_convo_entry', kwargs={"parent_id":nparent.id}) context = getContext(request, extra_context) return render_to_response(template_name, { 'form': form, "action_url" : action_url }, context_instance=context)
def edit_entry(request, e_id, form_class=None, success_url=None, template_name='convo/edit.html', extra_context = None): """ Edit an Entry """ e = Entry.objects.get(pk=e_id) if e.userCanEdit(request.user): if form_class is None: form_class = Convo.getForm(request.user) if success_url is None: success_url = "/" if request.method == 'POST': # have to check if e is published here before e gets its update from the form addEdit = e.published form = form_class(data=request.POST, instance=e) if form.is_valid(): en = form.save() if addEdit: edit = Edit() edit.entry = en edit.edit_by = request.user edit.save() return HttpResponseRedirect(success_url) else: form = form_class(instance=e) context = getContext(request, extra_context) return render_to_response(template_name, { 'form': form, 'e' : e, }, context_instance=context) else: return HttpResponseRedirect("/")