Skip to content

Commit

Permalink
Improved LFE file viewer to show contents of .zip files.
Browse files Browse the repository at this point in the history
  • Loading branch information
lethain committed Jul 10, 2008
1 parent 844a3d6 commit 95d6989
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion editor/views.py
Expand Up @@ -35,6 +35,8 @@
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_for_filename

from zipfile import ZipFile

CHARACTERS_TO_STRIP = re.compile(r"[ \.,\!\?'\";:/\\+=#]+")
def sluggify(str):
return CHARACTERS_TO_STRIP.subn(u"-", str.lower())[0].strip("-")
Expand Down Expand Up @@ -329,7 +331,13 @@ def display_resource(request, id):
if ext in IMAGE_EXTS:
opts['type'] = "image"
elif ext in ZIP_EXTS:
opts['type'] = "zip"
try:
opts['type'] = "zip"
zf = ZipFile(res.get_content_filename(),'r')
opts['files_list'] = zf.namelist()
zf.close()
except IOError:
opts['type'] = "file"
else:
try:
lexer = get_lexer_for_filename(file)
Expand Down
8 changes: 8 additions & 0 deletions templates/lifeflow/editor/resource.html
Expand Up @@ -15,6 +15,14 @@
{% endifequal %}

{% ifequal type "zip" %}
<div class="extra">
<ul>
{% for file in files_list %}
<li>{{ file }}</li>
{% endfor %}
</ul>
</div>

{% endifequal %}

{% ifequal type "code" %}
Expand Down

0 comments on commit 95d6989

Please sign in to comment.