]> git.phdru.name Git - m_librarian.git/commitdiff
Feat(web): Use CheetahTemplate
authorOleg Broytman <phd@phdru.name>
Sun, 1 Apr 2018 19:11:22 +0000 (22:11 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 1 Apr 2018 19:12:23 +0000 (22:12 +0300)
m_librarian/web/app.py
m_librarian/web/server.py
m_librarian/web/views/Makefile [new file with mode: 0644]
m_librarian/web/views/__init__.py [new file with mode: 0644]
m_librarian/web/views/index.py [new file with mode: 0644]
m_librarian/web/views/index.tmpl [new file with mode: 0644]
m_librarian/web/views/layout.py [new file with mode: 0644]
m_librarian/web/views/layout.tmpl [new file with mode: 0644]
setup.cfg
setup.py

index 01b15dd70f106fd3ec0d0cc856b582bcdec551a0..3a95c8bd701c67716d9423a8fb90a58405f7027c 100644 (file)
@@ -1,6 +1,7 @@
-from bottle import route
+from bottle import route, cheetah_view
 
 
 @route('/')
-def hello():
-    return "Hello World!"
+@cheetah_view('index.tmpl')
+def index():
+    return {}
index bc8e55220ab59f63ad8d57de7901d0a854624417..49c133f90e7686f1593a5303a62ee5985a94f030 100644 (file)
@@ -1,9 +1,10 @@
-from bottle import run
-
+import os
+import sys
 from wsgiref import simple_server
 from wsgiref.handlers import SimpleHandler
 from wsgiref.simple_server import WSGIServer
-from bottle import route
+
+from bottle import route, run
 
 simple_server.ServerHandler = SimpleHandler  # Stop logging to stdout
 
@@ -23,4 +24,7 @@ def quit():
 
 
 def run_server(host='localhost', port=0):
+    # Start here so that bottle can find templates
+    os.chdir(os.path.dirname(__file__))
+    sys.path.insert(0, os.getcwd())  # To import Cheetah templates
     run(host=host, port=port, server_class=QuitWSGIServer, debug=True)
diff --git a/m_librarian/web/views/Makefile b/m_librarian/web/views/Makefile
new file mode 100644 (file)
index 0000000..fc8b7be
--- /dev/null
@@ -0,0 +1,14 @@
+.SUFFIXES: # Clear the suffix list
+.SUFFIXES: .py .tmpl .html
+
+
+%.py: %.tmpl
+       cheetah compile --nobackup $< && compyle $@
+
+
+templates = $(shell echo *.tmpl)
+modules = $(patsubst %.tmpl,%.py,$(templates))
+
+
+.PHONY: all
+all: $(modules)
diff --git a/m_librarian/web/views/__init__.py b/m_librarian/web/views/__init__.py
new file mode 100644 (file)
index 0000000..792d600
--- /dev/null
@@ -0,0 +1 @@
+#
diff --git a/m_librarian/web/views/index.py b/m_librarian/web/views/index.py
new file mode 100644 (file)
index 0000000..9456a5e
--- /dev/null
@@ -0,0 +1,167 @@
+#!/usr/bin/env python
+
+
+
+
+##################################################
+## DEPENDENCIES
+import sys
+import os
+import os.path
+try:
+    import builtins as builtin
+except ImportError:
+    import __builtin__ as builtin
+from os.path import getmtime, exists
+import time
+import types
+from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
+from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
+from Cheetah.Template import Template
+from Cheetah.DummyTransaction import *
+from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
+from Cheetah.CacheRegion import CacheRegion
+import Cheetah.Filters as Filters
+import Cheetah.ErrorCatchers as ErrorCatchers
+from Cheetah.compat import unicode
+from views.layout import layout
+
+##################################################
+## MODULE CONSTANTS
+VFFSL=valueFromFrameOrSearchList
+VFSL=valueFromSearchList
+VFN=valueForName
+currentTime=time.time
+__CHEETAH_version__ = '3.1.0'
+__CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
+__CHEETAH_genTime__ = 1522609706.987582
+__CHEETAH_genTimestamp__ = 'Sun Apr  1 22:08:26 2018'
+__CHEETAH_src__ = 'index.tmpl'
+__CHEETAH_srcLastModified__ = 'Sun Apr  1 22:08:25 2018'
+__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
+
+if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
+    raise AssertionError(
+      'This template was compiled with Cheetah version'
+      ' %s. Templates compiled before version %s must be recompiled.'%(
+         __CHEETAH_version__, RequiredCheetahVersion))
+
+##################################################
+## CLASSES
+
+class index(layout):
+
+    ##################################################
+    ## CHEETAH GENERATED METHODS
+
+
+    def __init__(self, *args, **KWs):
+
+        super(index, self).__init__(*args, **KWs)
+        if not self._CHEETAH__instanceInitialized:
+            cheetahKWArgs = {}
+            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
+            for k,v in KWs.items():
+                if k in allowedKWs: cheetahKWArgs[k] = v
+            self._initCheetahInstance(**cheetahKWArgs)
+        
+
+    def body(self, **KWS):
+
+
+
+        ## CHEETAH: generated from #def body at line 3, col 1.
+        trans = KWS.get("trans")
+        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
+            trans = self.transaction # is None unless self.awake() was called
+        if not trans:
+            trans = DummyTransaction()
+            _dummyTrans = True
+        else: _dummyTrans = False
+        write = trans.response().write
+        SL = self._CHEETAH__searchList
+        _filter = self._CHEETAH__currentFilter
+        
+        ########################################
+        ## START - generated method body
+        
+        write(u'''<h1>Index</h1>
+
+<p>Hello, World!</p>
+
+<p><a href="/quit">Quit</a></p>
+''')
+        
+        ########################################
+        ## END - generated method body
+        
+        return _dummyTrans and trans.response().getvalue() or ""
+        
+
+    def writeBody(self, **KWS):
+
+
+
+        ## CHEETAH: main method generated for this template
+        trans = KWS.get("trans")
+        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
+            trans = self.transaction # is None unless self.awake() was called
+        if not trans:
+            trans = DummyTransaction()
+            _dummyTrans = True
+        else: _dummyTrans = False
+        write = trans.response().write
+        SL = self._CHEETAH__searchList
+        _filter = self._CHEETAH__currentFilter
+        
+        ########################################
+        ## START - generated method body
+        
+        
+        ########################################
+        ## END - generated method body
+        
+        return _dummyTrans and trans.response().getvalue() or ""
+        
+    ##################################################
+    ## CHEETAH GENERATED ATTRIBUTES
+
+
+    _CHEETAH__instanceInitialized = False
+
+    _CHEETAH_version = __CHEETAH_version__
+
+    _CHEETAH_versionTuple = __CHEETAH_versionTuple__
+
+    _CHEETAH_genTime = __CHEETAH_genTime__
+
+    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
+
+    _CHEETAH_src = __CHEETAH_src__
+
+    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
+
+    title = 'Index'
+
+    _mainCheetahMethod_for_index = 'writeBody'
+
+## END CLASS DEFINITION
+
+if not hasattr(index, '_initCheetahAttributes'):
+    templateAPIClass = getattr(index,
+                               '_CHEETAH_templateClass',
+                               Template)
+    templateAPIClass._addCheetahPlumbingCodeToClass(index)
+
+
+# CHEETAH was developed by Tavis Rudd and Mike Orr
+# with code, advice and input from many other volunteers.
+# For more information visit http://cheetahtemplate.org/
+
+##################################################
+## if run from command line:
+if __name__ == '__main__':
+    from Cheetah.TemplateCmdLineIface import CmdLineIface
+    CmdLineIface(templateObj=index()).run()
+
+
diff --git a/m_librarian/web/views/index.tmpl b/m_librarian/web/views/index.tmpl
new file mode 100644 (file)
index 0000000..9832186
--- /dev/null
@@ -0,0 +1,9 @@
+#extends views.layout
+#attr $title = 'Index'
+#def body
+<h1>Index</h1>
+
+<p>Hello, World!</p>
+
+<p><a href="/quit">Quit</a></p>
+#end def
diff --git a/m_librarian/web/views/layout.py b/m_librarian/web/views/layout.py
new file mode 100644 (file)
index 0000000..f8ba1b2
--- /dev/null
@@ -0,0 +1,158 @@
+#!/usr/bin/env python
+
+
+
+
+##################################################
+## DEPENDENCIES
+import sys
+import os
+import os.path
+try:
+    import builtins as builtin
+except ImportError:
+    import __builtin__ as builtin
+from os.path import getmtime, exists
+import time
+import types
+from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
+from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
+from Cheetah.Template import Template
+from Cheetah.DummyTransaction import *
+from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
+from Cheetah.CacheRegion import CacheRegion
+import Cheetah.Filters as Filters
+import Cheetah.ErrorCatchers as ErrorCatchers
+from Cheetah.compat import unicode
+
+##################################################
+## MODULE CONSTANTS
+VFFSL=valueFromFrameOrSearchList
+VFSL=valueFromSearchList
+VFN=valueForName
+currentTime=time.time
+__CHEETAH_version__ = '3.1.0'
+__CHEETAH_versionTuple__ = (3, 1, 0, 'final', 1)
+__CHEETAH_genTime__ = 1522609587.049776
+__CHEETAH_genTimestamp__ = 'Sun Apr  1 22:06:27 2018'
+__CHEETAH_src__ = 'layout.tmpl'
+__CHEETAH_srcLastModified__ = 'Sun Apr  1 22:06:06 2018'
+__CHEETAH_docstring__ = 'Autogenerated by Cheetah: The Python-Powered Template Engine'
+
+if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
+    raise AssertionError(
+      'This template was compiled with Cheetah version'
+      ' %s. Templates compiled before version %s must be recompiled.'%(
+         __CHEETAH_version__, RequiredCheetahVersion))
+
+##################################################
+## CLASSES
+
+class layout(Template):
+
+    ##################################################
+    ## CHEETAH GENERATED METHODS
+
+
+    def __init__(self, *args, **KWs):
+
+        super(layout, self).__init__(*args, **KWs)
+        if not self._CHEETAH__instanceInitialized:
+            cheetahKWArgs = {}
+            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
+            for k,v in KWs.items():
+                if k in allowedKWs: cheetahKWArgs[k] = v
+            self._initCheetahInstance(**cheetahKWArgs)
+        
+
+    def respond(self, trans=None):
+
+
+
+        ## CHEETAH: main method generated for this template
+        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
+            trans = self.transaction # is None unless self.awake() was called
+        if not trans:
+            trans = DummyTransaction()
+            _dummyTrans = True
+        else: _dummyTrans = False
+        write = trans.response().write
+        SL = self._CHEETAH__searchList
+        _filter = self._CHEETAH__currentFilter
+        
+        ########################################
+        ## START - generated method body
+        
+        write(u'''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+   "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!-- THIS PAGE IS AUTOMATICALLY GENERATED USING CheetahTemplate. DO NOT EDIT. -->
+<head>
+<meta HTTP-Equiv="Content-Type" content="text/html">
+<title>''')
+        _v = VFFSL(SL,"title",True) # u'$title' on line 8, col 8
+        if _v is not None: write(_filter(_v, rawExpr=u'$title')) # from line 8, col 8.
+        write(u'''</title>
+<meta name="author" content="Oleg Broytman">
+<meta name="copyright" content="&copy; 2018 PhiloSoft Design">
+<link rev="made" href="mailto:phd@phdru.name">
+<meta name="generator" content="CheetahTemplate">
+<meta name="MSSmartTagsPreventParsing" content="TRUE"> <!-- MUST DIE -->
+</head>
+<body bgcolor="#CCCCCC" text="#000000"
+      link="#0000bb"  vlink="#551a8b" alink="#ff0000">
+''')
+        _v = VFFSL(SL,"body",True) # u'$body' on line 17, col 1
+        if _v is not None: write(_filter(_v, rawExpr=u'$body')) # from line 17, col 1.
+        write(u'''
+</body>
+</html>
+''')
+        
+        ########################################
+        ## END - generated method body
+        
+        return _dummyTrans and trans.response().getvalue() or ""
+        
+    ##################################################
+    ## CHEETAH GENERATED ATTRIBUTES
+
+
+    _CHEETAH__instanceInitialized = False
+
+    _CHEETAH_version = __CHEETAH_version__
+
+    _CHEETAH_versionTuple = __CHEETAH_versionTuple__
+
+    _CHEETAH_genTime = __CHEETAH_genTime__
+
+    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
+
+    _CHEETAH_src = __CHEETAH_src__
+
+    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
+
+    title = ''
+
+    _mainCheetahMethod_for_layout = 'respond'
+
+## END CLASS DEFINITION
+
+if not hasattr(layout, '_initCheetahAttributes'):
+    templateAPIClass = getattr(layout,
+                               '_CHEETAH_templateClass',
+                               Template)
+    templateAPIClass._addCheetahPlumbingCodeToClass(layout)
+
+
+# CHEETAH was developed by Tavis Rudd and Mike Orr
+# with code, advice and input from many other volunteers.
+# For more information visit http://cheetahtemplate.org/
+
+##################################################
+## if run from command line:
+if __name__ == '__main__':
+    from Cheetah.TemplateCmdLineIface import CmdLineIface
+    CmdLineIface(templateObj=layout()).run()
+
+
diff --git a/m_librarian/web/views/layout.tmpl b/m_librarian/web/views/layout.tmpl
new file mode 100644 (file)
index 0000000..60da30e
--- /dev/null
@@ -0,0 +1,19 @@
+#attr $title = ''
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+   "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<!-- THIS PAGE IS AUTOMATICALLY GENERATED USING CheetahTemplate. DO NOT EDIT. -->
+<head>
+<meta HTTP-Equiv="Content-Type" content="text/html">
+<title>$title</title>
+<meta name="author" content="Oleg Broytman">
+<meta name="copyright" content="&copy; 2018 PhiloSoft Design">
+<link rev="made" href="mailto:phd@phdru.name">
+<meta name="generator" content="CheetahTemplate">
+<meta name="MSSmartTagsPreventParsing" content="TRUE"> <!-- MUST DIE -->
+</head>
+<body bgcolor="#CCCCCC" text="#000000"
+      link="#0000bb"  vlink="#551a8b" alink="#ff0000">
+$body
+</body>
+</html>
index 48b6211a4c0e5be2cce2fa76bd683de0edeae22f..39c17d20892872cf5a78fa5425e616d3eef3268d 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -11,5 +11,5 @@ tag_date = 0
 tag_svn_revision = 0
 
 [flake8]
-exclude = .git,.tox,docs/conf.py,docs-ru/conf.py
+exclude = .git,.tox,docs/conf.py,docs-ru/conf.py,m_librarian/web/views
 
index d342061cd631375e121120fb80f50055f5db3bdf..3ba68821ad18303f3abf93b913c4f7f6c5e2be0b 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -59,9 +59,7 @@ setup(name='m_librarian',
           'm_lib.defenc>=1.0',
       ],
       extras_require={
-          'm_lib': ['m_lib>=3.1'],
           'pbar': ['m_lib>=3.1'],
-          'web': ['bottle'],
-          'bottle': ['bottle'],
+          'web': ['bottle', 'Cheetah3'],
       },
       )