-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_processors.py
More file actions
32 lines (24 loc) · 1.26 KB
/
Copy pathcontext_processors.py
File metadata and controls
32 lines (24 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from .models import Category, ProfileCategory, ProfileAuthor, ProfileBook
def simple_book_store_processor(request):
categories = Category.objects.all()
values = {
'notifications': [],
'categories': categories,
'profile_categories': [],
'profile_authors': [],
'profile_books': {
1: 0,
2: 0,
3: 0
},
}
if request.user.is_authenticated:
profile_categories = ProfileCategory.objects.filter(profile=request.user.profile, status=1)
profile_authors = ProfileAuthor.objects.filter(profile=request.user.profile, status=1)
values["profile_categories"] = [v['category_id'] for v in profile_categories.values() if 'category_id' in v]
values["profile_authors"] = [v['author_id'] for v in profile_authors.values() if 'author_id' in v]
values['profile_books'][1] = ProfileBook.objects.filter(profile=request.user.profile, status=1).count()
values['profile_books'][2] = ProfileBook.objects.filter(profile=request.user.profile, status=2).count()
values['profile_books'][3] = ProfileBook.objects.filter(profile=request.user.profile, status=3).count()
values["notifications"] = request.user.received_notifications.all()
return values