added benchmarking
This commit is contained in:
		@@ -10,19 +10,20 @@ urlpatterns = [
 | 
			
		||||
    path('ratings/', views.RatingListView.as_view(), name='ratings'),
 | 
			
		||||
    path('tags/', views.TagListView.as_view(), name='tags'),
 | 
			
		||||
    path('series/', views.SeriesListView.as_view(), name='series'),
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    path('author/<int:pk>', views.AuthorDetailView.as_view(), name='author-detail-view'),
 | 
			
		||||
    path('author/<int:pk>', views.AuthorDetailView.as_view(),
 | 
			
		||||
         name='author-detail-view'),
 | 
			
		||||
    path('book/<int:pk>', views.BookDetailView.as_view(), name='book-detail-view'),
 | 
			
		||||
    path('publisher/<int:pk>', views.PublisherDetailView.as_view(), name='publisher-detail-view'),
 | 
			
		||||
    path('rating/<int:pk>', views.RatingDetailView.as_view(), name='rating-detail-view'),
 | 
			
		||||
    path('series/<int:pk>', views.SeriesDetailView.as_view(), name='series-detail-view'),
 | 
			
		||||
    path('publisher/<int:pk>', views.PublisherDetailView.as_view(),
 | 
			
		||||
         name='publisher-detail-view'),
 | 
			
		||||
    path('rating/<int:pk>', views.RatingDetailView.as_view(),
 | 
			
		||||
         name='rating-detail-view'),
 | 
			
		||||
    path('series/<int:pk>', views.SeriesDetailView.as_view(),
 | 
			
		||||
         name='series-detail-view'),
 | 
			
		||||
    path('tag/<int:pk>', views.TagDetailView.as_view(), name='tag-detail-view'),
 | 
			
		||||
 | 
			
		||||
    path('results/', views.ResultsView.as_view(), name='results'),
 | 
			
		||||
    path('search/', views.SearchView.as_view(), name='search'),
 | 
			
		||||
 | 
			
		||||
    path('accounts/sign_up/',views.sign_up,name="sign-up")
 | 
			
		||||
    path('accounts/sign_up/', views.sign_up, name="sign-up")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
]
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,9 @@ from django.contrib.auth import login
 | 
			
		||||
from django.contrib.auth.decorators import login_required
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# might be helpful for vary headers later
 | 
			
		||||
from django.utils.decorators import method_decorator
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def index(request):
 | 
			
		||||
@@ -31,6 +34,9 @@ def sign_up(request):
 | 
			
		||||
class SearchView(generic.TemplateView):
 | 
			
		||||
    template_name = 'search.html'
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(SearchView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ResultsView(generic.ListView):  # no clue if this is secure.
 | 
			
		||||
    # according to this https://stackoverflow.com/questions/13574043/how-do-django-forms-sanitize-text-input-to-prevent-sql-injection-xss-etc
 | 
			
		||||
@@ -38,6 +44,9 @@ class ResultsView(generic.ListView):  # no clue if this is secure.
 | 
			
		||||
    model = Book
 | 
			
		||||
    template_name = 'results.html'
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(ResultsView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self):  # new
 | 
			
		||||
        title = self.request.GET.get('title')
 | 
			
		||||
        author = self.request.GET.get('author')
 | 
			
		||||
@@ -52,8 +61,8 @@ class ResultsView(generic.ListView):  # no clue if this is secure.
 | 
			
		||||
            books = books.filter(identifier__val=identifier)
 | 
			
		||||
        if generic:
 | 
			
		||||
            books = books.filter(
 | 
			
		||||
                Q(sort__icontains=generic) | 
 | 
			
		||||
                Q(author_sort__icontains=generic) | 
 | 
			
		||||
                Q(sort__icontains=generic) |
 | 
			
		||||
                Q(author_sort__icontains=generic) |
 | 
			
		||||
                Q(identifier__val=generic)
 | 
			
		||||
            )
 | 
			
		||||
        return books
 | 
			
		||||
@@ -62,10 +71,16 @@ class ResultsView(generic.ListView):  # no clue if this is secure.
 | 
			
		||||
class AuthorListView(generic.ListView):
 | 
			
		||||
    model = Author
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(AuthorListView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BookListView(generic.ListView):
 | 
			
		||||
    model = Book
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(BookListView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self):
 | 
			
		||||
        # Annotate the books with ratings, tags, etc
 | 
			
		||||
        # books = Book.objects.annotate(
 | 
			
		||||
@@ -76,21 +91,37 @@ class BookListView(generic.ListView):
 | 
			
		||||
class PublisherListView(generic.ListView):
 | 
			
		||||
    model = Publisher
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(PublisherListView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RatingListView(generic.ListView):
 | 
			
		||||
    model = Rating
 | 
			
		||||
 | 
			
		||||
class SeriesListView(generic.ListView): # make url entry and template, sometime
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(RatingListView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SeriesListView(generic.ListView):  # make url entry and template, sometime
 | 
			
		||||
    model = Series
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(SeriesListView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TagListView(generic.ListView):
 | 
			
		||||
    model = Tag
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(TagListView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AuthorDetailView(generic.DetailView):
 | 
			
		||||
    model = Author
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(AuthorDetailView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, **kwargs):
 | 
			
		||||
        # Call the base implementation first to get the context
 | 
			
		||||
        context = super(AuthorDetailView, self).get_context_data(**kwargs)
 | 
			
		||||
@@ -104,6 +135,9 @@ class AuthorDetailView(generic.DetailView):
 | 
			
		||||
class BookDetailView(generic.DetailView):
 | 
			
		||||
    model = Book
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(BookDetailView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, **kwargs):
 | 
			
		||||
        # Call the base implementation first to get the context
 | 
			
		||||
        context = super(BookDetailView, self).get_context_data(**kwargs)
 | 
			
		||||
@@ -122,6 +156,9 @@ class BookDetailView(generic.DetailView):
 | 
			
		||||
class PublisherDetailView(generic.DetailView):
 | 
			
		||||
    model = Publisher
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(PublisherDetailView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, **kwargs):
 | 
			
		||||
        # Call the base implementation first to get the context
 | 
			
		||||
        context = super(PublisherDetailView, self).get_context_data(**kwargs)
 | 
			
		||||
@@ -135,6 +172,9 @@ class PublisherDetailView(generic.DetailView):
 | 
			
		||||
class RatingDetailView(generic.DetailView):
 | 
			
		||||
    model = Rating
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(RatingDetailView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, **kwargs):
 | 
			
		||||
        # Call the base implementation first to get the context
 | 
			
		||||
        context = super(RatingDetailView, self).get_context_data(**kwargs)
 | 
			
		||||
@@ -148,6 +188,9 @@ class RatingDetailView(generic.DetailView):
 | 
			
		||||
class TagDetailView(generic.DetailView):
 | 
			
		||||
    model = Tag
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(TagDetailView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, **kwargs):
 | 
			
		||||
        # Call the base implementation first to get the context
 | 
			
		||||
        context = super(TagDetailView, self).get_context_data(**kwargs)
 | 
			
		||||
@@ -157,9 +200,13 @@ class TagDetailView(generic.DetailView):
 | 
			
		||||
        context['books'] = sorted(books,  key=lambda x: x.title)
 | 
			
		||||
        return context
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SeriesDetailView(generic.DetailView):
 | 
			
		||||
    model = Series
 | 
			
		||||
 | 
			
		||||
    def dispatch(self, *args, **kwargs):
 | 
			
		||||
        return super(SeriesDetailView, self).dispatch(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, **kwargs):
 | 
			
		||||
        # Call the base implementation first to get the context
 | 
			
		||||
        context = super(SeriesDetailView, self).get_context_data(**kwargs)
 | 
			
		||||
@@ -167,4 +214,4 @@ class SeriesDetailView(generic.DetailView):
 | 
			
		||||
        books = Book.objects.prefetch_related("tags", "ratings")
 | 
			
		||||
        books = books.filter(series=context["object"].id)
 | 
			
		||||
        context['books'] = sorted(books,  key=lambda x: x.title)
 | 
			
		||||
        return context
 | 
			
		||||
        return context
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user