-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeneric_views.py
29 lines (26 loc) · 1.01 KB
/
generic_views.py
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
from django.views.generic import ListView
from note.models import Note, Tag
from note.views import getDistinctUserTags
from django.http import JsonResponse
class HomePage(ListView):
template_name = "base/home_page.html"
model = Note
def get_queryset(self):
queryset = super(HomePage, self).get_queryset()
if self.request.user.is_authenticated:
user = self.request.user
queryset = Note.objects.filter(user_id=user.id)
else:
queryset = Note.objects.none()
return queryset
def get_context_data(self, **kwargs):
context = super(HomePage, self).get_context_data(**kwargs)
# json_serializer = serializers.get_serializer("json")()
if self.request.user.is_authenticated:
tagList = ""
tags = getDistinctUserTags(self.request)
for q in tags:
tagList+=q.name+","
context['tagList']=tagList[:len(tagList)-1]
context['tags'] = tags
return context