-
Notifications
You must be signed in to change notification settings - Fork 2
/
views.py
123 lines (101 loc) · 4.84 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from django.views.generic import ListView,TemplateView,DetailView
from .models import Post,Category,Love,Skills,IpController,Tags
from django.shortcuts import get_list_or_404
class HomeListView(ListView):
"""Ana Sayfa"""
model = Post
queryset = Post.objects.all().filter(is_active=True).order_by('?')
context_object_name = 'post_obj'
template_name = 'home.html'
paginate_by = 5
def get_context_data(self, **kwargs):
context = super(HomeListView, self).get_context_data(**kwargs)
context['last_content'] = Post.objects.all().filter(is_active=True).order_by('-time')
return context
class PostDetailView(DetailView):
"""Post detay sayfası"""
model = Post
template_name = 'post.html'
context_object_name = 'post_obj'
slug_field = 'url'
def get_context_data(self, **kwargs):
tags = []
post_tags = []
posts_tags = []
context = super(PostDetailView, self).get_context_data(**kwargs)
context['last_content'] = Post.objects.all().filter(is_active=True).order_by('-time')[:5]
context['category'] = Category.objects.all()
context['post'] = Post.objects.all().filter(is_active=True).order_by('-site_hit')[:5]
ip = IpController.objects.all().filter(remote=str(self.request.META.get('REMOTE_ADDR')),
http_x=str(self.request.META.get('HTTP_X_FORWARDED_FOR')),
http_user=str(self.request.META['HTTP_USER_AGENT']),
url=str(self.kwargs['slug']))
if(not ip):
IpController.objects.create(remote=str(self.request.META.get('REMOTE_ADDR')),
http_x=str(self.request.META.get('HTTP_X_FORWARDED_FOR')),
http_user=str(self.request.META['HTTP_USER_AGENT']),
url=str(self.kwargs['slug'])).save()
hit = Post.objects.get(url=self.kwargs['slug'])
hit.site_hit += 1
hit.save()
return context
class AboutTemplateView(TemplateView):
"""Hakkımızda"""
template_name = 'about.html'
def get_context_data(self, **kwargs):
context = super(AboutTemplateView, self).get_context_data(**kwargs)
context['last_content'] = Post.objects.all().filter(is_active=True).order_by('-time')
context['love'] = Love.objects.all()
context['skills'] = Skills.objects.all().order_by()
return context
class BlogListView(ListView):
"""Blog Listeleme"""
model = Post
queryset = Post.objects.all().filter(is_active=True).order_by('-time')
context_object_name = 'post_obj'
template_name = 'blog_list.html'
paginate_by = 5
def get_context_data(self, **kwargs):
context = super(BlogListView, self).get_context_data(**kwargs)
context['last_content'] = Post.objects.all().filter(is_active=True).order_by('-time')
context['category'] = Category.objects.all()
context['post'] = Post.objects.all().filter(is_active=True).order_by('-site_hit')[:5]
context['random_post'] = Post.objects.all().filter(is_active=True).order_by('?')
return context
class ContactView(TemplateView):
"""İletişim"""
template_name = 'contact.html'
def get_context_data(self, **kwargs):
context = super(ContactView, self).get_context_data(**kwargs)
context['last_content'] = Post.objects.all().filter(is_active=True).order_by('-time')
return context
class CategoryView(ListView):
"""Kategori Detay"""
model = Post
template_name = 'category_page.html'
context_object_name = 'post_obj'
paginate_by = 3
def get_queryset(self, *args, **kwargs):
return get_list_or_404(Post.objects.filter(category_list__url=self.kwargs['slug'],is_active=True))
def get_context_data(self, **kwargs):
context = super(CategoryView, self).get_context_data(**kwargs)
context['last_content'] = Post.objects.all().filter(is_active=True).order_by('-time')
context['category'] = Category.objects.all()
context['category_post'] = Category.objects.all().filter(url=self.kwargs['slug'])
return context
class RobotsView(TemplateView):
"""robots.txt"""
template_name = 'robots.html'
class TagsView(ListView):
"""etiket detay"""
model = Tags
context_object_name = 'tags_obj'
template_name = 'tags.html'
paginate_by = 5
def get_queryset(self):
return get_list_or_404(Tags.objects.all().filter(blog__is_active=True,tags=self.kwargs['slug']))
def get_context_data(self, **kwargs):
context = super(TagsView, self).get_context_data(**kwargs)
context['last_content'] = Post.objects.all().filter(is_active=True).order_by('-time')
context['category'] = Category.objects.all()
return context