def generateHeader(target, db, user, generate_right=None, current_page=None, extra_links=[], profiler=None): target.addExternalStylesheet("resource/third-party/jquery-ui.css") target.addExternalStylesheet("resource/third-party/chosen.css") target.addExternalStylesheet("resource/overrides.css") target.addExternalStylesheet("resource/basic.css") target.addInternalStylesheet(".defaultfont, body { %s }" % user.getPreference(db, "style.defaultFont")) target.addInternalStylesheet(".sourcefont { %s }" % user.getPreference(db, "style.sourceFont")) target.addExternalScript("resource/third-party/jquery.js") target.addExternalScript("resource/third-party/jquery-ui.js") target.addExternalScript("resource/third-party/jquery-ui-autocomplete-html.js") target.addExternalScript("resource/third-party/chosen.js") target.addExternalScript("resource/basic.js") target.noscript().h1("noscript").blink().text("Please enable scripting support!") row = target.table("pageheader", width='100%').tr() left = row.td("left", valign='bottom', align='left') b = left.b() opera_class = "opera" if configuration.debug.IS_DEVELOPMENT: opera_class += " development" b.b(opera_class, onclick="location.href='/';").text("Opera") b.b("critic", onclick="location.href='/';").text("Critic") links = [] if not user.isAnonymous(): links.append(["home", "Home", None, None]) links.append(["dashboard", "Dashboard", None, None]) links.append(["branches", "Branches", None, None]) links.append(["search", "Search", None, None]) if user.hasRole(db, "administrator"): links.append(["services", "Services", None, None]) if user.hasRole(db, "repositories"): links.append(["repositories", "Repositories", None, None]) if profiler: profiler.check("generateHeader (basic)") if configuration.extensions.ENABLED: from extensions.extension import Extension updated = Extension.getUpdatedExtensions(db, user) if updated: link_title = "\n".join([("%s by %s can be updated!" % (extension_name, author_fullname)) for author_fullname, extension_name in updated]) links.append(["manageextensions", "Extensions (%d)" % len(updated), "color: red", link_title]) else: links.append(["manageextensions", "Extensions", None, None]) if profiler: profiler.check("generateHeader (updated extensions)") links.append(["config", "Config", None, None]) links.append(["tutorial", "Tutorial", None, None]) if user.isAnonymous(): count = 0 else: cursor = db.cursor() cursor.execute("""SELECT COUNT(*) FROM newsitems LEFT OUTER JOIN newsread ON (item=id AND uid=%s) WHERE uid IS NULL""", (user.id,)) count = cursor.fetchone()[0] if count: links.append(["news", "News (%d)" % count, "color: red", "There are %d unread news items!" % count]) else: links.append(["news", "News", None, None]) if profiler: profiler.check("generateHeader (news)") req = target.getRequest() if configuration.base.AUTHENTICATION_MODE != "host" \ and configuration.base.SESSION_TYPE == "cookie": if user.isAnonymous(): links.append(["javascript:void(location.href='/login?target='+encodeURIComponent(location.href));", "Sign in", None, None]) elif not req or (req.user == user.name and req.session_type == "cookie"): links.append(["javascript:signOut();", "Sign out", None, None]) for url, label in extra_links: links.append([url, label, None, None]) if req and configuration.extensions.ENABLED: import extensions.role.inject injected = {} extensions.role.inject.execute(db, req, user, target, links, injected, profiler=profiler) for url in injected.get("stylesheets", []): target.addExternalStylesheet(url, use_static=False, order=1) for url in injected.get("scripts", []): target.addExternalScript(url, use_static=False, order=1) else: injected = None ul = left.ul() for index, (url, label, style, title) in enumerate(links): if not re.match("[-.a-z]+:|/", url): url = "/" + url ul.li().a(href=url, style=style, title=title).text(label) rel = LINK_RELS.get(label) if rel: target.setLink(rel, url) right = row.td("right", valign='bottom', align='right') if generate_right: generate_right(right) else: right.div("buttons").span("buttonscope buttonscope-global") if profiler: profiler.check("generateHeader (finish)") return injected
def generateHeader(target, db, user, generate_right=None, current_page=None, extra_links=[], profiler=None): target.addExternalStylesheet("resource/third-party/jquery-ui.css") target.addExternalStylesheet("resource/third-party/chosen.css") target.addExternalStylesheet("resource/overrides.css") target.addExternalStylesheet("resource/basic.css") target.addInternalStylesheet(".defaultfont, body { %s }" % user.getPreference(db, "style.defaultFont")) target.addInternalStylesheet(".sourcefont { %s }" % user.getPreference(db, "style.sourceFont")) target.addExternalScript("resource/third-party/jquery.js") target.addExternalScript("resource/third-party/jquery-ui.js") target.addExternalScript( "resource/third-party/jquery-ui-autocomplete-html.js") target.addExternalScript("resource/third-party/chosen.js") target.addExternalScript("resource/basic.js") target.noscript().h1("noscript").blink().text( "Please enable scripting support!") row = target.table("pageheader", width='100%').tr() left = row.td("left", valign='bottom', align='left') b = left.b() opera_class = "opera" if configuration.debug.IS_DEVELOPMENT: opera_class += " development" b.b(opera_class, onclick="location.href='/';").text("Opera") b.b("critic", onclick="location.href='/';").text("Critic") links = [] if not user.isAnonymous(): links.append(["home", "Home", None, None]) links.append(["dashboard", "Dashboard", None, None]) links.append(["branches", "Branches", None, None]) links.append(["search", "Search", None, None]) if user.hasRole(db, "administrator"): links.append(["services", "Services", None, None]) if user.hasRole(db, "repositories"): links.append(["repositories", "Repositories", None, None]) if profiler: profiler.check("generateHeader (basic)") if configuration.extensions.ENABLED: from extensions.extension import Extension updated = Extension.getUpdatedExtensions(db, user) if updated: link_title = "\n".join([ ("%s by %s can be updated!" % (extension_name, author_fullname)) for author_fullname, extension_name in updated ]) links.append([ "manageextensions", "Extensions (%d)" % len(updated), "color: red", link_title ]) else: links.append(["manageextensions", "Extensions", None, None]) if profiler: profiler.check("generateHeader (updated extensions)") links.append(["config", "Config", None, None]) links.append(["tutorial", "Tutorial", None, None]) if user.isAnonymous(): count = 0 else: cursor = db.cursor() cursor.execute( """SELECT COUNT(*) FROM newsitems LEFT OUTER JOIN newsread ON (item=id AND uid=%s) WHERE uid IS NULL""", (user.id, )) count = cursor.fetchone()[0] if count: links.append([ "news", "News (%d)" % count, "color: red", "There are %d unread news items!" % count ]) else: links.append(["news", "News", None, None]) if profiler: profiler.check("generateHeader (news)") req = target.getRequest() if configuration.base.AUTHENTICATION_MODE != "host" \ and configuration.base.SESSION_TYPE == "cookie": if user.isAnonymous(): links.append([ "javascript:void(location.href='/login?target='+encodeURIComponent(location.href));", "Sign in", None, None ]) elif not req or req.user == user.name: links.append(["javascript:signOut();", "Sign out", None, None]) for url, label in extra_links: links.append([url, label, None, None]) if req and configuration.extensions.ENABLED: import extensions.role.inject injected = {} extensions.role.inject.execute(db, req, user, target, links, injected, profiler=profiler) for url in injected.get("stylesheets", []): target.addExternalStylesheet(url, use_static=False, order=1) for url in injected.get("scripts", []): target.addExternalScript(url, use_static=False, order=1) else: injected = None ul = left.ul() for index, (url, label, style, title) in enumerate(links): if not re.match("[-.a-z]+:|/", url): url = "/" + url ul.li().a(href=url, style=style, title=title).text(label) rel = LINK_RELS.get(label) if rel: target.setLink(rel, url) right = row.td("right", valign='bottom', align='right') if generate_right: generate_right(right) else: right.div("buttons").span("buttonscope buttonscope-global") if profiler: profiler.check("generateHeader (finish)") return injected