Commit 4216ec58 by Őry Máté

store: add toplist view/api

parent 1265f247
......@@ -25,4 +25,5 @@ urlpatterns = patterns('',
url(r'^reload/$', 'firewall.views.reload_firewall', name='reload_firewall'),
url(r'^fwapi/$', 'firewall.views.firewall_api', name='firewall_api'),
url(r'^store/$', 'store.views.index', name='store_index'),
url(r'^store/top/$', 'store.views.toplist', name='store_top'),
)
......@@ -168,6 +168,17 @@ def cmd_remove(request, neptun, home_path):
return
COMMANDS['REMOVE'] = cmd_remove
def cmd_toplist(request, neptun, home_path):
d = []
try:
top_dir = os.path.normpath(os.path.join(home_path, "../.top"))
d = [file_dict(os.readlink(os.path.join(top_dir, f)), home_path)
for f in os.listdir(top_dir)]
except:
pass
return json.dumps(sorted(d, key=lambda f: f['MTIME']))
COMMANDS['TOPLIST'] = cmd_toplist
@route('/set/<neptun>', method='POST')
def set_keys(neptun):
key_list = []
......
......@@ -76,6 +76,18 @@ class StoreApi:
else:
raise Http404
@staticmethod
def toplist(neptun):
url = settings['store_url']+'/'+neptun
payload = json.dumps({ 'CMD' : 'TOPLIST'})
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
tupplelist = json.loads(r.content)
for item in tupplelist:
item['MTIME'] = time.ctime(item['MTIME'])
return tupplelist
else:
raise Http404
@staticmethod
def requestdownload(neptun, path):
url = settings['store_url']+'/'+neptun
payload = json.dumps({ 'CMD' : 'DOWNLOAD', 'PATH' : path })
......
......@@ -66,6 +66,13 @@ def index(request):
file_list = StoreApi.listfolder(user,path)
return render_to_response('store/list.html', RequestContext(request, {'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user}))
@login_required
def toplist(request):
user = request.user.username
path = backpath = '/'
file_list = StoreApi.toplist(user)
return render_to_response('store/list.html', RequestContext(request, {'file_list': file_list, 'path' : path, 'backpath' : backpath, 'username' : user}))
def logout(request):
auth.logout(request)
return redirect('/')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment