diff options
author | Gregy <gregy@gregy.cz> | 2010-08-06 23:16:54 +0200 |
---|---|---|
committer | Gregy <gregy@gregy.cz> | 2010-08-06 23:16:54 +0200 |
commit | 4b27d1b8931d6b1ad78d605a40da35090d1b6725 (patch) | |
tree | 0749edccc0b34bcace4ec29be0225cf758b5dac5 | |
parent | settings page working (diff) | |
download | pyload-4b27d1b8931d6b1ad78d605a40da35090d1b6725.tar.xz |
Log page improvement
-rw-r--r-- | module/web/media/default/css/default.css | 3 | ||||
-rw-r--r-- | module/web/pyload/urls.py | 2 | ||||
-rw-r--r-- | module/web/pyload/views.py | 49 | ||||
-rw-r--r-- | module/web/templates/default/logs.html | 38 | ||||
-rwxr-xr-x | pyLoadCore.py | 1 |
5 files changed, 76 insertions, 17 deletions
diff --git a/module/web/media/default/css/default.css b/module/web/media/default/css/default.css index 7bd46d8cc..9d2ca1a14 100644 --- a/module/web/media/default/css/default.css +++ b/module/web/media/default/css/default.css @@ -1679,4 +1679,5 @@ div.tabContent border: none;
margin: 0px;
padding: 5px;
-}
\ No newline at end of file +}
+
diff --git a/module/web/pyload/urls.py b/module/web/pyload/urls.py index 420bc8ce1..66ea68e39 100644 --- a/module/web/pyload/urls.py +++ b/module/web/pyload/urls.py @@ -14,7 +14,7 @@ urlpatterns = patterns('pyload', (r'^collector/$', 'views.collector',{}, 'collector'), (r'^settings/$', 'views.config',{}, 'config'), (r'^logs/$', 'views.logs',{}, 'logs'), - (r'^logs/(?P<page>\d+)$', 'views.logs',{}, 'logs'), + (r'^logs/(?P<item>\d+)$', 'views.logs',{}, 'logs'), (r'^$', 'views.home',{}, 'home'), ) diff --git a/module/web/pyload/views.py b/module/web/pyload/views.py index 21e583348..4d247246a 100644 --- a/module/web/pyload/views.py +++ b/module/web/pyload/views.py @@ -9,6 +9,7 @@ from os.path import isfile from os.path import join from urllib import unquote from itertools import chain +from datetime import datetime from django.conf import settings from django.contrib.auth.decorators import login_required @@ -171,19 +172,53 @@ def download(request, path): @login_required @permission('pyload.can_see_logs') @check_server -def logs(request, page=0): +def logs(request, item=-1): - page = int(page) - log = settings.PYLOAD.get_log(page) - data = [] + perpage = request.session.get('perpage', 40); + perpage_p = {20:20, 40: 40, 100: 100, 0:'all'} + fro = None; + if request.method == 'POST': + try: + fro = datetime.strptime(request.POST['from'], '%d.%m.%Y %H:%M:%S') + except: + pass + try: + perpage = int(request.POST['perpage']) + request.session['perpage'] = perpage + except: + pass try: - for i in range(0, 20): - data.append({'line': i + 1+page, 'content':log[i]}) + item = int(item) except: pass + + log = settings.PYLOAD.get_log() + if perpage == 0: + item = 0 + + if item < 0 or type(item) is not int: + item = len(log) - perpage + data = [] + counter = 0 + perpagecheck = 0 + for l in log: + counter = counter+1; + try: + date,time,level,message = l.split(" ", 3) + except: + continue + if counter >= item: + dtime = datetime.strptime(date+' '+time, '%d.%m.%Y %H:%M:%S') + if fro == None: + fro = dtime + if fro <= dtime: + data.append({'line': counter, 'date': date+" "+time, 'level':level, 'message': message}) + perpagecheck = perpagecheck +1; + if perpagecheck >= perpage and perpage > 0: + break - return render_to_response(join(settings.TEMPLATE, 'logs.html'), RequestContext(request, {'log': data, 'next': str(page + 20), 'prev': 0 if page-20 < 0 else page-20}, [status_proc])) + return render_to_response(join(settings.TEMPLATE, 'logs.html'), RequestContext(request, {'log': data, 'from': fro.strftime('%d.%m.%Y %H:%M:%S'), 'perpage':perpage, 'perpage_p':perpage_p, 'iprev': 0 if item - perpage < 0 else item - perpage, 'inext': (item + perpage) if item+perpage < len(log) else len(log)-perpage}, [status_proc])) @login_required @permission('pyload.can_add_dl') diff --git a/module/web/templates/default/logs.html b/module/web/templates/default/logs.html index 52120ffc4..2bf626769 100644 --- a/module/web/templates/default/logs.html +++ b/module/web/templates/default/logs.html @@ -3,7 +3,9 @@ {% block title %}{% trans "Logs" %} - {{block.super}} {% endblock %} {% block subtitle %}{% trans "Logs" %}{% endblock %} - +{% block head %} +<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/log.css"/> +{% endblock %} {% block menu %} <li> <a href="/" title=""><img src="{{ MEDIA_URL }}img/head-menu-home.png" alt="" /> {% trans "Home" %}</a> @@ -26,10 +28,32 @@ {% endblock %} {% block content %} -<ul> -{% for line in log %} - <li>{{line.line}}: {{line.content}}</li> -{% endfor %} -</ul> -<a href="{% url logs %}"><< {% trans "Start" %}</a> <a href="{% url logs prev %}">< {% trans "prev" %}</a> <a href="{% url logs next %}">{% trans "next" %} ></a> +<div style="clear: both;"></div> + +<div class="logpaginator"><a href="{% url logs 0%}"><< {% trans "Start" %}</a> <a href="{% url logs iprev %}">< {% trans "prev" %}</a> <a href="{% url logs inext %}">{% trans "next" %} ></a> <a href="{% url logs %}">{% trans "End" %} >></a></div> +<div class="logperpage"> + <form id="logform1" action="" method="POST"> + <label for="perpage">Lines per page:</label> + <select name="perpage" onchange="this.form.submit();"> + {% for value,text in perpage_p.iteritems %} + <option value="{{value}}"{% ifequal value perpage %} selected="selected" {% endifequal %}>{{text}}</option> + {% endfor %} + </select> + </form> +</div> +<div style="clear: both;"></div> +<div class="logdiv"> + <table class="logtable" cellpadding="0" cellspacing="0"> + {% for line in log %} + <tr><td class="logline">{{line.line}}</td><td>{{line.date}}</td><td class="loglevel">{{line.level}}</td><td>{{line.message}}</td></tr> + {% endfor %} + </table> +</div> +<div class="logform"> +<form id="logform2" action="" method="POST"> + <label for="from">Jump to time:</label><input type="text" name="from" size="15" value="{{from}}"/> + <input type="submit" value="ok" /> +</form> +</div> +<div style="clear: both; height: 10px;"> </div> {% endblock %}
\ No newline at end of file diff --git a/pyLoadCore.py b/pyLoadCore.py index 86e15b19f..59c529742 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -547,7 +547,6 @@ class ServerMethods(): fh = open(filename, "r") lines = fh.readlines() fh.close() - lines.reverse() if offset >= len(lines): return None |