class SeriesList(generic.ListView): template_name = StaticTemplates.view( BookConstants.series_list_template_name) context_object_name = BookConstants.series_context_name def get_queryset(self): return BookSeries.objects.all().order_by(Constants.title)
class SearchEverything(generic.ListView): template_name = StaticTemplates.view(BookConstants.series_template_name) context_object_name = Constants.data_context_name def get_queryset(self): search_string = self.request.GET.get('search') or '-created' # query_string = super(SearchEverything, self).get_queryset() books = Book.objects.filter(title__contains=search_string) authors = BookAuthor.objects.filter(name__contains=search_string) series = BookSeries.objects.filter(title__contains=search_string) data = { 'books': books, 'authors': authors, 'series': series, 'search_text': search_string } return data
def post(self, request): form = self.form_class(request.POST) if form.is_valid(): review = form.save(commit=False) review.reviewer = request.user review.book = form.cleaned_data['book'] print(review) review.save() else: print(request.user) print('error in form') test_template = StaticTemplates.view(Constants.test_template_name) return render(request, test_template, {'errors': form.errors}) return redirect('books:detail', slug=form.cleaned_data['book'].slug)
class BookUpload(View): form_class = UploadForm template_name = StaticTemplates.create(Constants.upload_template_name) def get(self, request): form = self.form_class(None) return render(request, self.template_name, {'form': form}) def post(self, request): form = self.form_class(request.POST, request.FILES) if form.is_valid(): upload = form.save(commit=False) upload.uploader = request.user upload.save() return render(request, self.template_name, {'form': form})
from django.http import JsonResponse from django.shortcuts import render, redirect from django.views import generic from django.views.generic import View from django.views.generic.base import TemplateView from django.views.generic.edit import CreateView, UpdateView, DeleteView from django_countries.widgets import CountrySelectWidget import json from .models import Brand, Wrestler, Championship, Event, Match, TagTeamMatch, MatchType, TagTeam, ChampionshipHistory, \ DraftHistory, TemporaryDraft from .forms import MatchForm, ChampionshipForm, TagTeamForm, TagMatchForm from common.constants import Constants, TemplateConstants, WweConstants from common.helper import Helper, StaticTemplates static_templates = StaticTemplates(WweConstants.app_name) class IndexView(TemplateView): template_name = static_templates.view( TemplateConstants.index_template_name) class BrandsView(generic.ListView): template_name = static_templates.view( TemplateConstants.brands_template_name) context_object_name = WweConstants.brands_context_name def get_queryset(self): return Brand.objects.order_by(Constants.created_at)
class SeriesCreate(CreateView): model = BookSeries fields = BookSeries.db_fields() template_name = StaticTemplates.create(BookConstants.series_template_name)
class SeriesView(generic.DetailView): model = BookSeries template_name = StaticTemplates.view(BookConstants.series_template_name)
class BookUpdate(UpdateView): model = Book template_name = StaticTemplates.update(BookConstants.book_template_name) fields = Book.db_fields()
class BookCreate(CreateView): form_class = BookForm template_name = StaticTemplates.create(BookConstants.book_template_name)
class BookView(generic.DetailView): model = Book template_name = StaticTemplates.view(BookConstants.book_template_name)
class IndexView(generic.ListView): template_name = StaticTemplates.view(Constants.index_template_name) context_object_name = BookConstants.books_context_name def get_queryset(self): return Book.objects.all().order_by(Constants.title)
class AuthorCreate(CreateView): model = BookAuthor fields = BookAuthor.db_fields() widgets = {'country': CountrySelectWidget()} template_name = StaticTemplates.create(BookConstants.author_template_name)
class AuthorView(generic.DetailView): model = BookAuthor template_name = StaticTemplates.view(BookConstants.author_template_name)
class AuthorsView(generic.ListView): template_name = StaticTemplates.view(BookConstants.authors_template_name) context_object_name = BookConstants.author_context_name def get_queryset(self): return BookAuthor.objects.all().order_by(Constants.name)