changeset 2393:0cb9f75fb9ba

Refactored local_panel rendering code, almost everything processed on python side
author sharky93 <rishabhr123@gmail.com>
date Sun, 18 Aug 2013 02:08:46 +0530
parents c515adfb6b69
children 2e84d4574332
files MoinMoin/themes/__init__.py MoinMoin/themes/basic/templates/show.html
diffstat 2 files changed, 86 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/themes/__init__.py	Sat Aug 17 20:59:34 2013 +0530
+++ b/MoinMoin/themes/__init__.py	Sun Aug 18 02:08:46 2013 +0530
@@ -88,10 +88,68 @@
         return navtabs
 
     def get_local_panel(self, item_name):
-        user_actions = ['frontend.quicklink_item', 'frontend.subscribe_item', ]
-        item_navigation = ['frontend.index', 'frontend.sitemap', ]
-        item_actions = ['frontend.rename_item', 'frontend.delete_item', 'frontend.destroy_item',
-                'frontend.similar_names', 'frontend.download_item', 'frontend.copy_item',] if self.user.may.write(item_name) else []
+        user_actions_endpoints = ['frontend.quicklink_item', 'frontend.subscribe_item', ]
+        item_navigation_endpoints = ['frontend.index', 'frontend.sitemap', ]
+        item_actions_endpoints = ['frontend.rename_item', 'frontend.delete_item', 'frontend.destroy_item',
+                'frontend.similar_names', 'frontend.download_item', 
+                'frontend.copy_item', 'special.supplementation'] if self.user.may.write(item_name) else []
+
+        user_actions = []
+        item_navigation = []
+        item_actions = []
+
+        icon = self.get_endpoint_iconmap()
+        exists = flaskg.storage.has_item(item_name)
+
+        for endpoint, label, title, check_exists in app.cfg.item_views:
+            if endpoint not in app.cfg.endpoints_excluded:
+                if not check_exists or exists:
+                    if endpoint in user_actions_endpoints:
+                        print user_actions
+                        if flaskg.user.valid:
+                            href = url_for(endpoint, item_name=item_name)
+                            iconcls = icon[endpoint]
+                            #endpoint = iconcls = label = None
+
+                            if endpoint == 'frontend.quicklink_item':
+                                if not flaskg.user.is_quicklinked_to([item_name]):
+                                    label = _('Add Link')
+                                    user_actions.append((endpoint, href, iconcls, label, title))
+                            elif endpoint == 'frontend.subscribe_item':
+                                if flaskg.user.is_subscribed_to([item_name]):
+                                    label = _('Unsubscribe')
+                                else:
+                                    label = _('Subscribe')
+                                    user_actions.append((endpoint, href, iconcls, label, title))
+
+                    elif endpoint in item_actions_endpoints:
+
+                        iconcls = icon[endpoint]
+
+                        if endpoint == 'special.supplementation':
+                            for sub_item_name in app.cfg.supplementation_item_names:
+                                current_sub = item_name.rsplit('/', 1)[-1]
+                                if current_sub not in app.cfg.supplementation_item_names:
+                                    supp_name = '%s/%s' % (item_name, sub_item_name)
+                                    if flaskg.storage.has_item(supp_name) or flaskg.user.may.write(supp_name):
+                                        href = url_for('frontend.show_item', item_name=supp_name)
+                                        label = _(sub_item_name)
+                                        title = None
+
+                                        item_actions.append((endpoint, href, iconcls, label, title))
+                        else:
+                            href = url_for(endpoint, item_name=item_name)
+                            item_actions.append((endpoint, href, iconcls, label, title))
+
+                    elif endpoint in item_navigation_endpoints:
+
+                        iconcls = icon[endpoint]
+                        href = url_for(endpoint, item_name=item_name)
+
+                        item_navigation.append((endpoint, href, iconcls, label, title))
+
+        print user_actions
+
         return user_actions, item_navigation, item_actions
 
     def get_endpoint_iconmap(self):
--- a/MoinMoin/themes/basic/templates/show.html	Sat Aug 17 20:59:34 2013 +0530
+++ b/MoinMoin/themes/basic/templates/show.html	Sun Aug 18 02:08:46 2013 +0530
@@ -22,89 +22,38 @@
 {% endblock %}
 
 {% block user_actions %}
-    {% set user_actions_exist = false %}
-
-    {% if user.valid %}
     <div class="list-group-item">User Actions</div>
-        {%- for endpoint, label, title, check_exists in cfg.item_views if not endpoint in cfg.endpoints_excluded %}
-            {%- if not check_exists or check_exists and exists %}
-
-                {%- if endpoint in user_actions %}
-                    {%- if endpoint == 'frontend.quicklink_item' %}
-                        {%- if not user.is_quicklinked_to([item_name]) %}
-                            <a class="list-group-item" href="{{ url_for(endpoint, item_name=item_name) }}" title="{{ title }}" rel="nofollow">
-                            <span class="icon-stack">
-                                <i class={{icon[endpoint]}}></i>
-                            </span> 
-                            {{ _('Add Link') }}
-                            </a>
-                        {%- endif %}
-                    {% elif endpoint == 'frontend.subscribe_item' %}
-                        <a class="list-group-item" href="{{ url_for(endpoint, item_name=item_name) }}" title="{{ title }}" rel="nofollow">
-                        <span class="icon-stack">
-                            <i class={{icon[endpoint]}}></i>
-                        </span> 
-                        {%- if user.is_subscribed_to([item_name]) %}
-                            {{ _('Unsubscribe') }}
-                        {%- else %}
-                            {{ _('Subscribe') }}
-                        {%- endif %}
-                        </a>
-                    {% endif %}
-                {%- endif %}
-
-            {%- endif %}
-        {% endfor %}
-    {% endif %}
+    {% for endpoint, href, iconcls, label, title in user_actions %}
+        <a class="list-group-item" href="{{ href }}" title="{{ title }}" rel="nofollow">
+            <span class="icon-stack">
+                <i class="{{ iconcls }}"></i>
+            </span> 
+            {{ label }}
+        </a>
+    {% endfor %}
 {% endblock %}
 
-{% block site_actions %}
+{% block item_navigation %}
     <div class="list-group-item">Item Navigation</div>
-    {%- for endpoint, label, title, check_exists in cfg.item_views if not endpoint in cfg.endpoints_excluded %}
-        {%- if not check_exists or check_exists and exists %}
-
-            {%- if endpoint in item_navigation %}
-                <a class="list-group-item" href="{{ url_for(endpoint, item_name=item_name) }}" title="{{ title }}" rel="nofollow">
-                <span class="icon-stack">    
-                    <i class={{icon[endpoint]}}></i>
-                </span>
-                    {{ label }}
-                </a>
-            {%- endif %}
-
-        {% endif %}
+    {% for endpoint, href, iconcls, label, title in item_navigation %}
+        <a class="list-group-item" href="{{ href }}" title="{{ title }}" rel="nofollow">
+        <span class="icon-stack">    
+            <i class="{{ iconcls }}"></i>
+        </span>
+            {{ label }}
+        </a>
     {% endfor %}
 {% endblock %}
 
 {% block item_actions %}
     <div class="list-group-item">Item Actions</div>
-    {%- for endpoint, label, title, check_exists in cfg.item_views if not endpoint in cfg.endpoints_excluded %}
-        {%- if not check_exists or check_exists and exists %}
-            {%- if endpoint == 'special.supplementation' %}
-                {%- for sub_item_name in cfg.supplementation_item_names %}
-                    {%- set current_sub = item_name.rsplit('/', 1)[-1] %}
-                    {%- if not current_sub in cfg.supplementation_item_names %}
-                        {%- set supp_name = '%s/%s' % (item_name, sub_item_name) %}
-                        {%- if storage.has_item(supp_name) or user.may.write(supp_name) %}
-                            <a class="list-group-item" href="{{ url_for('frontend.show_item', item_name=supp_name) }}" rel="nofollow">
-                                <span class="icon-stack">
-                                    <i class={{icon[endpoint]}}></i>
-                                </span>
-                                {{ _(sub_item_name) }}
-                            </a>
-                        {%- endif %}
-                    {%- endif %}
-                {%- endfor %}
-            {%- elif endpoint in item_actions %}
-                <a class="list-group-item" href="{{ url_for(endpoint, item_name=item_name) }}" title="{{ title }}" rel="nofollow">
-                <span class="icon-stack">
-                    <i class={{icon[endpoint]}}></i>
-                </span>
-                    {{ label }}
-                </a>
-            {%- endif %}
-
-        {% endif %}
+    {% for endpoint, href, iconcls, label, title in item_actions %}
+        <a class="list-group-item" href="{{ href }}" title="{{ title }}" rel="nofollow">
+        <span class="icon-stack">
+            <i class="{{ iconcls }}"></i>
+        </span>
+            {{ label }}
+        </a>
     {% endfor %}
 {% endblock %}
 
@@ -114,7 +63,7 @@
     <div class="list-group">
         {{ self.user_actions() }}
 
-        {{ self.site_actions() }}
+        {{ self.item_navigation() }}
 
         {{ self.item_actions() }}
     </div>