Started working on the display of the files.

This commit is contained in:
Raoul Snyman 2010-04-30 00:44:58 +02:00
commit 310cff88bc
7 changed files with 201 additions and 34 deletions

View File

@ -22,25 +22,51 @@
import os
import logging
from pprint import pprint, pformat
from scribeengine.lib.base import *
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={}):
if not parent:
parent = config[u'paths.media']
for dirpath in os.listdir(parent):
if os.path.isdir(dirpath):
tree[os.path.abspath(dirpath)] = {u'path': dirpath, u'children': {}}
self._get_directories(os.path.abspath(dirpath),
tree[os.path.abspath(dirpath)][u'children'])
def __before__(self):
BaseController.__before__(self)
self._add_javascript('ScribeEngine.Media.js')
def _get_directories(self, parent=None, tree=[]):
old_root = parent
dirname = os.path.split(parent)[1]
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, node[u'children'])
tree.append(node)
def _get_files(self, dirpath):
for root, dirs, files in os.walk(os.path.abspath(dirpath)):
return files
break
def index(self):
c.directories = self._get_directories()
return render(u'/media/index.html')
self._add_javascript(u'jtree/jquery.tree.js')
directories = []
path = os.path.join(config[u'paths.media'], u'user%s' % c.current_user.id)
if not os.path.exists(path):
os.makedirs(path)
self._get_directories(path, directories)
c.directories = json.dumps(directories)
c.files = self._get_files(path)
#return pformat(c.directories, indent=2)
return render(u'/media/index.mako')

View File

@ -244,7 +244,7 @@ def authenticate(permission=None):
session[u'redirect_url'] = request.environ[u'PATH_INFO']
session.save()
h.flash.set_message(u'You need to be logged in to do that.', u'error')
h.redirect_to('/admin/login')
h.redirect_to('/account/login')
return decorator(validate)

View File

@ -0,0 +1,39 @@
/*****************************************************************************
* ScribeEngine - Open Source Blog Software *
* ------------------------------------------------------------------------- *
* Copyright (c) 2010 Raoul Snyman *
* ------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
* Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
*****************************************************************************/
ScribeEngine.Namespace.create("ScribeEngine.Media", {
new_directory: function ()
{
var dirname = prompt("New Directory:", "directory");
},
get_files: function (node, tree)
{
tree_string = "";
while (node)
{
alert($(tree.get_node(node)).text());
node = tree.parent(node);
}
}
});
ScribeEngine.Events.load(function () {
ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.new_directory);
ScribeEngine.Events.click("#file-select", window.close);
});

View File

@ -23,15 +23,5 @@ ScribeEngine.Namespace.create("ScribeEngine.Post", {
ScribeEngine.Events.load(function () {
ScribeEngine.Widgets.tagEditor("#post-tags");
$('textarea').tinymce({
script_url: "/scripts/tinymce/tiny_mce.js",
theme: "advanced",
dialog_type: "modal",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: true,
theme_advanced_resize_horizontal: false
});
ScribeEngine.Widgets.tinymce("textarea");
});

View File

@ -119,18 +119,81 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", {
/**
* Adds a datepicker to an element.
*/
datepicker: function (selector)
{
$(selector).datepicker({showButtonPanel: true, dateFormat: "dd/mm/yy"});
},
tagEditor: function (selector)
{
$(selector).tagEditor({completeOnBlur: true, initialParse: true});
},
elastic: function (selector)
{
$(selector).elastic();
}
datepicker: function (selector)
{
$(selector).datepicker({showButtonPanel: true, dateFormat: "dd/mm/yy"});
},
tagEditor: function (selector)
{
$(selector).tagEditor({completeOnBlur: true, initialParse: true});
},
elastic: function (selector)
{
$(selector).elastic();
},
fileBrowser: function (field_name, url, type, win)
{
alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
var cmsURL = window.location.toString(); // script URL - use an absolute path!
if (cmsURL.indexOf("?") < 0)
{
//add the type as the only query parameter
cmsURL = cmsURL + "?type=" + type;
}
else
{
//add the type as an additional query parameter
// (PHP session ID is now included if there is one at all)
cmsURL = cmsURL + "&type=" + type;
}
tinyMCE.activeEditor.windowManager.open(
{
file: "/media",
title: "Media Library",
width: 600, // Your dimensions may differ - toy around with them!
height: 400,
resizable: "yes",
inline: "yes", // This parameter only has an effect if you use the inlinepopups plugin!
close_previous: "no"
},
{
window: win,
input: field_name
}
);
return false;
},
tinymce: function (selector)
{
$(selector).tinymce({
script_url: "/scripts/tinymce/tiny_mce.js",
theme: "advanced",
dialog_type: "modal",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: true,
theme_advanced_resize_horizontal: false,
file_browser_callback: "ScribeEngine.Widgets.fileBrowser"
});
},
tree: function (selector, data, onselect)
{
$(selector).tree({
data:
{
type: "json",
opts:
{
static: data
}
},
callback:
{
onselect: onselect
}
});
}
});
ScribeEngine.Namespace.create("ScribeEngine.General", {

View File

@ -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 */

View File

@ -0,0 +1,48 @@
<!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
<style type="text/css">
body { margin: 0; padding: 0; }
#directory-tree { border-right: 1px solid #999; border-bottom: 1px solid #999; height: 370px; float: left; padding-right: 4px; width: 195px; }
#file-list { border-bottom: 1px solid #999; height: 370px; padding-left: 4px; float: left; width: 396px; }
#button-bar { clear: both; height: 30px; line-height: 30px; }
#file-list ul { list-style: none; margin: 0; padding: 0; }
#file-list ul li { float: left; }
#file-list ul li div.file { border: 1px solid #f0f0f0; height: 87px; line-height: 87px; list-style: none; margin: 5px; padding: 0; width: 87px; }
#file-list ul li div.caption { font-size: 8pt; text-align: center; width: 89px; }
</style>
</head>
<body>
<div id="directory-tree"></div>
<div id="file-list">
<ul>
% for filename in c.files:
<li>
<div class="file">&nbsp;</div>
% if len(filename) > 15:
<div class="caption" title="${filename}">${filename[:12]}...</div>
% else:
<div class="caption">${filename}</div>
% endif
</li>
% endfor
</ul>
</div>
<div id="button-bar">
<input type="button" id="new-directory" value="New Directory"/>
<input type="button" id="file-select" value="Select"/>
</div>
<script type="text/javascript">
ScribeEngine.Widgets.tree("#directory-tree", ${c.directories | n}, ScribeEngine.Media.get_files);
</script>
</body>
</html>