示例#1
0
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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
文件: aca.py 项目: dansalmo/new-aca
 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
示例#5
0
 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
示例#6
0
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))
示例#7
0
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))
示例#8
0
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)
示例#9
0
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)