diff options
-rw-r--r-- | cherry_lesana/app.py | 25 | ||||
-rw-r--r-- | cherry_lesana/data/static/style.css | 0 | ||||
-rw-r--r-- | cherry_lesana/data/templates/base.html | 14 | ||||
-rw-r--r-- | cherry_lesana/data/templates/list.html | 10 | ||||
-rwxr-xr-x | clesana | 21 | ||||
-rw-r--r-- | tests/data/simple/.gitignore | 1 | ||||
-rw-r--r-- | tests/data/simple/items/11189ee47ddf4796b718a483b379f976.yaml | 3 | ||||
-rw-r--r-- | tests/data/simple/settings.yaml | 20 | ||||
-rw-r--r-- | tests/test_views.py | 25 |
9 files changed, 116 insertions, 3 deletions
diff --git a/cherry_lesana/app.py b/cherry_lesana/app.py index 4ab7672..6670dcb 100644 --- a/cherry_lesana/app.py +++ b/cherry_lesana/app.py @@ -1,13 +1,38 @@ import cherrypy +import jinja2 class App: """ """ + def __init__(self, collection=None): + self.collection = collection + self.j_env = jinja2.Environment( + loader=jinja2.PackageLoader('cherry_lesana', 'data/templates'), + autoescape=jinja2.select_autoescape(['html', 'xml'], default=True), + ) @cherrypy.expose def index(self): cherrypy.log('asd') return "Hello World" + @cherrypy.expose + def list(self): + """Show a list of items in the current collection""" + if not self.collection: + return "No collection loaded" + template = self.j_env.get_template('list.html') + # TODO: paginate + items = self.collection.get_all_documents() + return template.render( + collection=self.collection, + items=items, + ) + + +class Item: + """ + Work on the contents of an item + """ diff --git a/cherry_lesana/data/static/style.css b/cherry_lesana/data/static/style.css new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/cherry_lesana/data/static/style.css diff --git a/cherry_lesana/data/templates/base.html b/cherry_lesana/data/templates/base.html new file mode 100644 index 0000000..232a76e --- /dev/null +++ b/cherry_lesana/data/templates/base.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> + <head> + <title>{% block title %}{% endblock %}</title> + <link rel="stylesheet" href="/static/style.css" /> + {% block head %} + {% endblock %} + </head> + <body> + <div id="content">{% block content %}{% endblock %}</div> + <div id="footer"> + </div> + </body> +</html> diff --git a/cherry_lesana/data/templates/list.html b/cherry_lesana/data/templates/list.html new file mode 100644 index 0000000..2fbe14c --- /dev/null +++ b/cherry_lesana/data/templates/list.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} +{% block title %}CherryLesana{% endblock %} +{% block content %} +<h1>{{ collection.settings.name }}</h1> +<ul> + {% for item in items %} + <li>{{ item }}</li> + {% endfor %} +</ul> +{% endblock %} @@ -1,16 +1,35 @@ #!/usr/bin/env python3 +import sys + +import lesana import cherrypy import cherry_lesana as cl +from pkg_resources import resource_filename + def main(): # TODO: read config from a file or something config = { '/': { + 'tools.staticdir.root': resource_filename( + 'cherry_lesana', + 'data', + ) }, + '/static': { + 'tools.staticdir.on': True, + 'tools.staticdir.dir': 'static', + } } - cherrypy.quickstart(cl.App(), '/', config) + # TODO: properly read command line args + try: + collection = lesana.Collection(sys.argv[1]) + except IndexError: + collection = None + app = cl.App(collection) + cherrypy.quickstart(app, '/', config) if __name__ == '__main__': main() diff --git a/tests/data/simple/.gitignore b/tests/data/simple/.gitignore new file mode 100644 index 0000000..17f377f --- /dev/null +++ b/tests/data/simple/.gitignore @@ -0,0 +1 @@ +.lesana diff --git a/tests/data/simple/items/11189ee47ddf4796b718a483b379f976.yaml b/tests/data/simple/items/11189ee47ddf4796b718a483b379f976.yaml new file mode 100644 index 0000000..e1f7fc1 --- /dev/null +++ b/tests/data/simple/items/11189ee47ddf4796b718a483b379f976.yaml @@ -0,0 +1,3 @@ +name: Another item +description: with just a short description +position: somewhere diff --git a/tests/data/simple/settings.yaml b/tests/data/simple/settings.yaml new file mode 100644 index 0000000..20f35d8 --- /dev/null +++ b/tests/data/simple/settings.yaml @@ -0,0 +1,20 @@ +name: "Simple lesana collection" +lang: 'english' +entry_label: '{{ uid }}: {{ name }}' +fields: + - name: name + type: string + index: free + - name: description + type: text + index: free + - name: position + type: string + index: facet + - name: quantity + type: integer + index: no + help: 'how many items are there' + - name: other + type: yaml + help: '' diff --git a/tests/test_views.py b/tests/test_views.py index 9c0c471..efb87bf 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,11 +1,12 @@ -import cherrypy +from lesana import Collection +import cherrypy from cherrypy.test import helper from cherry_lesana import App -class TestViews(helper.CPWebCase): +class TestNoCollection(helper.CPWebCase): def setup_server(): cherrypy.tree.mount(App()) setup_server = staticmethod(setup_server) @@ -13,3 +14,23 @@ class TestViews(helper.CPWebCase): def test_root(self): self.getPage('/') self.assertStatus(200) + + def test_list(self): + self.getPage('/list') + self.assertStatus(200) + self.assertInBody('No collection loaded') + + +class TestSimpleCollection(helper.CPWebCase): + def setup_server(): + collection = Collection('tests/data/simple') + collection.update_cache() + cherrypy.tree.mount(App(Collection('tests/data/simple'))) + setup_server = staticmethod(setup_server) + + def test_list(self): + self.getPage('/list') + self.assertStatus(200) + self.assertNotInBody('No collection loaded') + self.assertInBody('Simple lesana collection') + self.assertInBody('Another item') |