Browse Source

Smarter links builder.

Ralfp 12 years ago
parent
commit
a4789019b0
1 changed files with 12 additions and 22 deletions
  1. 12 22
      templates/cranefly/watched.html

+ 12 - 22
templates/cranefly/watched.html

@@ -37,12 +37,12 @@
         {% for thread in threads %}
         <tr id="watch-{{ loop.index }}">
           <td>
-            <a href="{{ thread_new(thread) }}" class="thread-icon{% if not thread.is_read %} thread-new{% endif %} tooltip-top" title="{% if not thread.is_read -%}
+            <a href="{{ thread_url(thread, 'new') }}" class="thread-icon{% if not thread.is_read %} thread-new{% endif %} tooltip-top" title="{% if not thread.is_read -%}
             {% trans %}Click to see first unread post{% endtrans %}
             {%- else -%}
             {% trans %}Click to see last post{% endtrans %}
             {%- endif %}"><i class="icon-comment"></i></a>
-            <a href="{{ thread_start(thread) }}" class="thread-name">{{ thread.name }}</a>
+            <a href="{{ thread_url(thread) }}" class="thread-name">{{ thread.name }}</a>
             <span class="thread-details">
               {% trans user=thread_starter(thread), forum=thread_forum(thread), start=thread.start|reltimesince|low %}by {{ user }} in {{ forum }} {{ start }}{% endtrans %}
             </span>
@@ -53,13 +53,13 @@
             </div>
           </td>
           <td class="watched-thread-flags">
-            <form action="{% url 'thread_unwatch' thread=thread.pk, slug=thread.slug %}" method="post">
+            <form action="{{ thread_url(thread, 'unwatch') }}" method="post">
               <input type="hidden" name="{{ csrf_id }}" value="{{ csrf_token }}">
               <input type="hidden" name="retreat" value="{{ delete_retreat(loop) }}">
               <button type="submit" class="btn btn-danger tooltip-top" title="{% trans %}Unwatch{% endtrans %}"><i class="icon-remove"></i></button>
             </form>
 
-            <form action="{% if thread.send_email %}{% url 'thread_unwatch_email' thread=thread.pk, slug=thread.slug %}{% else %}{% url 'thread_watch_email' thread=thread.pk, slug=thread.slug %}{% endif %}" method="post">
+            <form action="{% if thread.send_email %}{{ thread_url(thread, 'unwatch_email') }}{% else %}{{ thread_url(thread, 'watch_email') }}{% endif %}" method="post">
               <input type="hidden" name="{{ csrf_id }}" value="{{ csrf_token }}">
               <input type="hidden" name="retreat" value="{{ request_path }}#watch-{{ loop.index }}">
               <button type="submit" class="btn btn-{% if thread.send_email %}success{% else %}inverse{% endif %} tooltip-top" title="{% if thread.send_email %}{% trans %}Don't notify with e-mail{% endtrans %}{% else %}{% trans %}Notify with e-mail{% endtrans %}{% endif %}"><i class="icon-envelope"></i></button>
@@ -82,24 +82,14 @@
 {% endblock %}
 
 
-{% macro thread_new(thread) -%}
-{% if thread.forum_id == private_threads.pk %}
-{% url 'private_thread_new' thread=thread.pk, slug=thread.slug %}
-{% elif thread.forum_id == reports.pk %}
-TODO!
-{% else %}
-{% url 'thread_new' thread=thread.pk, slug=thread.slug %}
-{% endif%}
-{%- endmacro%}
-
-{% macro thread_start(thread) -%}
-{% if thread.forum_id == private_threads.pk %}
-{% url 'private_thread' thread=thread.pk, slug=thread.slug %}
-{% elif thread.forum_id == reports.pk %}
-TODO!
-{% else %}
-{% url 'thread' thread=thread.pk, slug=thread.slug %}
-{% endif%}
+{% macro thread_url(thread, route='') -%}{% filter url(thread=thread.pk, slug=thread.slug) %}{% filter trim %}
+{% if thread.forum_id == private_threads.pk -%}
+private_thread
+{%- elif thread.forum_id == reports.pk -%}
+report
+{%- else -%}
+thread
+{%- endif -%}{%- if route %}_{{ route }}{% endif %}{% endfilter %}{% endfilter %}
 {%- endmacro%}
 
 {% macro replies(thread_replies) -%}