def render_overlays(self, req): """Generate XML streams for the overlays. Returns a list of streams. Populates the scripts, styles, and scripts_init. """ overlays = [] styles = [] scripts = [] scripts_init = [] if not self.allow_overlays: return (overlays, styles, scripts, scripts_init) for plugin in req.config.plugin_index[OverlayPlugin]: for overclass in plugin.overlays: if overclass in self.overlay_blacklist: continue overlay = overclass(req) #TODO: Re-factor this to look nicer for mplugin in overlay.plugin_scripts: for path in overlay.plugin_scripts[mplugin]: scripts.append(media_url(req, mplugin, path)) for mplugin in overlay.plugin_styles: for path in overlay.plugin_styles[mplugin]: styles.append(media_url(req, mplugin, path)) scripts_init += overlay.plugin_scripts_init overlays.append(overlay.render(req)) return (overlays, styles, scripts, scripts_init)
def populate(self, req, ctx): ctx['windowpane'] = True ctx['maximize_path'] = media_url(req, CorePlugin, 'images/interface/maximize.png') ctx['minimize_path'] = media_url(req, CorePlugin, 'images/interface/minimize.png') ctx['start_body_attrs'] = {'class': 'console_body windowpane minimal'} return ctx
def populate(self, req, ctx): ctx['req'] = req ctx['offering'] = self.context ctx['mediapath'] = media_url(req, CorePlugin, 'images/') ctx['offering_perms'] = self.context.get_permissions( req.user, req.config) ctx['EnrolView'] = EnrolView ctx['EnrolmentEdit'] = EnrolmentEdit ctx['EnrolmentDelete'] = EnrolmentDelete
def populate(self, req, ctx): ctx['req'] = req ctx['mediapath'] = media_url(req, CorePlugin, 'images/') ctx['SubjectView'] = SubjectView ctx['SubjectEdit'] = SubjectEdit ctx['SemesterEdit'] = SemesterEdit ctx['subjects'] = req.store.find(Subject).order_by(Subject.name) ctx['semesters'] = req.store.find(Semester).order_by( Semester.year, Semester.display_name)
def populate_headings(self, req, ctx): ctx['favicon'] = None ctx['root_dir'] = req.config['urls']['root'] ctx['public_host'] = req.config['urls']['public_host'] ctx['svn_base'] = req.config['urls']['svn_addr'] ctx['write_javascript_settings'] = req.write_javascript_settings if req.user: ctx['login'] = req.user.login ctx['logged_in'] = True ctx['nick'] = req.user.nick else: ctx['login'] = None ctx['logged_in'] = False ctx['publicmode'] = req.publicmode if hasattr(self, 'help'): ctx['help_path'] = self.help ctx['apps_in_tabs'] = [] for plugin in req.config.plugin_index[ViewPlugin]: if not hasattr(plugin, 'tabs'): continue for tab in plugin.tabs: # tab is a tuple: name, title, desc, icon, path, weight, admin # (Admin is optional, defaults to false) new_app = {} new_app['this_app'] = hasattr(self, 'tab') \ and tab[0] == self.tab # Icon name if tab[3] is not None: new_app['has_icon'] = True icon_url = media_url(req, plugin, tab[3]) new_app['icon_url'] = icon_url if new_app['this_app']: ctx['favicon'] = icon_url else: new_app['has_icon'] = False # The following check is here, so it is AFTER setting the # icon, but BEFORE actually installing the tab in the menu if len(tab) > 6 and tab[6]: # Admin-only tab if not (req.user and req.user.admin): break new_app['path'] = req.make_path(tab[4]) new_app['desc'] = tab[2] new_app['name'] = tab[1] new_app['weight'] = tab[5] ctx['apps_in_tabs'].append(new_app) ctx['apps_in_tabs'].sort(key=lambda tab: tab['weight'])
def populate(self, req, ctx): if len(self.path) == 0: # If no path specified, default to the user's home directory redirectPath = req.make_path(os.path.join('files', req.user.login)) req.throw_redirect(redirectPath) # Set request attributes self.plugin_styles[Plugin] = ['browser.css', 'listing.css', 'editor.css'] self.plugin_scripts[Plugin] = ['browser.js', 'listing.js', 'editor.js', 'specialhome.js'] self.plugin_scripts['+external/codemirror'] = ['js/codemirror.js'] self.scripts_init = ["browser_init"] # Start writing data # TODO: Set this properly. We can't get into the jail from server-side # code at the moment, so we can't determine this. isdir = False revision = ivle.svn.revision_from_string( req.get_fieldstorage().getfirst('r')) try: revno = revision.number except: revno = None ctx['isdir'] = isdir ctx['revno'] = revno self.extra_breadcrumbs = make_path_breadcrumbs(req, self.subpath,revno) self.gen_actions(req, ctx) # The page title should contain the name of the file being browsed ctx['title'] = os.path.normpath(self.path).rsplit('/', 1)[-1] ctx['fileservice_action'] = req.make_path(os.path.join("fileservice", self.path)) ctx['filename'] = cgi.escape(self.path) # Media URL for CodeMirror ctx['codemirrorpath'] = media_url(req, '+external/codemirror', '')
def render(self, req): req.content_type = 'text/html' # TODO: Detect application/xhtml+xml # View template viewctx = genshi.template.Context() self.populate(req, viewctx) # The template is found in the directory of the module containing the # view. app_template = os.path.join(os.path.dirname( inspect.getmodule(self).__file__), self.template) tmpl = self._loader.load(app_template) app = self.filter(tmpl.generate(viewctx), viewctx) view_scripts = [] for plugin in self.plugin_scripts: for path in self.plugin_scripts[plugin]: view_scripts.append(media_url(req, plugin, path)) view_styles = [] for plugin in self.plugin_styles: for path in self.plugin_styles[plugin]: view_styles.append(media_url(req, plugin, path)) # Global template ctx = genshi.template.Context() overlay_bits = self.render_overlays(req) if req.user else [[]]*4 ctx['overlays'] = overlay_bits[0] ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')] ctx['styles'] += view_styles ctx['styles'] += overlay_bits[1] ctx['scripts'] = [media_url(req, CorePlugin, path) for path in ('util.js', 'json2.js', 'md5.js')] ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js')) ctx['scripts'] += view_scripts ctx['scripts'] += overlay_bits[2] ctx['scripts_init'] = self.scripts_init + overlay_bits[3] ctx['app_template'] = app ctx['title_img'] = media_url(req, CorePlugin, "images/chrome/root-breadcrumb.png") try: ancestry = self.get_context_ancestry(req) except NoPath: ancestry = [] crumber = Breadcrumber(req) ctx['breadcrumbs'] = [] if not req.publicmode: for ancestor in ancestry: crumb = crumber.crumb(ancestor) if crumb is None: continue if hasattr(crumb, 'extra_breadcrumbs_before'): ctx['breadcrumbs'].extend(crumb.extra_breadcrumbs_before) ctx['breadcrumbs'].append(crumb) if hasattr(crumb, 'extra_breadcrumbs_after'): ctx['breadcrumbs'].extend(crumb.extra_breadcrumbs_after) # If the view has specified text for a breadcrumb, add one. if self.breadcrumb_text: ctx['breadcrumbs'].append(ViewBreadcrumb(req, self)) # Allow the view to add its own fake breadcrumbs. ctx['breadcrumbs'].extend(self.extra_breadcrumbs) self.populate_headings(req, ctx) tmpl = self._loader.load(os.path.join(os.path.dirname(__file__), 'ivle-headings.html')) req.write(tmpl.generate(ctx).render('xhtml', doctype='xhtml'))