Added the initial directory tree for the media library.
This commit is contained in:
parent
1ea6a3396f
commit
030166f356
@ -29,24 +29,31 @@ from scribeengine.lib import utils
|
|||||||
from scribeengine.model import MediaType, File
|
from scribeengine.model import MediaType, File
|
||||||
from scribeengine.model.meta import Session
|
from scribeengine.model.meta import Session
|
||||||
|
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
except ImportError:
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class MediaController(BaseController):
|
class MediaController(BaseController):
|
||||||
|
|
||||||
def _get_directories(self, parent=None, tree={}):
|
def _get_directories(self, parent=None, tree=[]):
|
||||||
old_root = parent
|
old_root = parent
|
||||||
dirname = os.path.split(parent)[1]
|
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):
|
for root, dirs, files in os.walk(parent):
|
||||||
if root != old_root:
|
if root != old_root:
|
||||||
break
|
break
|
||||||
for dirpath in dirs:
|
for dirpath in dirs:
|
||||||
full_dirpath = os.path.join(root, dirpath)
|
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):
|
def index(self):
|
||||||
c.directories = {}
|
self._add_javascript(u'jtree/jquery.tree.js')
|
||||||
self._get_directories(config[u'paths.media'], c.directories)
|
directories = []
|
||||||
pprint(c.directories)
|
self._get_directories(config[u'paths.media'], directories)
|
||||||
return pformat(c.directories, indent=2)
|
c.directories = json.dumps(directories)
|
||||||
#return render(u'/media/index.html')
|
#return pformat(c.directories, indent=2)
|
||||||
|
return render(u'/media/index.mako')
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
.tree-default { font-family: "Lucida Grande", "Trebuchet MS", "Lucida Sans", "Arial", sans-serif; font-size: 80%; }
|
||||||
/* LOCKED */
|
/* LOCKED */
|
||||||
.tree-default .locked li a { color:gray; }
|
.tree-default .locked li a { color:gray; }
|
||||||
/* DOTS */
|
/* DOTS */
|
||||||
|
31
scribeengine/templates/media/index.mako
Normal file
31
scribeengine/templates/media/index.mako
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||||
|
<title>${c.page_title}</title>
|
||||||
|
% for script in c.scripts:
|
||||||
|
<script src="/scripts/${script}" type="text/javascript"></script>
|
||||||
|
% endfor
|
||||||
|
% if c.jsinit:
|
||||||
|
<script src="/scripts/${c.jsinit}" type="text/javascript"></script>
|
||||||
|
% endif
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="directory-tree" style="border: 1px solid #999; height: 400px; width: 200px;"></div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#directory-tree").tree(
|
||||||
|
{
|
||||||
|
data:
|
||||||
|
{
|
||||||
|
type: "json",
|
||||||
|
opts:
|
||||||
|
{
|
||||||
|
static : ${c.directories | n}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user