simplify posts
This commit is contained in:
@@ -136,13 +136,8 @@ class Post(models.Model):
|
|||||||
self.title,
|
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):
|
def get_absolute_url(self):
|
||||||
return self.url
|
return reverse("posts:posts.show", kwargs={"id": self.slug})
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
# save the post with some defaults
|
# save the post with some defaults
|
||||||
@@ -221,36 +216,9 @@ class Post(models.Model):
|
|||||||
return None
|
return None
|
||||||
return create_pad_for_post(self.slug, "protocol")
|
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
|
@property
|
||||||
def three_tag_names(self):
|
def three_tag_names(self):
|
||||||
tag_lst = []
|
return self.tags.names()[:3]
|
||||||
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()]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def imageurl(self):
|
def imageurl(self):
|
||||||
@@ -260,6 +228,7 @@ class Post(models.Model):
|
|||||||
if self.image:
|
if self.image:
|
||||||
return self.image.url
|
return self.image.url
|
||||||
|
|
||||||
|
# return default image
|
||||||
return settings.STATIC_URL + "img/FET-Logo-2014-quadrat.png"
|
return settings.STATIC_URL + "img/FET-Logo-2014-quadrat.png"
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
@@ -269,7 +238,6 @@ class Post(models.Model):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Für diesen Post Typ ist kein Event Start zulässig")
|
_("Für diesen Post Typ ist kein Event Start zulässig")
|
||||||
)
|
)
|
||||||
super().clean()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def published(self):
|
def published(self):
|
||||||
@@ -320,7 +288,6 @@ class Event(Post):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
if not self.event_start:
|
if not self.event_start:
|
||||||
raise ValidationError(_("Das Datum des Events fehlt."))
|
raise ValidationError(_("Das Datum des Events fehlt."))
|
||||||
super().clean()
|
|
||||||
|
|
||||||
|
|
||||||
class FetMeeting(Event):
|
class FetMeeting(Event):
|
||||||
@@ -374,7 +341,6 @@ class FetMeeting(Event):
|
|||||||
return slug
|
return slug
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
|
||||||
if not self.slug:
|
if not self.slug:
|
||||||
self.slug = self.__get_slug()
|
self.slug = self.__get_slug()
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
from taggit.models import Tag
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.http import HttpResponse, Http404
|
from django.http import HttpResponse, Http404
|
||||||
@@ -24,7 +22,6 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
posts = None
|
posts = None
|
||||||
taglist = None
|
|
||||||
|
|
||||||
compact_view = None
|
compact_view = None
|
||||||
fet_meeting_only = None
|
fet_meeting_only = None
|
||||||
@@ -78,21 +75,17 @@ def index(request):
|
|||||||
year = None
|
year = None
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'year': year,
|
"year": year,
|
||||||
}
|
}
|
||||||
|
|
||||||
form = PostSearchForm(data)
|
form = PostSearchForm(data)
|
||||||
posts = Post.objects.date_filtered_list(public_only, data["year"])
|
posts = Post.objects.date_filtered_list(public_only, data["year"])
|
||||||
|
|
||||||
if posts:
|
|
||||||
taglist = map(lambda post: post.tags, posts)
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"formset": form,
|
"formset": form,
|
||||||
"compact_view": compact_view,
|
"compact_view": compact_view,
|
||||||
"fet_meeting_only": fet_meeting_only,
|
"fet_meeting_only": fet_meeting_only,
|
||||||
"posts": posts,
|
"posts": posts,
|
||||||
"tags_list": taglist,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, "posts/index.html", context)
|
return render(request, "posts/index.html", context)
|
||||||
@@ -118,23 +111,9 @@ def tags(request, tag=""):
|
|||||||
public_only = not request.user.is_authenticated
|
public_only = not request.user.is_authenticated
|
||||||
|
|
||||||
posts = Post.objects.published(public_only).filter(tags__name=tag)
|
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 = {
|
context = {
|
||||||
"posts": posts,
|
"posts": posts,
|
||||||
"author_image": author_image,
|
|
||||||
"featured_post": featured_post,
|
|
||||||
"job_members": job_members,
|
|
||||||
"tags_list": None,
|
|
||||||
"tag": tag,
|
"tag": tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<a href="{{ post.url }}" class="block">
|
<a href="{{ post.get_absolute_url }}" class="block">
|
||||||
<h3 class="text-gray-700 dark:text-gray-200">{{ post.title }}</h3>
|
<h3 class="text-gray-700 dark:text-gray-200">{{ post.title }}</h3>
|
||||||
<p class="my-1 text-sm text-gray-600 dark:text-gray-300">
|
<p class="my-1 text-sm text-gray-600 dark:text-gray-300">
|
||||||
<i class="fas fa-calendar-alt text-gray-500 dark:text-gray-400"></i>
|
<i class="fas fa-calendar-alt text-gray-500 dark:text-gray-400"></i>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<a href="{{ post.url }}" class="calendar-entry">
|
<a href="{{ post.get_absolute_url }}" class="calendar-entry">
|
||||||
<div class="calendar-dateBubble">
|
<div class="calendar-dateBubble">
|
||||||
<span class="dateBubble-day">{{ post.event_start|date:"d" }}</span>
|
<span class="dateBubble-day">{{ post.event_start|date:"d" }}</span>
|
||||||
<span class="dateBubble-month">{{ post.event_start|date:"M" }}</span>
|
<span class="dateBubble-month">{{ post.event_start|date:"M" }}</span>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div class="my-2">
|
<div class="my-2">
|
||||||
<a href="{{ post.url }}">
|
<a href="{{ post.get_absolute_url }}">
|
||||||
<h3 class="">{{ post.title }}</h3>
|
<h3 class="">{{ post.title }}</h3>
|
||||||
<p class="py-1 text-sm lg:text-base text-gray-600 dark:text-gray-300">
|
<p class="py-1 text-sm lg:text-base text-gray-600 dark:text-gray-300">
|
||||||
<i class="fas fa-calendar-alt text-gray-500 dark:text-gray-400"></i>
|
<i class="fas fa-calendar-alt text-gray-500 dark:text-gray-400"></i>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<article class="article-cover-image" style="background-image: url('{{ post.imageurl }}');" onclick="openArticle('{{ post.url }}')">
|
<article class="article-cover-image" style="background-image: url('{{ post.imageurl }}');" onclick="openArticle('{{ post.get_absolute_url }}')">
|
||||||
<div class="article-cover-desc">
|
<div class="article-cover-desc">
|
||||||
<div class="article-cover-desc-items">
|
<div class="article-cover-desc-items">
|
||||||
<ul class="article-cover-tags">
|
<ul class="article-cover-tags">
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ post.url }}"><h3 class="text-gray-50">{{ post.title|safe }}</h3></a>
|
<a href="{{ post.get_absolute_url }}"><h3 class="text-gray-50">{{ post.title|safe }}</h3></a>
|
||||||
<div class="text-gray-200">
|
<div class="text-gray-200">
|
||||||
<i class="fas fa-clock"></i>
|
<i class="fas fa-clock"></i>
|
||||||
{{ post.date|date:"d. F Y" }}
|
{{ post.date|date:"d. F Y" }}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<article class="bg-white dark:bg-gray-800 rounded-md shadow transition-all duration-300 hover:shadow-md transform hover:scale-105">
|
<article class="bg-white dark:bg-gray-800 rounded-md shadow transition-all duration-300 hover:shadow-md transform hover:scale-105">
|
||||||
<a href="{{ post.url }}" class="block p-4">
|
<a href="{{ post.get_absolute_url }}" class="block p-4">
|
||||||
<div class="float-right px-2 py-0.5 rounded-full text-sm font-medium text-proprietary dark:text-blue-100 bg-blue-200 dark:bg-proprietary-dark">
|
<div class="float-right px-2 py-0.5 rounded-full text-sm font-medium text-proprietary dark:text-blue-100 bg-blue-200 dark:bg-proprietary-dark">
|
||||||
<i class="fa-solid fa-calendar-days mr-1"></i>
|
<i class="fa-solid fa-calendar-days mr-1"></i>
|
||||||
<p style="margin-bottom: 0rem;">{{ post.date|date:"d. F Y" }}</p>
|
<p style="margin-bottom: 0rem;">{{ post.date|date:"d. F Y" }}</p>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<article class="article-cover-image" style="background-image: url('{{ post.imageurl }}');" onclick="openArticle('{{ post.url }}')">
|
<article class="article-cover-image" style="background-image: url('{{ post.imageurl }}');" onclick="openArticle('{{ post.get_absolute_url }}')">
|
||||||
<div class="article-cover-desc">
|
<div class="article-cover-desc">
|
||||||
<div class="article-cover-desc-items">
|
<div class="article-cover-desc-items">
|
||||||
<div class="absolute rounded-full px-2 py-1 bg-gray-800 text-gray-200 bg-opacity-90 capitalize"
|
<div class="absolute rounded-full px-2 py-1 bg-gray-800 text-gray-200 bg-opacity-90 capitalize"
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ post.url }}"><h3 class="text-gray-50">{{ post.title | safe }}</h3></a>
|
<a href="{{ post.get_absolute_url }}"><h3 class="text-gray-50">{{ post.title|safe }}</h3></a>
|
||||||
<div class="text-gray-200">
|
<div class="text-gray-200">
|
||||||
<i class="fas fa-clock"></i>
|
<i class="fas fa-clock"></i>
|
||||||
{{ post.date|date:"d. F Y" }}
|
{{ post.date|date:"d. F Y" }}
|
||||||
|
|||||||
Reference in New Issue
Block a user