From 68ce65034bf74802383ea3fb70511e8683a6b948 Mon Sep 17 00:00:00 2001 From: Patrick Mayr Date: Sat, 9 Apr 2022 10:14:15 +0000 Subject: [PATCH] simplify post urls --- fet2020/posts/models.py | 2 +- fet2020/posts/templatetags/post_helpers.py | 29 ++----------------- fet2020/posts/urls.py | 10 +++---- fet2020/templates/base.html | 2 +- fet2020/templates/flatpages/social_media.html | 2 +- fet2020/templates/home.html | 5 ++-- fet2020/templates/layout.html | 2 +- fet2020/templates/posts/index.html | 2 -- .../templates/posts/partials/_posts_hero.html | 2 +- .../posts/partials/_posts_pinned.html | 2 +- fet2020/templates/posts/show.html | 13 ++++----- fet2020/tests/test_posts.py | 2 +- 12 files changed, 23 insertions(+), 50 deletions(-) diff --git a/fet2020/posts/models.py b/fet2020/posts/models.py index 4a87ffcf..fa357ca2 100644 --- a/fet2020/posts/models.py +++ b/fet2020/posts/models.py @@ -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 diff --git a/fet2020/posts/templatetags/post_helpers.py b/fet2020/posts/templatetags/post_helpers.py index 2a8c0a80..bf591e46 100644 --- a/fet2020/posts/templatetags/post_helpers.py +++ b/fet2020/posts/templatetags/post_helpers.py @@ -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'#\g<1>', 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 '' + v + "" - except Exception: - m = None - try: - j = Job.objects.filter(shortterm=v).first - if j: - return ' + j.name + '' - except Exception: - j = None - - return "%s" % (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'#\g<1>', value) + ) diff --git a/fet2020/posts/urls.py b/fet2020/posts/urls.py index 4766b332..79515e53 100644 --- a/fet2020/posts/urls.py +++ b/fet2020/posts/urls.py @@ -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("", 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("", views.show, name="show"), re_path( r"^(?P[-\w]+)/agenda.pdf$", views.show_pdf_agenda, @@ -21,7 +21,7 @@ urlpatterns = [ views.show_pdf_protocol, name="show_pdf_protocol", ), - path("t/", views.tags, name="posts.tags"), + path("t/", views.tags, name="tags"), path("func/tag_complete", tag_complete), path("func/slug_calc", slug_calc), ] diff --git a/fet2020/templates/base.html b/fet2020/templates/base.html index 64db1a2c..549df7d1 100644 --- a/fet2020/templates/base.html +++ b/fet2020/templates/base.html @@ -68,7 +68,7 @@ x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-90" > -
  • News
  • +
  • News
  • Fachschaft
  • Galerie
  • Blackboard
  • diff --git a/fet2020/templates/flatpages/social_media.html b/fet2020/templates/flatpages/social_media.html index 40d67252..44858956 100644 --- a/fet2020/templates/flatpages/social_media.html +++ b/fet2020/templates/flatpages/social_media.html @@ -70,7 +70,7 @@ - + @@ -81,7 +80,7 @@ {% include 'posts/partials/_posts_hero.html' %} {% endfor %} - Mehr anzeigen + Mehr anzeigen diff --git a/fet2020/templates/layout.html b/fet2020/templates/layout.html index 3bca7edb..beaf1823 100644 --- a/fet2020/templates/layout.html +++ b/fet2020/templates/layout.html @@ -59,7 +59,7 @@
  • Intern
  • Legacy
  • {% endif %} -
  • News
  • +
  • News
  • Fachschaft
  • Galerie
  • diff --git a/fet2020/templates/posts/index.html b/fet2020/templates/posts/index.html index cfd0c0ad..6433467a 100644 --- a/fet2020/templates/posts/index.html +++ b/fet2020/templates/posts/index.html @@ -1,7 +1,5 @@ {% extends 'base.html' %} -{% load post_helpers %} - {% block title %}News{% endblock %} {% block content %} diff --git a/fet2020/templates/posts/partials/_posts_hero.html b/fet2020/templates/posts/partials/_posts_hero.html index b5ae5069..1291372b 100644 --- a/fet2020/templates/posts/partials/_posts_hero.html +++ b/fet2020/templates/posts/partials/_posts_hero.html @@ -3,7 +3,7 @@
    diff --git a/fet2020/templates/posts/partials/_posts_pinned.html b/fet2020/templates/posts/partials/_posts_pinned.html index 5aceed3c..ed0000d1 100644 --- a/fet2020/templates/posts/partials/_posts_pinned.html +++ b/fet2020/templates/posts/partials/_posts_pinned.html @@ -11,7 +11,7 @@
    diff --git a/fet2020/templates/posts/show.html b/fet2020/templates/posts/show.html index 7549cffb..eabde158 100644 --- a/fet2020/templates/posts/show.html +++ b/fet2020/templates/posts/show.html @@ -1,7 +1,6 @@ {% extends 'base.html' %} {% load post_helpers %} -{% load admin_urls %} {% block title %}News{% endblock %} @@ -15,7 +14,7 @@ {% block content %}
    - -

    {{ post.title|tags_to_url }}

    @@ -149,7 +148,7 @@ {{ post.agenda_html|safe }}
    {% 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 @@
    - + Vorheriger Artikel - + Nächster Artikel diff --git a/fet2020/tests/test_posts.py b/fet2020/tests/test_posts.py index d8501d26..1498006d 100644 --- a/fet2020/tests/test_posts.py +++ b/fet2020/tests/test_posts.py @@ -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