From 2090d0909e990711867e8acb7ab584fa0f8b6a3c Mon Sep 17 00:00:00 2001 From: ianb Date: Wed, 20 Jul 2005 03:35:27 +0000 Subject: Made the WYSIWYG editor more customizable; added cancel links; added delete function; added search function; added function to add new pages based on 'blank' templates --- examples/filebrowser/pathobj.py | 49 +++++++++++++++++++++++++- examples/filebrowser/templates/addfile_form.pt | 13 +++++++ examples/filebrowser/templates/directory.pt | 9 +++++ examples/filebrowser/templates/edit_html.pt | 3 +- examples/filebrowser/templates/edit_text.pt | 1 - examples/filebrowser/templates/view_file.pt | 3 ++ examples/filebrowser/web/__init__.py | 3 +- examples/filebrowser/web/addfile_form.py | 10 ++++++ 8 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 examples/filebrowser/templates/addfile_form.pt create mode 100644 examples/filebrowser/web/addfile_form.py (limited to 'examples') diff --git a/examples/filebrowser/pathobj.py b/examples/filebrowser/pathobj.py index bee2628..aeda780 100644 --- a/examples/filebrowser/pathobj.py +++ b/examples/filebrowser/pathobj.py @@ -27,8 +27,9 @@ class PathContext(object): path_classes = {} - def __init__(self, root): + def __init__(self, root, config): self.root = root + self.config = config def path(self, path): filename = self.root + '/' + path.lstrip('/') @@ -57,6 +58,23 @@ class PathContext(object): ptype)) cls.path_classes[ptype] = path_class + def stylesheets(self): + if self.config.get('stylesheet'): + value = self.config['stylesheet'] + else: + value = [] + if isinstance(value, (str, unicode)): + value = [value] + return [self.path(p) for p in value] + + def translate_path(self, path): + possible = self.config.get('live_web_translation', {}).items() + possible.sort(lambda a, b: cmp(len(a[0]), len(b[0]))) + for source, dest in possible: + if path.startswith(source): + return dest + path[len(source):] + return None + class Path(sitepage.SitePage): extensions = ['*'] @@ -126,6 +144,12 @@ class Path(sitepage.SitePage): self.write(f.read()) f.close() + def action_delete(self): + parent = self.pathurl.up() + os.unlink(self.filename) + self.message.write('%s deleted' % self.basename) + self.redirect(parent, action='view') + def join(self, name): parts = name.split('/') for part in parts: @@ -147,6 +171,9 @@ class Path(sitepage.SitePage): new_path += name return self.pathcontext.path(new_path) + def live_url(self): + return self.pathcontext.translate_path(self.path) + bad_regexes = [ re.compile(r'', re.I+re.S), re.compile(r'style="[^"]*position:.*?"', re.I+re.S), @@ -441,6 +468,26 @@ class Dir(Path): self.message.write('Created directory %s' % dest) self.redirect(self.pathurl(dest.path, action='view')) + def action_create_from_blank(self): + tmpl = self.fields.template + filename = self.fields.filename + good = True + if not tmpl: + self.message.write('You must select a blank template') + good = False + if not filename: + self.message.write('You must give a filename') + good = False + if not good: + self.redirect(self.pathurl(action='view')) + if not os.path.splitext(filename)[1]: + filename += os.path.splitext(tmpl)[1] + source = self.pathcontext.path(tmpl) + dest = self.join(filename) + dest.write_text(source.read()) + self.message.write('%s created' % dest.basename) + self.redirect(self.pathurl(dest.path, action='edit')) + def listdir(self): result = [] for fn in os.listdir(self.filename): diff --git a/examples/filebrowser/templates/addfile_form.pt b/examples/filebrowser/templates/addfile_form.pt new file mode 100644 index 0000000..e75275e --- /dev/null +++ b/examples/filebrowser/templates/addfile_form.pt @@ -0,0 +1,13 @@ +
+ +Create from: + +in: + + +
diff --git a/examples/filebrowser/templates/directory.pt b/examples/filebrowser/templates/directory.pt index 212e77e..cf57072 100644 --- a/examples/filebrowser/templates/directory.pt +++ b/examples/filebrowser/templates/directory.pt @@ -47,6 +47,15 @@ function change_upload_button() { + | + + + ... + + + diff --git a/examples/filebrowser/templates/edit_html.pt b/examples/filebrowser/templates/edit_html.pt index 03d8dbd..74afda0 100644 --- a/examples/filebrowser/templates/edit_html.pt +++ b/examples/filebrowser/templates/edit_html.pt @@ -12,13 +12,12 @@ xinha_editors = ['txt-content'];
-Edit:
+ value prop/value" style="width: 100%">
name
diff --git a/examples/filebrowser/templates/edit_text.pt b/examples/filebrowser/templates/edit_text.pt index 26ab12d..b730ae7 100644 --- a/examples/filebrowser/templates/edit_text.pt +++ b/examples/filebrowser/templates/edit_text.pt @@ -48,7 +48,6 @@ function find_text(txt_id, input_id) { -Edit:
diff --git a/examples/filebrowser/templates/view_file.pt b/examples/filebrowser/templates/view_file.pt index 78a01c4..6f6dae6 100644 --- a/examples/filebrowser/templates/view_file.pt +++ b/examples/filebrowser/templates/view_file.pt @@ -17,6 +17,9 @@ Mimetype: | edit | rename +| delete

diff --git a/examples/filebrowser/web/__init__.py b/examples/filebrowser/web/__init__.py index 2bff242..8b8f313 100644 --- a/examples/filebrowser/web/__init__.py +++ b/examples/filebrowser/web/__init__.py @@ -22,7 +22,8 @@ special_dirs['app'] = urlparser.URLParser( def application(environ, start_response): context = environ['filebrowser.pathcontext'] = pathobj.PathContext( - root=environ['paste.config']['browse_path']) + root=environ['paste.config']['browse_path'], + config=environ['paste.config']) if environ.get('filebrowser.resolved'): return special_dirs['app'](environ, start_response) path_info = environ.get('PATH_INFO', '') diff --git a/examples/filebrowser/web/addfile_form.py b/examples/filebrowser/web/addfile_form.py new file mode 100644 index 0000000..c459b59 --- /dev/null +++ b/examples/filebrowser/web/addfile_form.py @@ -0,0 +1,10 @@ +from filebrowser.sitepage import * + +class addfile_form(SitePage): + + def setup(self): + root = self.pathcontext.path(self.config.get('blank_file_dir', '/')) + self.options.blanks = root.find_filename('blank') + + + \ No newline at end of file -- cgit v1.2.1