From 7163dfa3d0252067de90e8c088ea90d0b0f7d059 Mon Sep 17 00:00:00 2001
From: Elena ``of Valhalla'' Grandi <valhalla@trueelena.org>
Date: Sun, 29 Oct 2017 14:54:38 +0100
Subject: Load a collection from command line and show a list of items

---
 cherry_lesana/app.py                   | 25 +++++++++++++++++++++++++
 cherry_lesana/data/static/style.css    |  0
 cherry_lesana/data/templates/base.html | 14 ++++++++++++++
 cherry_lesana/data/templates/list.html | 10 ++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 cherry_lesana/data/static/style.css
 create mode 100644 cherry_lesana/data/templates/base.html
 create mode 100644 cherry_lesana/data/templates/list.html

(limited to 'cherry_lesana')

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
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 %}
-- 
cgit v1.2.3