simplify post urls

This commit is contained in:
2022-04-09 10:14:15 +00:00
parent 531b69663c
commit 68ce65034b
12 changed files with 23 additions and 50 deletions

View File

@@ -137,7 +137,7 @@ class Post(models.Model):
)
def get_absolute_url(self):
return reverse("posts:posts.show", kwargs={"id": self.slug})
return reverse("posts:show", kwargs={"id": self.slug})
def save(self, *args, **kwargs):
# save the post with some defaults

View File

@@ -12,29 +12,6 @@ register = template.Library()
@stringfilter
def tags_to_url(value):
# return "Tag to url: %s" % value
return mark_safe(re.sub(r'\#([\d\w-]+)', r'<a href="/posts/t/\g<1>">#\g<1></a>', value))
def create_a_link_for(v):
v = v.group(1)
try:
m = Member.all_members.get(nickname=v)
str_nickname = str(reverse('member', kwargs={"member_name": m.nickname}))
return '<a href="' + str_nickname + '">' + v + "</a>"
except Exception:
m = None
try:
j = Job.objects.filter(shortterm=v).first
if j:
return '<a href="' + '"' > + j.name + '</a>'
except Exception:
j = None
return "<a href=\"/posts/%s\">%s</a>" % (v, v)
@register.filter(is_safe=True)
def add_internal_links(value):
# m=Member.all_members.get(value)
return mark_safe(re.sub(r'\[\[([\d\w-]+)\]\]', create_a_link_for, value))
return mark_safe(
re.sub(r"\#([\d\w-]+)", r'<a href="/posts/t/\g<1>">#\g<1></a>', value)
)

View File

@@ -7,10 +7,10 @@ from .utils import slug_calc, tag_complete
app_name = apps.PostsConfig.name
urlpatterns = [
path("", views.index, name="posts.index"),
# fet calendar (path have to be ahead posts.show)
path("fet_calendar.ics", views.calendar, name="posts.calendar"),
path("<str:id>", views.show, name="posts.show"),
path("", views.index, name="index"),
# fet calendar (path have to be ahead show)
path("fet_calendar.ics", views.calendar, name="calendar"),
path("<str:id>", views.show, name="show"),
re_path(
r"^(?P<id>[-\w]+)/agenda.pdf$",
views.show_pdf_agenda,
@@ -21,7 +21,7 @@ urlpatterns = [
views.show_pdf_protocol,
name="show_pdf_protocol",
),
path("t/<str:tag>", views.tags, name="posts.tags"),
path("t/<str:tag>", views.tags, name="tags"),
path("func/tag_complete", tag_complete),
path("func/slug_calc", slug_calc),
]

View File

@@ -68,7 +68,7 @@
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-90"
>
<li><a href="{% url 'posts:posts.index' %}">News</a></li>
<li><a href="{% url 'posts:index' %}">News</a></li>
<li><a href="{% url 'members_view' 'active' %}">Fachschaft</a></li>
<li><a href="{% url 'gallery' %}">Galerie</a></li>
<li><a href="{% url 'blackboard' %}">Blackboard</a></li>

View File

@@ -70,7 +70,7 @@
</div>
</a>
<a href="{% url 'posts:posts.calendar' %}">
<a href="{% url 'posts:calendar' %}">
<div class="social-media-box">
<span class="social-media-badge badge">
<span class="social-media-badge-symbol">

View File

@@ -1,6 +1,5 @@
{% extends 'base.html' %}
{% load post_helpers %}
{% load static %}
{% block content %}
@@ -63,7 +62,7 @@
{% include 'posts/partials/_date_box.html' %}
{% endfor %}
<a href="{% url 'posts:posts.calendar' %}" class="btn btn-secondary block w-full"><i class="fas fa-calendar-alt mr-2"></i>Kalender abonnieren</a>
<a href="{% url 'posts:calendar' %}" class="btn btn-secondary block w-full"><i class="fas fa-calendar-alt mr-2"></i>Kalender abonnieren</a>
</div>
</div>
</aside>
@@ -81,7 +80,7 @@
{% include 'posts/partials/_posts_hero.html' %}
{% endfor %}
<a href="{% url 'posts:posts.index' %}" class="btn btn-primary block w-full"><i class="fas fa-plus-square mr-2"></i>Mehr anzeigen</a>
<a href="{% url 'posts:index' %}" class="btn btn-primary block w-full"><i class="fas fa-plus-square mr-2"></i>Mehr anzeigen</a>
</section>
</div>

View File

@@ -59,7 +59,7 @@
<li><a class="button header-intern-btn header-intern-link" href="{% url 'intern:index' %}">Intern</a></li>
<li><a class="button header-intern-btn header-intern-link" href="https://legacy.fet.at/home/intern">Legacy</a></li>
{% endif %}
<li><a class="button header-btn header-link" href="{% url 'posts:posts.index' %}">News</a></li>
<li><a class="button header-btn header-link" href="{% url 'posts:index' %}">News</a></li>
<!-- show active members first -->
<li><a class="button header-btn header-link" href="{% url 'members_view' 'active' %}">Fachschaft</a></li>
<li><a class="button header-btn header-link" href="{% url 'gallery' %}">Galerie</a></li>

View File

@@ -1,7 +1,5 @@
{% extends 'base.html' %}
{% load post_helpers %}
{% block title %}News{% endblock %}
{% block content %}

View File

@@ -3,7 +3,7 @@
<div class="article-cover-desc-items">
<ul class="article-cover-tags">
{% for t in post.three_tag_names %}
<li><a href="{% url 'posts:posts.tags' t %}">#{{ t }}</a></li>
<li><a href="{% url 'posts:tags' t %}">#{{ t }}</a></li>
{% endfor %}
</ul>
<div>

View File

@@ -11,7 +11,7 @@
</div>
<ul class="article-cover-tags">
{% for t in post.three_tag_names %}
<li><a href="{% url 'posts:posts.tags' t %}">#{{ t }}</a></li>
<li><a href="{% url 'posts:tags' t %}">#{{ t }}</a></li>
{% endfor %}
</ul>
<div>

View File

@@ -1,7 +1,6 @@
{% extends 'base.html' %}
{% load post_helpers %}
{% load admin_urls %}
{% block title %}News{% endblock %}
@@ -15,7 +14,7 @@
{% block content %}
<!-- Main Content -->
<main class="container mx-auto w-full flex-1 my-8 sm:flex flex-col sm:px-4">
<a href="{% url 'posts:posts.show' previous %}" class="hidden z-20 fixed left-0 top-1/2 -mt-8 p-2 xl:flex items-center text-gray-400 dark:text-gray-300 rounded-md"
<a href="{% url 'posts:show' previous %}" class="hidden z-20 fixed left-0 top-1/2 -mt-8 p-2 xl:flex items-center text-gray-400 dark:text-gray-300 rounded-md"
x-data="{ showPrevArticleButton : false }"
@mouseleave="showPrevArticleButton = false"
@mouseover="showPrevArticleButton = true"
@@ -31,7 +30,7 @@
x-transition:leave-end="opacity-0 bg-opacity-0 transform scale-100"
>Vorheriger<br>Artikel</span>
</a>
<a href="{% url 'posts:posts.show' next %}" class="hidden z-20 fixed right-0 top-1/2 -mt-8 p-2 xl:flex items-center text-gray-400 dark:text-gray-300 rounded-md"
<a href="{% url 'posts:show' next %}" class="hidden z-20 fixed right-0 top-1/2 -mt-8 p-2 xl:flex items-center text-gray-400 dark:text-gray-300 rounded-md"
x-data="{ showNextArticleButton : false }"
@mouseleave="showNextArticleButton = false"
@mouseover="showNextArticleButton = true"
@@ -51,7 +50,7 @@
<div class="mb-4 flex flex-col sm:flex-col gap-2 mx-auto">
<ul class="px-4 sm:px-0 mb-2 flex flex-row justify-center gap-2 sm:gap-4 flex-wrap text-sky-700 dark:text-blue-200 text-sm uppercase tracking-wide sm:font-medium">
{% for t in post.tag_names %}
<li class="inline-block py-1 px-2 bg-sky-100 dark:bg-sky-900 rounded-full"><a href="{% url 'posts:posts.tags' t %}">#{{ t }}</a></li>
<li class="inline-block py-1 px-2 bg-sky-100 dark:bg-sky-900 rounded-full"><a href="{% url 'posts:tags' t %}">#{{ t }}</a></li>
{% endfor %}
</ul>
<h1 class="px-4 sm:px-0 text-lg sm:text-xl lg:text-3xl text-center sm:text-left font-medium text-gray-900 dark:text-gray-100 font-serif tracking-wider leading-normal" style="line-height: 1.5;">{{ post.title|tags_to_url }}</h1>
@@ -149,7 +148,7 @@
{{ post.agenda_html|safe }}
<hr>
{% elif post.body %}
{{ post.body|safe|add_internal_links|tags_to_url }}
{{ post.body|safe|tags_to_url }}
{% endif %}
{% if request.user.is_authenticated and post.has_protocol %}
@@ -283,11 +282,11 @@
<hr class="-mx-4 border-gray-200 dark:border-gray-800 dark:border my-4">
<div class="-m-4 flex divide-x divide-gray-200 dark:divide-gray-800 dark:divide-x-2 text-sm sm:text-base">
<a href="{% url 'posts:posts.show' previous %}" class="w-1/2 p-4 flex items-center gap-2">
<a href="{% url 'posts:show' previous %}" class="w-1/2 p-4 flex items-center gap-2">
<i class="fa-solid fa-chevron-left text-gray-600 dark:text-gray-400"></i>
<span class="text-gray-700 dark:text-gray-300 font-medium">Vorheriger Artikel</span>
</a>
<a href="{% url 'posts:posts.show' next %}" class="w-1/2 p-4 flex flex-row-reverse items-center gap-2">
<a href="{% url 'posts:show' next %}" class="w-1/2 p-4 flex flex-row-reverse items-center gap-2">
<i class="fa-solid fa-chevron-right text-gray-600 dark:text-gray-400"></i>
<span class="text-gray-700 dark:text-gray-300 font-medium">Nächster Artikel</span>
</a>

View File

@@ -54,7 +54,7 @@ class TestPostModel:
assert "asdf" in post_saved.slug
def test_url_attribute(self, post_saved):
assert reverse("posts.show", kwargs={"id": post_saved.slug}) == post_saved.url
assert reverse("show", kwargs={"id": post_saved.slug}) == post_saved.url
def test_default_hidden(self, post_saved):
assert post_saved.is_hidden==False