Simplify list book and supplies view

This commit is contained in:
Gabriel Augendre 2018-06-02 18:21:04 +02:00
parent 7276b8eedc
commit 0a93b93a7e
2 changed files with 4 additions and 14 deletions

View file

@ -58,7 +58,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for book in books %} {% for book in teacher.book_set.all %}
<tr> <tr>
{% if not teacher.has_confirmed_list %} {% if not teacher.has_confirmed_list %}
<th scope="row"> <th scope="row">
@ -115,7 +115,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for supply in supplies %} {% for supply in teacher.suppliesrequirement_set.all %}
<tr> <tr>
{% if not teacher.has_confirmed_list %} {% if not teacher.has_confirmed_list %}
<th scope="row"> <th scope="row">

View file

@ -2,7 +2,7 @@ from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse from django.urls import reverse
from django.views.generic import CreateView, ListView, UpdateView, DeleteView, FormView from django.views.generic import CreateView, ListView, UpdateView, DeleteView, FormView, DetailView, TemplateView
from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm from manuels.forms import AddBookForm, AddSuppliesForm, EditBookForm, EditSuppliesForm
from manuels.models import Teacher, Book, SuppliesRequirement from manuels.models import Teacher, Book, SuppliesRequirement
@ -46,18 +46,8 @@ class BaseTeacherView:
return context return context
class ListBooksView(BaseTeacherView, ListView): class ListBooksView(BaseTeacherView, TemplateView):
model = Book
template_name = 'manuels/list_books_supplies.html' template_name = 'manuels/list_books_supplies.html'
context_object_name = 'books'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['supplies'] = SuppliesRequirement.objects.filter(teacher=self.teacher)
return context
def get_queryset(self):
return Book.objects.filter(teacher=self.teacher)
class ItemView(BaseTeacherView): class ItemView(BaseTeacherView):