Browse Source

Updating is_active_page to use context and check for attributes (#158)

Vince Salvino 6 years ago
parent
commit
4ba7419b64

+ 2 - 2
coderedcms/templates/coderedcms/blocks/base_link_block.html

@@ -4,7 +4,7 @@
     {% if value.page.live or value.link or value.document %}
     {% is_menu_item_dropdown value as has_dropdown %}
     <li class="{{liclass}} {% if has_dropdown %}dropdown{% endif %}">
-        {% is_active_page page value.page request as is_active_url %}
+        {% is_active_page page value.page as is_active_url %}
         <a href="{% block url %}#{% endblock %}"
         {% if value.settings.custom_id %}id="{{value.settings.custom_id}}"{% endif %}
         class="{{aclass}} {% if has_dropdown %}dropdown-toggle{% endif %} {% if is_active_url %}active{% endif %} {% if value.settings.custom_css_class %}{{value.settings.custom_css_class}}{% endif %}"
@@ -40,7 +40,7 @@
             {% endfor %}
             {% if value.show_child_links %}
                 {% for child in value.page.specific.get_index_children %}
-                    {% is_active_page page child request as is_active_child %}
+                    {% is_active_page page child as is_active_child %}
                     <li><a class="dropdown-item {% if is_active_child %}active{% endif %}" href="{% pageurl child %}">{{child.title}}</a></li>
                 {% endfor %}
             {% endif %}

+ 6 - 7
coderedcms/templatetags/coderedcms_tags.py

@@ -63,14 +63,13 @@ def is_menu_item_dropdown(value):
             len(value.get('page', []).get_children().live()) > 0
         )
 
-@register.simple_tag
-def is_active_page(curr_page, other_page, request):
-    try:
-        curr_url = curr_page.get_url(request)
-        other_url = other_page.get_url(request)
+@register.simple_tag(takes_context=True)
+def is_active_page(context, curr_page, other_page):
+    if hasattr(curr_page, 'get_url') and hasattr(other_page, 'get_url'):
+        curr_url = curr_page.get_url(context['request'])
+        other_url = other_page.get_url(context['request'])
         return curr_url == other_url
-    except:
-        return False
+    return False
 
 @register.simple_tag
 def get_pictures(collection_id):