public
Description: A full featured and opinionated blogging solution using Django
Homepage: http://lethain.com/projects/lifeflow/
Clone URL: git://github.com/lethain/lifeflow.git
Improved LFE file viewer to show contents of .zip files.
lethain (author)
Thu Jul 10 02:31:52 -0700 2008
commit  95d6989673b98dff87dad9aa408fc68de9ce8676
tree    a193f1a246308a0858341260f09e6f5e6ae16d7b
parent  844a3d6c96070d32730203976ffba0281389362a
...
35
36
37
 
 
38
39
40
...
329
330
331
332
 
 
 
 
 
 
 
333
334
335
...
35
36
37
38
39
40
41
42
...
331
332
333
 
334
335
336
337
338
339
340
341
342
343
0
@@ -35,6 +35,8 @@ from pygments.util import ClassNotFound
0
 from pygments.formatters import HtmlFormatter
0
 from pygments.lexers import get_lexer_for_filename
0
 
0
+from zipfile import ZipFile
0
+
0
 CHARACTERS_TO_STRIP = re.compile(r"[ \.,\!\?'\";:/\\+=#]+")
0
 def sluggify(str):
0
     return CHARACTERS_TO_STRIP.subn(u"-", str.lower())[0].strip("-")
0
@@ -329,7 +331,13 @@ def display_resource(request, id):
0
     if ext in IMAGE_EXTS:
0
         opts['type'] = "image"
0
     elif ext in ZIP_EXTS:
0
-        opts['type'] = "zip"
0
+        try:
0
+            opts['type'] = "zip"
0
+            zf = ZipFile(res.get_content_filename(),'r')
0
+            opts['files_list'] = zf.namelist()
0
+            zf.close()
0
+        except IOError:
0
+            opts['type'] = "file"
0
     else:
0
         try:
0
             lexer = get_lexer_for_filename(file)
...
15
16
17
 
 
 
 
 
 
 
 
18
19
20
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0
@@ -15,6 +15,14 @@
0
 {% endifequal %}
0
 
0
 {% ifequal type "zip" %}
0
+<div class="extra">
0
+  <ul>
0
+    {% for file in files_list %}
0
+    <li>{{ file }}</li>
0
+    {% endfor %}
0
+  </ul>
0
+</div>
0
+
0
 {% endifequal %}
0
 
0
 {% ifequal type "code" %}

Comments