Rafał Pitoń 10 лет назад
Родитель
Сommit
dc8dccc80e

+ 2 - 2
misago/core/templatetags/misago_shorthands.py

@@ -5,10 +5,10 @@ register = template.Library()
 
 
 
 
 @register.filter
 @register.filter
-def iftrue(value, test):
+def iftrue(test, value):
     return value if test else ""
     return value if test else ""
 
 
 
 
 @register.filter
 @register.filter
-def iffalse(value, test):
+def iffalse(test, value):
     return "" if test else value
     return "" if test else value

+ 58 - 0
misago/core/tests/test_templatetags.py

@@ -180,3 +180,61 @@ class PaginationTests(TestCase):
 
 
         tpl = Template(tpl_content)
         tpl = Template(tpl_content)
         tpl.render(self.context).strip()
         tpl.render(self.context).strip()
+
+
+class ShorthandsTests(TestCase):
+    def test_iftrue_for_true(self):
+        """iftrue renders value for true"""
+        tpl_content = """
+{% load misago_shorthands %}
+
+{{ value|iftrue:result }}
+"""
+
+        tpl = Template(tpl_content)
+        self.assertEqual(tpl.render(Context({
+            'result': 'Ok!',
+            'value': True
+        })).strip(), 'Ok!')
+
+    def test_iftrue_for_false(self):
+        """iftrue isnt rendering value for false"""
+        tpl_content = """
+{% load misago_shorthands %}
+
+{{ value|iftrue:result }}
+"""
+
+        tpl = Template(tpl_content)
+        self.assertEqual(tpl.render(Context({
+            'result': 'Ok!',
+            'value': False
+        })).strip(), '')
+
+    def test_iffalse_for_true(self):
+        """iffalse isnt rendering value for true"""
+        tpl_content = """
+{% load misago_shorthands %}
+
+{{ value|iffalse:result }}
+"""
+
+        tpl = Template(tpl_content)
+        self.assertEqual(tpl.render(Context({
+            'result': 'Ok!',
+            'value': True
+        })).strip(), '')
+
+    def test_iffalse_for_false(self):
+        """iffalse renders value for false"""
+        tpl_content = """
+{% load misago_shorthands %}
+
+{{ value|iffalse:result }}
+"""
+
+        tpl = Template(tpl_content)
+        self.assertEqual(tpl.render(Context({
+            'result': 'Ok!',
+            'value': False
+        })).strip(), 'Ok!')

+ 1 - 1
misago/templates/misago/threads/base.html

@@ -9,7 +9,7 @@
     <div class="table-panel">
     <div class="table-panel">
       <ul class="list-group">
       <ul class="list-group">
         {% for thread in threads %}
         {% for thread in threads %}
-        <li class="list-group-item {{ "new"|iffalse:thread.is_read }}">
+        <li class="list-group-item {{ thread.is_read|iffalse:"new" }}">
           <div class="row">
           <div class="row">
 
 
             <div class="col-md-7">
             <div class="col-md-7">

+ 4 - 4
misago/templates/misago/user_nav.html

@@ -21,7 +21,7 @@
       </li>
       </li>
       <li>
       <li>
         <a href="{% url 'misago:notifications' %}">
         <a href="{% url 'misago:notifications' %}">
-          <span class="badge fade {{ "in"|iftrue:user.new_notifications }} pull-right" data-misago-badge="notifications.count">{{ user.new_notifications }}</span>
+          <span class="badge fade {{ user.new_notifications|iftrue:"in" }} pull-right" data-misago-badge="notifications.count">{{ user.new_notifications }}</span>
           <span class="fa fa-bell-o"></span>
           <span class="fa fa-bell-o"></span>
           {% trans "See all notifications" %}
           {% trans "See all notifications" %}
         </a>
         </a>
@@ -29,14 +29,14 @@
       <li class="divider"></li>
       <li class="divider"></li>
       <li>
       <li>
         <a href="{% url 'misago:new_threads' %}">
         <a href="{% url 'misago:new_threads' %}">
-          <span class="badge fade {{ "in"|iftrue:user.new_threads }} pull-right" data-misago-badge="new_threads">{{ user.new_threads }}</span>
+          <span class="badge fade {{ user.new_threads|iftrue:"in" }} pull-right" data-misago-badge="new_threads">{{ user.new_threads }}</span>
           <span class="fa fa-plus-circle"></span>
           <span class="fa fa-plus-circle"></span>
           {% trans "New threads" %}
           {% trans "New threads" %}
         </a>
         </a>
       </li>
       </li>
       <li>
       <li>
         <a href="{% url 'misago:unread_threads' %}">
         <a href="{% url 'misago:unread_threads' %}">
-          <span class="badge fade {{ "in"|iftrue:user.unread_threads }} pull-right" data-misago-badge="unread_threads">{{ user.unread_threads }}</span>
+          <span class="badge fade {{ user.unread_threads|iftrue:"in" }} pull-right" data-misago-badge="unread_threads">{{ user.unread_threads }}</span>
           <span class="fa fa-signal"></span>
           <span class="fa fa-signal"></span>
           {% trans "Unread threads" %}
           {% trans "Unread threads" %}
         </a>
         </a>
@@ -83,7 +83,7 @@
         {% endif %}
         {% endif %}
         data-toggle="dropdown">
         data-toggle="dropdown">
       <span class="fa fa-bell-o fa-fw"></span>
       <span class="fa fa-bell-o fa-fw"></span>
-      <span class="badge fade {{ "in"|iftrue:user.new_notifications }}" data-misago-badge="notifications.count">{{ user.new_notifications }}</span>
+      <span class="badge fade {{ user.new_notifications|iftrue:"in" }}" data-misago-badge="notifications.count">{{ user.new_notifications }}</span>
     </a>
     </a>
     <div class="dropdown-menu">
     <div class="dropdown-menu">
       <div class="display"></div>
       <div class="display"></div>