Skip to content

Commit

Permalink
Update views.py - restore order
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee authored Nov 6, 2023
1 parent 41c47e9 commit 2103afd
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions catalog/views.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
from .models import Author
from django.urls import reverse_lazy
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from catalog.forms import RenewBookForm
from django.contrib.auth.decorators import login_required, permission_required
import datetime
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views import generic
from django.shortcuts import render

# Create your views here.

from .models import Book, Author, BookInstance, Genre, Language


def index(request):
"""View function for home page of site."""
# Generate counts of some of the main objects
Expand All @@ -41,6 +28,8 @@ def index(request):
)


from django.views import generic

class BookListView(generic.ListView):
"""Generic class-based view for a list of books."""
model = Book
Expand Down Expand Up @@ -95,6 +84,7 @@ class BookInstanceDetailView(generic.DetailView):
"""Generic class-based detail view for a book."""
model = BookInstance

from django.contrib.auth.mixins import LoginRequiredMixin

class LoanedBooksByUserListView(LoginRequiredMixin, generic.ListView):
"""Generic class-based view listing books on loan to current user."""
Expand All @@ -111,7 +101,7 @@ def get_queryset(self):


# Added as part of challenge!

from django.contrib.auth.mixins import PermissionRequiredMixin

class LoanedBooksAllListView(PermissionRequiredMixin, generic.ListView):
"""Generic class-based view listing all books on loan. Only visible to users with can_mark_returned permission."""
Expand All @@ -124,8 +114,12 @@ def get_queryset(self):
return BookInstance.objects.filter(status__exact='o').order_by('due_back')


# from .forms import RenewBookForm

from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
import datetime
from django.contrib.auth.decorators import login_required, permission_required
from catalog.forms import RenewBookForm

@login_required
@permission_required('catalog.can_mark_returned', raise_exception=True)
Expand Down Expand Up @@ -161,6 +155,10 @@ def renew_book_librarian(request, pk):
return render(request, 'catalog/book_renew_librarian.html', context)


from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.urls import reverse_lazy
from .models import Author

class AuthorCreate(PermissionRequiredMixin, CreateView):
model = Author
fields = ['first_name', 'last_name', 'date_of_birth', 'date_of_death']
Expand Down

0 comments on commit 2103afd

Please sign in to comment.