From 030166f356b1c0267269981694608e2861d53c23 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 22 Apr 2010 08:12:04 +0200 Subject: [PATCH] Added the initial directory tree for the media library. --- scribeengine/controllers/media.py | 23 +++++++++----- .../scripts/jtree/themes/default/style.css | 1 + scribeengine/templates/media/index.mako | 31 +++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 scribeengine/templates/media/index.mako diff --git a/scribeengine/controllers/media.py b/scribeengine/controllers/media.py index 35f30d1..ba12036 100644 --- a/scribeengine/controllers/media.py +++ b/scribeengine/controllers/media.py @@ -29,24 +29,31 @@ from scribeengine.lib import utils from scribeengine.model import MediaType, File from scribeengine.model.meta import Session +try: + import json +except ImportError: + import simplejson as json + log = logging.getLogger(__name__) class MediaController(BaseController): - def _get_directories(self, parent=None, tree={}): + def _get_directories(self, parent=None, tree=[]): old_root = parent dirname = os.path.split(parent)[1] - tree[dirname] = {u'dirpath': parent, u'children': {}} + node = {'data': dirname, u'state': u'open', u'children': []} for root, dirs, files in os.walk(parent): if root != old_root: break for dirpath in dirs: full_dirpath = os.path.join(root, dirpath) - self._get_directories(full_dirpath, tree[dirname][u'children']) + self._get_directories(full_dirpath, node[u'children']) + tree.append(node) def index(self): - c.directories = {} - self._get_directories(config[u'paths.media'], c.directories) - pprint(c.directories) - return pformat(c.directories, indent=2) - #return render(u'/media/index.html') + self._add_javascript(u'jtree/jquery.tree.js') + directories = [] + self._get_directories(config[u'paths.media'], directories) + c.directories = json.dumps(directories) + #return pformat(c.directories, indent=2) + return render(u'/media/index.mako') diff --git a/scribeengine/public/scripts/jtree/themes/default/style.css b/scribeengine/public/scripts/jtree/themes/default/style.css index fab2676..8f58ce6 100644 --- a/scribeengine/public/scripts/jtree/themes/default/style.css +++ b/scribeengine/public/scripts/jtree/themes/default/style.css @@ -1,3 +1,4 @@ +.tree-default { font-family: "Lucida Grande", "Trebuchet MS", "Lucida Sans", "Arial", sans-serif; font-size: 80%; } /* LOCKED */ .tree-default .locked li a { color:gray; } /* DOTS */ diff --git a/scribeengine/templates/media/index.mako b/scribeengine/templates/media/index.mako new file mode 100644 index 0000000..63f7e70 --- /dev/null +++ b/scribeengine/templates/media/index.mako @@ -0,0 +1,31 @@ + + + + + ${c.page_title} +% for script in c.scripts: + +% endfor +% if c.jsinit: + +% endif + + +
+ + + \ No newline at end of file