From: Michael Tremer Date: Sun, 18 Oct 2015 01:42:59 +0000 (+0200) Subject: Add a very basic website template X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fwestferry.git;a=commitdiff_plain;h=95da2e8693d5fe509661011b65b5758277e9beb9 Add a very basic website template Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 664a197..8fa2863 100644 --- a/Makefile.am +++ b/Makefile.am @@ -109,15 +109,38 @@ westferry_handlersdir = $(pythondir)/westferry/handlers westferry_ui_PYTHON = \ src/westferry/ui/__init__.py \ - src/westferry/ui/base.py + src/westferry/ui/base.py \ + src/westferry/ui/menu.py \ + src/westferry/ui/utils.py westferry_uidir = $(pythondir)/westferry/ui +# - templates ------------------------------------------------------------------ + +templatesdir = $(datadir)/westferry/templates + +dist_templates_DATA = \ + src/templates/base.html + +templates_modulesdir = $(templatesdir)/modules + +templates_modules_menudir = $(templates_modulesdir)/menu + +dist_templates_modules_menu_DATA = \ + src/templates/modules/menu/sidebar.html + +ui_modulesdir = $(datadir)/westferry/templates/modules + +ui_modules_DATA = + +dist_webroot_css_DATA = \ + src/styles/westferry.css + # - third party ---------------------------------------------------------------- # We currently ship a copy of Bootstrap which eventually has to go away -dist_webroot_css_DATA = \ +dist_webroot_css_DATA += \ src/third-party/bootstrap/css/bootstrap.min.css EXTRA_DIST += \ @@ -144,7 +167,7 @@ EXTRA_DIST += \ # Also shipping jQuery -dist_webroot_scripts_DATA = \ +dist_webroot_scripts_DATA += \ src/third-party/jquery.min.js # ------------------------------------------------------------------------------ @@ -221,6 +244,7 @@ substitutions = \ '|configsdir=$(configsdir)|' \ '|bindir=$(bindir)|' \ '|datadir=$(datadir)|' \ + '|templatesdir=$(templatesdir)|' \ '|webrootdir=$(webrootdir)|' SED_PROCESS = \ diff --git a/src/styles/westferry.css b/src/styles/westferry.css new file mode 100644 index 0000000..348ac98 --- /dev/null +++ b/src/styles/westferry.css @@ -0,0 +1,70 @@ +/* + * Base structure + */ + +/* Move down content because we have a fixed navbar that is 50px tall */ +body { + padding-top: 50px; +} + +/* + * Global add-ons + */ + +.sub-header { + padding-bottom: 10px; + border-bottom: 1px solid #eee; +} + +/* + * Top navigation + * Hide default border to remove 1px line. + */ +.navbar-fixed-top { + border: 0; +} + +/* + * Main content + */ + +.main { + padding: 20px; +} + +@media (min-width: 768px) { + .main { + padding-right: 40px; + padding-left: 40px; + } +} + +.main .page-header { + margin-top: 0; +} + +/* Make sidebar nav vertical */ +@media (min-width: 768px) { + .sidebar-nav .navbar .navbar-collapse { + padding: 0; + max-height: none; + } + + .sidebar-nav .navbar ul { + float: none; + } + + .sidebar-nav .navbar ul:not { + display: block; + } + + .sidebar-nav .navbar li { + float: none; + display: block; + } + + .sidebar-nav .navbar li a { + padding-top: 12px; + padding-bottom: 12px; + } +} diff --git a/src/templates/base.html b/src/templates/base.html new file mode 100644 index 0000000..72be9a6 --- /dev/null +++ b/src/templates/base.html @@ -0,0 +1,60 @@ + + + + + + + + + + + + + Dashboard Template for Bootstrap + + + + + + + + +
+
+
+ {% module SidebarMenu() %} +
+ +
+ {% block main %} +

Dashboard

+ {% end %} +
+
+
+ + + + + diff --git a/src/templates/modules/menu/sidebar.html b/src/templates/modules/menu/sidebar.html new file mode 100644 index 0000000..b4829be --- /dev/null +++ b/src/templates/modules/menu/sidebar.html @@ -0,0 +1,34 @@ + diff --git a/src/westferry/application.py b/src/westferry/application.py index 10ef9d6..06acd8c 100644 --- a/src/westferry/application.py +++ b/src/westferry/application.py @@ -35,6 +35,9 @@ class WebApplication(tornado.web.Application): # Serve static files from our webroot "static_path" : WEBROOTDIR, + # Templates + "template_path" : TEMPLATESDIR, + # Use Cross-Site-Request-Forgery protection "xsrf_cookies" : True, } diff --git a/src/westferry/constants.py.in b/src/westferry/constants.py.in index f405dc8..46b4de3 100644 --- a/src/westferry/constants.py.in +++ b/src/westferry/constants.py.in @@ -19,4 +19,5 @@ # # ############################################################################### +TEMPLATESDIR = "@templatesdir@" WEBROOTDIR = "@webrootdir@" diff --git a/src/westferry/handlers/index.py b/src/westferry/handlers/index.py index 3edf7bc..6198568 100644 --- a/src/westferry/handlers/index.py +++ b/src/westferry/handlers/index.py @@ -25,4 +25,4 @@ class IndexHandler(base.BaseHandler): url = r"/" def get(self): - self.finish("Hello World") + self.render("base.html") diff --git a/src/westferry/ui/__init__.py b/src/westferry/ui/__init__.py index a7641dd..40b0745 100644 --- a/src/westferry/ui/__init__.py +++ b/src/westferry/ui/__init__.py @@ -20,6 +20,8 @@ ############################################################################### from . import base +from . import menu +from . import utils def get_ui_methods(): """ diff --git a/src/westferry/ui/menu.py b/src/westferry/ui/menu.py new file mode 100644 index 0000000..dbbdb99 --- /dev/null +++ b/src/westferry/ui/menu.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 +############################################################################### +# # +# Westferry - The IPFire web user interface # +# Copyright (C) 2015 IPFire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +from . import base + +class SidebarMenuModule(base.BaseUIModule): + def render(self): + return self.render_string("modules/menu/sidebar.html") diff --git a/src/westferry/ui/utils.py b/src/westferry/ui/utils.py new file mode 100644 index 0000000..ea1be18 --- /dev/null +++ b/src/westferry/ui/utils.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +############################################################################### +# # +# Westferry - The IPFire web user interface # +# Copyright (C) 2015 IPFire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import socket + +from . import base + +class HostnameMethod(base.BaseUIMethod): + """ + This method returns the hostname of this system. + """ + + handle = "hostname" + + def __call__(self, handler): + return socket.gethostname()