summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/filebrowser/pathobj.py49
-rw-r--r--examples/filebrowser/templates/addfile_form.pt13
-rw-r--r--examples/filebrowser/templates/directory.pt9
-rw-r--r--examples/filebrowser/templates/edit_html.pt3
-rw-r--r--examples/filebrowser/templates/edit_text.pt1
-rw-r--r--examples/filebrowser/templates/view_file.pt3
-rw-r--r--examples/filebrowser/web/__init__.py3
-rw-r--r--examples/filebrowser/web/addfile_form.py10
8 files changed, 86 insertions, 5 deletions
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'<script.*?</script>', 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 @@
+<form class="inline" action="" method="POST">
+<input type="hidden" name="action" value="create_from_blank">
+Create from:
+<select name="template">
+ <option value="">select template</option>
+ <option tal:repeat="blank options/blanks"
+ tal:attributes="value blank/path"
+ tal:content="blank/basename"/>
+</select>
+in:
+<input type="text" name="filename" style="width: 5em">
+<input type="submit" value="create">
+</form>
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() {
</form>
</span>
+ | <tal:let define="toggle servlet/globalurl/addfile_form/toggle">
+ <span tal:replace="structure python: toggle.link(
+ 'add file...', shownhtml='&amp;lt;&amp;lt;&amp;lt;',
+ style='text-decoration: none; color: #226')"/>
+ <span tal:attributes="id toggle/id" style="display: none">
+ ...
+ </span>
+ </tal:let>
+
</div>
<tal:for repeat="f options/files">
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'];
<form tal:attributes="action options/action" method="POST">
<input type="hidden" name="action" value="save">
-Edit:<br>
<table tal:condition="options/properties | nothing">
<tr tal:repeat="prop options/properties">
<td tal:content="prop/description">name</td>
<td><input tal:attributes="type prop/type; name prop/input_name;
- value prop/value"></td>
+ value prop/value" style="width: 100%"></td>
</tr>
</table>
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) {
<form tal:attributes="action options/action" method="POST">
<input type="hidden" name="action" value="save">
-Edit:<br>
<textarea name="content" id="txt-content" cols=60 style="width: 100%"
tal:attributes="rows options/ta_height"
tal:content="options/content"></textarea>
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: <tt tal:content="servlet/mimetype"/>
<tal:if condition="options/allow_edit"> |
<a tal:attributes="href servlet/pathurl/action=edit">edit</a></tal:if>
| <a tal:attributes="href servlet/pathurl/action=rename">rename</a>
+| <a href="#" tal:attributes="onclick
+ servlet/pathurl/action=delete/confirm=Are+you+sure+you+want+to+delete+this?"
+ >delete</a>
</p>
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