From 65c2fce63675f6b29cce8ba1e3fdd590da52dcba Mon Sep 17 00:00:00 2001 From: posativ Date: Sun, 16 Dec 2012 17:59:17 +0100 Subject: [PATCH] better admin 'theme', 304 Not Modified support and minor improvements --- README | 2 +- isso/__init__.py | 20 ++++--- isso/admin.py | 8 +-- isso/templates/admin.js | 4 +- isso/templates/admin.mako | 103 ++++++++++++++++++++++-------------- isso/templates/base.mako | 106 ++++++++++++++++++++++++++++++++++++-- isso/templates/login.mako | 3 +- isso/wsgi.py | 27 ++++++++-- setup.py | 3 +- 9 files changed, 215 insertions(+), 61 deletions(-) diff --git a/README b/README index 547e39f..19b06bd 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ Isso – Ich schrei sonst ======================= -You love static blog generators (especially [Acrylamid][1] \*cough\*) and the +You love static blog generators (especially [Acrylamid][1] *cough*) and the only option to interact with the community is [Disqus][2]. There's nothing wrong with it, but if you care about the privacy of your audience you should better use a comment system that is under your control. This is, were Isso diff --git a/isso/__init__.py b/isso/__init__.py index ba64e07..8e531e1 100644 --- a/isso/__init__.py +++ b/isso/__init__.py @@ -54,7 +54,8 @@ class Isso(object): MAX_AGE = 15 * 60 HTTP_STATUS_CODES = { - 200: 'Ok', 201: 'Created', 202: 'Accepted', 301: 'Moved Permanently', + 200: 'Ok', 201: 'Created', 202: 'Accepted', + 301: 'Moved Permanently', 304: 'Not Modified', 400: 'Bad Request', 404: 'Not Found', 403: 'Forbidden', 500: 'Internal Server Error', } @@ -73,13 +74,16 @@ class Isso(object): lambda r: (wsgi.Rule(r[0]), r[1], r[2] if isinstance(r[2], list) else [r[2]]), [ # moderation panel - ('/', admin.login, ['GET', 'POST']), - ('/admin/', admin.index, ['GET', 'POST']), + ('/', admin.login, ['HEAD', 'GET', 'POST']), + ('/admin/', admin.index, ['HEAD', 'GET', 'POST']), + + # assets + ('/<(static|js):directory>/<(.+?):path>', wsgi.static, ['HEAD', 'GET']), # comment API, note that the client side quotes the URL, but this is # actually unnecessary. PEP 333 aka WSGI always unquotes PATH_INFO. - ('/1.0/<(.+?):path>/new', comment.create, 'POST'), - ('/1.0/<(.+?):path>/<(int):id>', comment.get, 'GET'), + ('/1.0/<(.+?):path>/new', comment.create,'POST'), + ('/1.0/<(.+?):path>/<(int):id>', comment.get, ['HEAD', 'GET']), ('/1.0/<(.+?):path>/<(int):id>', comment.modify, ['PUT', 'DELETE']), ('/1.0/<(.+?):path>/<(int):id>/approve', comment.approve, 'PUT'), @@ -117,11 +121,11 @@ class Isso(object): if code == 404: try: - code, body, headers = wsgi.sendfile(environ['PATH_INFO'], os.getcwd()) + code, body, headers = wsgi.sendfile(environ['PATH_INFO'], os.getcwd(), environ) except (IOError, OSError): try: path = environ['PATH_INFO'].rstrip('/') + '/index.html' - code, body, headers = wsgi.sendfile(path, os.getcwd()) + code, body, headers = wsgi.sendfile(path, os.getcwd(), environ) except (IOError, OSError): pass @@ -181,7 +185,7 @@ def main(): print 'isso', __version__ sys.exit(0) - app = Isso({'SQLITE': options.sqlite, 'PRODUCTION': options.production, 'MODERATION': False}) + app = Isso({'SQLITE': options.sqlite, 'PRODUCTION': options.production, 'MODERATION': True}) if len(args) > 0 and args[0] == 'import': if len(args) < 2: diff --git a/isso/admin.py b/isso/admin.py index 2fd7374..743de2e 100644 --- a/isso/admin.py +++ b/isso/admin.py @@ -3,13 +3,15 @@ # Copyright 2012, Martin Zimmermann . All rights reserved. # License: BSD Style, 2 clauses. see isso/__init__.py +from os.path import join, dirname + from mako.lookup import TemplateLookup from itsdangerous import SignatureExpired, BadSignature from isso.wsgi import setcookie -mako = TemplateLookup(directories=['isso/templates'], input_encoding='utf-8') +mako = TemplateLookup(directories=[join(dirname(__file__), 'templates')], input_encoding='utf-8') render = lambda template, **context: mako.get_template(template).render_unicode(**context) @@ -19,7 +21,7 @@ def login(app, environ, request): if request.form.getfirst('secret') == app.SECRET: return 301, '', { 'Location': '/admin/', - 'Set-Cookie': setcookie('session-admin', app.signer.dumps('*'), + 'Set-Cookie': setcookie('admin', app.signer.dumps('*'), max_age=app.MAX_AGE, path='/') } @@ -29,7 +31,7 @@ def login(app, environ, request): def index(app, environ, request): try: - app.unsign(request.cookies.get('session-admin', '')) + app.unsign(request.cookies.get('admin', '')) except (SignatureExpired, BadSignature): return 301, '', {'Location': '/'} diff --git a/isso/templates/admin.js b/isso/templates/admin.js index 40bcd4b..8755d68 100644 --- a/isso/templates/admin.js +++ b/isso/templates/admin.js @@ -1,9 +1,9 @@ function initialize() { - $('article > footer > a').forEach(function(item) { + $('div.buttons > a').forEach(function(item) { - var node = $(item).parent().parent()[0] + var node = $(item).parent().parent().parent().parent()[0] var path = node.getAttribute("data-path"); var id = node.getAttribute("data-id"); diff --git a/isso/templates/admin.mako b/isso/templates/admin.mako index 973f572..75fcea3 100644 --- a/isso/templates/admin.mako +++ b/isso/templates/admin.mako @@ -27,58 +27,83 @@ <%def name="make(comment)"> -
-
- - ${strftime('%a %d %B %Y', gmtime(comment.created))} - - % if comment.website: - ${comment.author} - % else: - ${comment.author} - % endif - - -
- -
- ${app.markup.convert(comment.text)} +
+
+
+
+ ${comment.path} +
+ +
+ ${app.markup.convert(comment.text)} +
+ +
+ +
+ +
    +
  • ${strftime('%d. %B %Y um %H:%M', gmtime(comment.created))}
  • +
  • von ${comment.author}
  • + % if comment.website: +
  • ${comment.website}
  • + % endif + +
+ +
+ Delete + % if comment.pending: + Approve + % endif +
+
- -
-

Dashboard

+
+
+

Pending

+
+ +
+ + [ 10 + | 20 + | All ] + +
-
-

Pending

- - [ 10 - | 20 - | All ] - +
+
% for comment in app.db.recent(limit=get('pendinglimit', int), mode=2): ${make(comment)} % endfor
-
-

Recent

- - [10 - | 20 - | All] - +
+
+

Recent

+
+
+ + [ 10 + | 20 + | All ] + +
+
+
% for comment in app.db.recent(limit=get('recentlimit', int) or 20, mode=5): ${make(comment)} % endfor -
+ +
+ +

Isso – Ich schrei sonst!

+ +
diff --git a/isso/templates/base.mako b/isso/templates/base.mako index c204ffa..58ea6c3 100644 --- a/isso/templates/base.mako +++ b/isso/templates/base.mako @@ -8,16 +8,116 @@