~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/xhtml.py

Add tabs to the new framework. Move the app icons into the apps themselves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from ivle.webapp.media import media_url
26
26
from ivle.webapp.base.views import BaseView
27
 
from ivle.webapp.base.plugins import OverlayPlugin
 
27
from ivle.webapp.base.plugins import ViewPlugin, OverlayPlugin
28
28
from ivle.webapp.errors import HTTPError, Unauthorized
29
29
import ivle.conf
30
30
import ivle.util
98
98
            ctx['login'] = None
99
99
            ctx['logged_in'] = False
100
100
        ctx['publicmode'] = req.publicmode
101
 
        ctx['apps_in_tabs'] = []
102
101
        if hasattr(self, 'help'):
103
102
            ctx['help_path'] = self.help
104
 
        for urlname in ivle.conf.apps.apps_in_tabs:
105
 
            new_app = {}
106
 
            app = ivle.conf.apps.app_url[urlname]
107
 
            new_app['this_app'] = hasattr(self, 'appname') \
108
 
                                  and urlname == self.appname
109
 
            if app.icon:
110
 
                new_app['has_icon'] = True
111
 
                icon_dir = ivle.conf.apps.app_icon_dir
112
 
                icon_url = ivle.util.make_path(os.path.join(icon_dir, app.icon))
113
 
                new_app['icon_url'] = icon_url
114
 
                if new_app['this_app']:
115
 
                    ctx['favicon'] = icon_url
116
 
            else:
117
 
                new_app['has_icon'] = False
118
 
            new_app['path'] = ivle.util.make_path(urlname)
119
 
            new_app['desc'] = app.desc
120
 
            new_app['name'] = app.name
121
 
            ctx['apps_in_tabs'].append(new_app)
122
 
            
 
103
 
 
104
        ctx['apps_in_tabs'] = []
 
105
        for plugin in req.plugin_index[ViewPlugin]:
 
106
            if not hasattr(plugin, 'tabs'):
 
107
                continue
 
108
 
 
109
            for tab in plugin.tabs:
 
110
                # tab is a tuple: name, title, desc, icon, path
 
111
                new_app = {}
 
112
                new_app['this_app'] = hasattr(self, 'appname') \
 
113
                                      and tab[0] == self.appname
 
114
 
 
115
                # Icon name
 
116
                if tab[3] is not None:
 
117
                    new_app['has_icon'] = True
 
118
                    icon_url = media_url(req, plugin, tab[3])
 
119
                    new_app['icon_url'] = icon_url
 
120
                    if new_app['this_app']:
 
121
                        ctx['favicon'] = icon_url
 
122
                else:
 
123
                    new_app['has_icon'] = False
 
124
                new_app['path'] = ivle.util.make_path(tab[4])
 
125
                new_app['desc'] = tab[2]
 
126
                new_app['name'] = tab[1]
 
127
                new_app['weight'] = tab[5]
 
128
                ctx['apps_in_tabs'].append(new_app)
 
129
 
 
130
        ctx['apps_in_tabs'].sort(key=lambda tab: tab['weight'])
 
131
 
123
132
    def render_overlays(self, req):
124
133
        """Generate XML streams for the overlays.
125
134