Skip to content
This repository was archived by the owner on May 23, 2020. It is now read-only.

Commit d0d3c1a

Browse files
committed
fixed trending posts by week & removed pkg-resources
1 parent a2191b0 commit d0d3c1a

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### v.3.8
2+
* Fixed trending posts by week.
3+
* Removed pkg-resources
4+
15
### v.3.7
26
* Added feature blog post json format: `<post_url>/?format=json`
37

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
Django-Blog-Python-Learning
22
-------
33

4-
Release Source Code of Django Blog Python Learning v.3.7
4+
Release Source Code of Django Blog Python Learning v.3.8
55

66
### Demo:
77
- [https://python.web.id](https://python.web.id)
88

9+
### Technologies
10+
11+
- Django 1.10
12+
- Python 3.5
13+
- Postgresql
14+
915
### Features
1016

1117
- Django Suit

blog/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,21 @@ def get_queryset(self):
292292
.values('post').annotate(visit=Count('post__id'))\
293293
.order_by('-visit')
294294

295-
list_pk_top_posts = [pk['post'] for pk in top_posts[:20]] # Return 20 posts only
295+
list_pk_top_posts = [pk['post'] for pk in top_posts]
296296
filter_posts = list(Post.objects.published().filter(pk__in=list_pk_top_posts))
297297
sorted_posts = sorted(filter_posts, key=lambda i: list_pk_top_posts.index(i.pk))
298298

299299
self.get_filter = self.request.GET.get('filter')
300300
now_year = time.strftime("%Y")
301301
now_month = time.strftime("%m")
302302
now_date = datetime.date.today()
303-
start_week = now_date - datetime.timedelta(now_date.weekday())
303+
start_week = now_date - datetime.timedelta(7)
304304
end_week = start_week + datetime.timedelta(7)
305305

306306
if self.get_filter == 'week':
307307
filter_posts = list(Post.objects.published()
308308
.filter(pk__in=list_pk_top_posts)
309-
.filter(created__range=[start_week, end_week])
309+
.filter(created__date__range=[start_week, end_week])
310310
)
311311
sorted_posts = sorted(filter_posts, key=lambda i: list_pk_top_posts.index(i.pk))
312312

@@ -328,7 +328,7 @@ def get_queryset(self):
328328
else:
329329
self.get_filter == 'global'
330330
sorted_posts = sorted_posts
331-
return sorted_posts
331+
return sorted_posts[:20] # Return 20 posts only
332332

333333
def get_context_data(self, **kwargs):
334334
context_data = super(TrendingPostsView, self).get_context_data(**kwargs)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ django-wysiwyg-redactor==0.4.9.1
88
mock==2.0.0
99
pbr==1.10.0
1010
Pillow==3.3.1
11-
pkg-resources==0.0.0
1211
psycopg2==2.6.2
1312
pytz==2016.6.1
1413
six==1.10.0

0 commit comments

Comments
 (0)