Ejemplo n.º 1
0
def createGutenberg(request):
    """Allows the user to automatically look up a book's details when
    given the HTML address from gutenberg.org"""

    if request.method == "POST":
        form = BookForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            Book.objects.create(title=data['title'],
                                author_first=data['author_first'],
                                author_last=data['author_last'],
                                description=data['description'],
                                URL=data['URL'],
                                language=data['language'].title(),
                                sort_title=get_sort_title(data['title']))
            return HttpResponseRedirect(reverse('all_books'))

    projectg = request.POST['projectg']
    (new_title, new_author_first, new_author_last, _, new_language,
     new_description) = scrap_html(projectg)

    form = BookForm(
        initial={
            'title': new_title,
            'author_first': new_author_first,
            'author_last': new_author_last,
            'description': new_description,
            'URL': projectg,
            'language': new_language,
        })

    return render(request, 'digital_books/book_form.html', {
        'form': form,
        'show_gutenberg': True
    })
Ejemplo n.º 2
0
def update_book(request, id):
    """Allows the user to update a specific book object"""

    if request.user.is_superuser:
        book = Book.objects.get(id=id)
        if request.method == "POST":
            form = BookForm(request.POST)
            if form.is_valid():
                data = form.cleaned_data
                book.title = data['title']
                book.author_first = data['author_first'],
                book.author_last = data['author_last'],
                book.description = data['description']
                book.URL = data['URL']
                book.language = data['language'].title()
                book.sort_title = data['sort_title']
                book.save()
                return HttpResponseRedirect(reverse('detail_book',
                                                    args=(id, )))

        form = BookForm(
            initial={
                'title': book.title,
                'author_last': book.author_last,
                'author_first': book.author_first,
                'description': book.description,
                'URL': book.URL,
                'language': book.language,
                'sort_title': book.sort_title
            })
        return render(request, 'digital_books/book_form.html', {
            'form': form,
            'show_gutenberg': True
        })
Ejemplo n.º 3
0
 def post(self, request):
     form = BookForm(request.POST)
     if form.is_valid():
         data = form.cleaned_data
         Book.objects.create(title=data['title'],
                             author_last=data['author_last'],
                             author_first=data['author_first'],
                             description=data['description'],
                             URL=data['URL'],
                             language=data['language'].title(),
                             sort_title=get_sort_title(data['title']))
         return HttpResponseRedirect(reverse('all_books'))
Ejemplo n.º 4
0
 def get(self, request):
     if request.user.is_librarian is False:
         return HttpResponseRedirect(reverse('all_books'))
     form = BookForm()
     return render(request, 'digital_books/book_form.html', {'form': form})