MCPcopy Create free account
hub / github.com/codemistic/Web-Development / index

Function index

locallibrary/catalog/views.py:12–38  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

10
11@api_view(['GET'])
12def index(request):
13
14 # Generate counts of some of the main objects
15 num_books = Book.objects.all().count()
16
17 num_instances = BookInstance.objects.all().count()
18 # Available books (status = 'a')
19 num_instances_available = BookInstance.objects.filter(
20 status__exact='Available').count()
21
22 # # The 'all()' is implied by default.
23 num_authors = Author.objects.count()
24
25 # Numbwe of visits to this view
26 num_visits = request.session.get('num_visits', 0)
27 request.session['num_visits'] = num_visits + 1
28
29 context = {
30 'num_books': num_books,
31 'num_instances': num_instances,
32 'num_instances_available': num_instances_available,
33 'num_authors': num_authors,
34 'num_visits': num_visits,
35 }
36
37 # Render the HTML template index.html with the data in the context variable
38 return Response(context)
39
40
41@api_view(['GET'])

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected