posts sorted by public date or event start depend on post type
This commit is contained in:
@@ -6,7 +6,7 @@ from posts.models import Post, FetMeeting, Event
|
||||
|
||||
|
||||
def index(request):
|
||||
posts = deque(Post.articles.get_visible_articles())
|
||||
posts = deque(Post.articles.get_date_sorted_list())
|
||||
posts_for_tags = deque(Post.objects.get_last_months_posts())
|
||||
|
||||
def get_tags(lst):
|
||||
|
||||
@@ -12,6 +12,19 @@ class PostManager(models.Manager):
|
||||
def get_visible_articles(self):
|
||||
return self.get_queryset().filter(is_hidden=False)
|
||||
|
||||
def get_date_sorted_list(self):
|
||||
post_list = []
|
||||
for post in self.get_visible_articles():
|
||||
if post.post_type != "N":
|
||||
post_list.append((post, post.event_start.date()))
|
||||
else:
|
||||
post_list.append((post, post.public_date))
|
||||
|
||||
result = sorted(post_list, key=lambda x: x[1], reverse=True)
|
||||
posts = [x[0] for x in result]
|
||||
|
||||
return posts
|
||||
|
||||
def get_last_months_posts(self):
|
||||
date_today = timezone.now().date()
|
||||
return self.get_visible_articles().filter(
|
||||
@@ -43,6 +56,19 @@ class ArticleManager(models.Manager):
|
||||
def get_visible_articles(self):
|
||||
return self.get_queryset().filter(is_hidden=False)
|
||||
|
||||
def get_date_sorted_list(self):
|
||||
post_list = []
|
||||
for post in self.get_visible_articles():
|
||||
if post.post_type != "N":
|
||||
post_list.append((post, post.event_start.date()))
|
||||
else:
|
||||
post_list.append((post, post.public_date))
|
||||
|
||||
result = sorted(post_list, key=lambda x: x[1], reverse=True)
|
||||
posts = [x[0] for x in result]
|
||||
|
||||
return posts
|
||||
|
||||
def get_pinned_article(self):
|
||||
return self.get_visible_articles().filter(is_pinned=True).first()
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def index(request):
|
||||
"Index von aktuellen Posts"
|
||||
posts = deque(Post.objects.get_visible_articles().order_by("-public_date"))
|
||||
posts = deque(Post.objects.get_date_sorted_list())
|
||||
|
||||
taglist = map(lambda post: post.tags, posts)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user