def author_add(request): if request.method == "POST": form = AuthorForm(request.POST) if form.is_valid(): form.save() return render_to_response("common/success.html") else: form = AuthorForm() variables = RequestContext(request, {"form": form}) return render_to_response("crud/author/author_add.html", variables)
def author_add(request): if request.method == 'POST': form = AuthorForm(request.POST) if form.is_valid(): form.save() return render_to_response('common/success.html') else: form = AuthorForm() variables = RequestContext(request, { 'form': form }) return render_to_response('crud/author/author_add.html', variables)
def author_edit(request, id): author = Author.objects.get(pk=id) if request.method == "POST": form = AuthorForm(request.POST, instance=author) if form.is_valid(): form.save() return render_to_response("common/success.html") else: form = AuthorForm(instance=author) variables = RequestContext(request, {"form": form}) return render_to_response("crud/author/author_edit.html", variables)
def _copyAuthorToForm(self, author): """Copy relevant fields from Author to AuthorForm.""" af = AuthorForm() for field in af.all_fields(): if hasattr(author, field.name): # convert view string to Enum if field.name == 'userRights': setattr(af, field.name, getattr(UserRights, str(getattr(author, field.name)))) else: setattr(af, field.name, getattr(author, field.name)) elif field.name == "websafeAuthorKey": setattr(af, field.name, author.key.urlsafe()) af.check_initialized() return af
def _copyAuthorToForm(self, author): """Copy relevant fields from Author to AuthorForm.""" af = AuthorForm() for field in af.all_fields(): if hasattr(author, field.name): # convert view string to Enum if field.name == 'userRights': setattr( af, field.name, getattr(UserRights, str(getattr(author, field.name)))) else: setattr(af, field.name, getattr(author, field.name)) elif field.name == "websafeAuthorKey": setattr(af, field.name, author.key.urlsafe()) af.check_initialized() return af
def author_manager(request, author): BookInlineFormSet = inlineformset_factory(Author, Book, extra=1, formfield_callback=add_category) form = AuthorForm(request.POST or None, instance=author) formset = BookInlineFormSet(request.POST or None, instance=author) if form.is_valid() and formset.is_valid(): form.save() formset.save() return HttpResponseRedirect('/inlines/') return render_to_response("manage_authors.html", {"formset": formset, "form": form}, RequestContext(request))
def author_manager(request, author): BookInlineFormSet = inlineformset_factory(Author, Book, extra=1, formfield_callback=add_category) form = AuthorForm(request.POST or None, instance=author) formset = BookInlineFormSet(request.POST or None, instance=author) if form.is_valid() and formset.is_valid(): form.save() formset.save() return HttpResponseRedirect('/inlines/') return render_to_response("manage_authors.html", { "formset": formset, "form": form }, RequestContext(request))
def author_add(request): if request.method == 'POST': form = AuthorForm(request.POST) if form.is_valid(): form.save() return render_to_response('common/success.html') else: form = AuthorForm() variables = RequestContext(request, {'form': form}) return render_to_response('crud/author/author_add.html', variables)
def author_edit(request, id): author = Author.objects.get(pk=id) if request.method == "POST": form = AuthorForm(request.POST, instance=author) if form.is_valid(): form.save() return render_to_response('common/success.html') else: form = AuthorForm(instance=author) variables = RequestContext(request, {'form': form}) return render_to_response("crud/author/author_edit.html", variables)