Skip to content

Commit

Permalink
show statistics on /
Browse files Browse the repository at this point in the history
  • Loading branch information
posativ committed Nov 10, 2012
1 parent 14aeeac commit b5491d6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
9 changes: 1 addition & 8 deletions regenwolken/manage.py
Expand Up @@ -19,14 +19,7 @@
from gridfs import GridFS from gridfs import GridFS
from gridfs.errors import NoFile from gridfs.errors import NoFile



from regenwolken.utils import ppsize
def ppsize(num):
'''pretty-print filesize.
http://blogmag.net/blog/read/38/Print_human_readable_file_size'''
for x in ['bytes','KiB','MiB','GiB','TB']:
if num < 1024.0:
return "%3.2f %s" % (num, x)
num /= 1024.0




def tdelta(input): def tdelta(input):
Expand Down
Binary file added regenwolken/static/images/regenwolken.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions regenwolken/templates/index.html
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Regenwolken: open source, self-hosting CloudApp</title>
</head>
<body>

<section style="margin: 0 auto; width: 800px;">
<img src="/static/images/regenwolken.png" />

<ul style="list-style-type: none;">
<li>Users: {{ users }}</li>
<li>Files: {{ files }}</li>
<li>Size : {{ size }}</li>
<li>Hits : {{ hits }}</li>
</ul>
<p><a href="https://github.com/posativ/regenwolken#readme">See
Instructions on GitHub</a>.</p>

</section>

</body>

</html>
9 changes: 9 additions & 0 deletions regenwolken/utils.py
Expand Up @@ -189,3 +189,12 @@ class Struct:
"""dict -> class, http://stackoverflow.com/questions/1305532/convert-python-dict-to-object""" """dict -> class, http://stackoverflow.com/questions/1305532/convert-python-dict-to-object"""
def __init__(self, **entries): def __init__(self, **entries):
self.__dict__.update(entries) self.__dict__.update(entries)


def ppsize(num):
'''pretty-print filesize.
http://blogmag.net/blog/read/38/Print_human_readable_file_size'''
for x in ['bytes','KiB','MiB','GiB','TB']:
if num < 1024.0:
return "%3.2f %s" % (num, x)
num /= 1024.0
20 changes: 10 additions & 10 deletions regenwolken/views.py
Expand Up @@ -14,7 +14,7 @@
from pymongo import DESCENDING from pymongo import DESCENDING
from flask import request, abort, jsonify, json, current_app, render_template, redirect from flask import request, abort, jsonify, json, current_app, render_template, redirect


from regenwolken.utils import login, private, A1, slug, thumbnail, clear, urlscheme from regenwolken.utils import login, private, A1, slug, thumbnail, clear, urlscheme, ppsize
from regenwolken.specs import Item, Account, Drop from regenwolken.specs import Item, Account, Drop




Expand All @@ -23,16 +23,16 @@ def index():
-- http://developer.getcloudapp.com/upload-file""" -- http://developer.getcloudapp.com/upload-file"""


db, fs = current_app.db, current_app.fs
config, sessions = current_app.config, current_app.sessions

if request.method == 'POST' and not request.accept_mimetypes.accept_html: if request.method == 'POST' and not request.accept_mimetypes.accept_html:


try: try:
account = current_app.sessions.pop(request.form.get('key'))['account'] account = sessions.pop(request.form.get('key'))['account']
except KeyError: except KeyError:
abort(401) abort(401)


db, fs = current_app.db, current_app.fs
config, sessions = current_app.config, current_app.sessions

acc = db.accounts.find_one({'email': account}) acc = db.accounts.find_one({'email': account})
source = request.headers.get('User-Agent', 'Regenschirm++/1.0').split(' ', 1)[0] source = request.headers.get('User-Agent', 'Regenschirm++/1.0').split(' ', 1)[0]
privacy = request.form.get('acl', acc['private_items']) privacy = request.form.get('acl', acc['private_items'])
Expand All @@ -50,11 +50,11 @@ def index():
else: else:
return jsonify(Item(obj, config, urlscheme(request))) return jsonify(Item(obj, config, urlscheme(request)))
else: else:
return Response(status=501, content_type='text/html', response=( users = db.accounts.find().count()
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' files = fs.gfs._GridFS__files.count()
'<title>501 Not Implemented</title>' size = ppsize(sum([f['length'] for f in fs.gfs._GridFS__files.find()]))
'<h1>Nope. Web Interface still not implemented.</h1>' hits = sum([f['view_counter'] for f in fs.mdb.find()])
'<p>The server does not support the action requested by the browser.</p>')) return Response(render_template("index.html", **locals()), 200, content_type="text/html")




@login @login
Expand Down

0 comments on commit b5491d6

Please sign in to comment.