From 2659ef4b33a411a2451036975a306bb294400a71 Mon Sep 17 00:00:00 2001 From: Patrick Mayr Date: Fri, 8 Apr 2022 21:21:01 +0000 Subject: [PATCH] simplify posts --- fet2020/posts/models.py | 40 ++----------------- fet2020/posts/views.py | 23 +---------- .../posts/partials/_article_row.html | 2 +- .../templates/posts/partials/_date_box.html | 2 +- .../posts/partials/_meeting_row.html | 2 +- .../templates/posts/partials/_posts_hero.html | 4 +- .../posts/partials/_posts_hero_compact.html | 2 +- .../posts/partials/_posts_pinned.html | 4 +- 8 files changed, 12 insertions(+), 67 deletions(-) diff --git a/fet2020/posts/models.py b/fet2020/posts/models.py index 809b3275..4a87ffcf 100644 --- a/fet2020/posts/models.py +++ b/fet2020/posts/models.py @@ -136,13 +136,8 @@ class Post(models.Model): self.title, ) - @property - def url(self): - # TODO: replace with get_absolute_url - return reverse("posts:posts.show", kwargs={"id": self.slug}) - def get_absolute_url(self): - return self.url + return reverse("posts:posts.show", kwargs={"id": self.slug}) def save(self, *args, **kwargs): # save the post with some defaults @@ -221,36 +216,9 @@ class Post(models.Model): return None return create_pad_for_post(self.slug, "protocol") - def get_tags(self): - """ - Returns assigned tags as a comma seperated list. - """ - return ",".join(self.tags.names()) - - @property - def get_tagnames(self): - return ["#%s" % t for t in self.tags.names()] - - @property - def tag_string(self): - return self.get_tags() - @property def three_tag_names(self): - tag_lst = [] - count = 0 - - for t in self.tags.names(): - tag_lst.append(t) - count += 1 - if count > 2: - break - - return tag_lst - - @property - def tag_names(self): - return [t for t in self.tags.names()] + return self.tags.names()[:3] @property def imageurl(self): @@ -260,6 +228,7 @@ class Post(models.Model): if self.image: return self.image.url + # return default image return settings.STATIC_URL + "img/FET-Logo-2014-quadrat.png" def clean(self): @@ -269,7 +238,6 @@ class Post(models.Model): raise ValidationError( _("Für diesen Post Typ ist kein Event Start zulässig") ) - super().clean() @property def published(self): @@ -320,7 +288,6 @@ class Event(Post): def clean(self): if not self.event_start: raise ValidationError(_("Das Datum des Events fehlt.")) - super().clean() class FetMeeting(Event): @@ -374,7 +341,6 @@ class FetMeeting(Event): return slug def clean(self): - super().clean() if not self.slug: self.slug = self.__get_slug() diff --git a/fet2020/posts/views.py b/fet2020/posts/views.py index 9bdf536d..a70c4604 100644 --- a/fet2020/posts/views.py +++ b/fet2020/posts/views.py @@ -1,8 +1,6 @@ import logging from collections import deque -from taggit.models import Tag - from django.conf import settings from django.contrib import messages from django.http import HttpResponse, Http404 @@ -24,7 +22,6 @@ logger = logging.getLogger(__name__) def index(request): posts = None - taglist = None compact_view = None fet_meeting_only = None @@ -78,21 +75,17 @@ def index(request): year = None data = { - 'year': year, + "year": year, } form = PostSearchForm(data) posts = Post.objects.date_filtered_list(public_only, data["year"]) - if posts: - taglist = map(lambda post: post.tags, posts) - context = { "formset": form, "compact_view": compact_view, "fet_meeting_only": fet_meeting_only, "posts": posts, - "tags_list": taglist, } return render(request, "posts/index.html", context) @@ -118,23 +111,9 @@ def tags(request, tag=""): public_only = not request.user.is_authenticated posts = Post.objects.published(public_only).filter(tags__name=tag) - featured_post = Post.objects.published(public_only).filter(slug=tag).first() - - job_members = JobMember.active_member.get_all_by_slug(slug=tag) - - author_image = None - if featured_post: - post_author = Member.all_members.filter(nickname=featured_post.author).first() - - if post_author: - author_image = post_author.image["avatar"].url context = { "posts": posts, - "author_image": author_image, - "featured_post": featured_post, - "job_members": job_members, - "tags_list": None, "tag": tag, } diff --git a/fet2020/templates/posts/partials/_article_row.html b/fet2020/templates/posts/partials/_article_row.html index 706337a7..338471e9 100644 --- a/fet2020/templates/posts/partials/_article_row.html +++ b/fet2020/templates/posts/partials/_article_row.html @@ -1,4 +1,4 @@ - +

{{ post.title }}

diff --git a/fet2020/templates/posts/partials/_date_box.html b/fet2020/templates/posts/partials/_date_box.html index 28023bb0..0068eadd 100644 --- a/fet2020/templates/posts/partials/_date_box.html +++ b/fet2020/templates/posts/partials/_date_box.html @@ -1,4 +1,4 @@ - +

{{ post.event_start|date:"d" }} {{ post.event_start|date:"M" }} diff --git a/fet2020/templates/posts/partials/_meeting_row.html b/fet2020/templates/posts/partials/_meeting_row.html index 9683db44..fff37675 100644 --- a/fet2020/templates/posts/partials/_meeting_row.html +++ b/fet2020/templates/posts/partials/_meeting_row.html @@ -1,5 +1,5 @@