Commit 95ffcdb5 by Kálmán Viktor

dashboard: store display quota on index

parent 4c9dd092
$(function() {
$("#store-list-container").on("click", ".store-list-item", function() {
if($(this).data("item-type") == "D") {
$("#store-list-up-icon").removeClass("fa-reply").addClass("fa-refresh fa-spin");
var url = $(this).prop("href");
$.get(url, function(result) {
$("#store-list-container").html(result);
......
......@@ -47,7 +47,7 @@ class Store(object):
url = urljoin(self.store_url, url)
if timeout is None:
timeout = self.default_timeout
payload = json.dumps(kwargs)
payload = json.dumps(kwargs) if kwargs else None
try:
headers = {'content-type': 'application/json'}
response = method(url, data=payload, headers=headers,
......@@ -84,7 +84,7 @@ class Store(object):
return result
def request_download(self, path):
r = self._request_cmd("DOWNLOAD", PATH=path, timeout=5)
r = self._request_cmd("DOWNLOAD", PATH=path, timeout=10)
return r.json()['LINK']
def request_upload(self, path):
......@@ -102,7 +102,13 @@ class Store(object):
def get_quota(self): # no CMD? :o
r = self._request(self.username)
return r.json()
quota = r.json()
quota.update({
'readable_used': filesizeformat(float(quota['Used'])),
'readable_soft': filesizeformat(float(quota['Soft'])),
'readable_hard': filesizeformat(float(quota['Hard'])),
})
return quota
def set_quota(self, quota):
self._request("/quota/" + self.username, post, QUOTA=quota)
......
......@@ -68,12 +68,12 @@
class="list-group-item store-list-item" data-item-type="D">
{% if current == "/" %}
<div class="store-list-item-icon">
<i class="fa fa-refresh"></i>
<i class="fa fa-refresh" id="store-list-up-icon"></i>
</div>
{% trans "Refresh" %}
{% else %}
<div class="store-list-item-icon">
<i class="fa fa-reply"></i>
<i class="fa fa-reply" id="store-list-up-icon"></i>
</div>
..
{% endif %}
......
......@@ -2,15 +2,22 @@
<div class="panel panel-default">
<div class="panel-heading">
<span class="btn btn-default btn-xs infobtn pull-right"
title="A list of your most recent files!">
<span class="btn btn-default btn-xs infobtn pull-right store-action-button"
title="{% trans "A list of your most recent files." %}">
<i class="fa fa-info-circle"></i>
</span>
<h3 class="no-margin"><i class="icon-briefcase"></i> Files
<span class="btn btn-default btn-xs infobtn pull-right"
title="
{% blocktrans with used=files.quota.readable_used soft=files.quota.readable_soft hard=files.quota.readable_hard %}
You are currently using {{ used }}, your soft limit is {{ soft }}, your hard limit is {{ hard }}.
{% endblocktrans %}">
<i class="fa fa-adjust"></i>
</span>
<h3 class="no-margin"><i class="fa fa-briefcase"></i> {% trans "Files" %}
</h3>
</div>
<div class="list-group" id="dashboard-files-toplist">
{% for t in toplist %}
{% for t in files.toplist %}
{% if t.TYPE == "F" %}
<div class="list-group-item">
<i class="fa fa-{{ t.icon }} dashboard-toplist-icon"></i>
......
......@@ -227,19 +227,22 @@ class IndexView(LoginRequiredMixin, TemplateView):
# toplist
if settings.STORE_URL:
cache_key = "toplist-%d" % self.request.user.pk
cache_key = "files-%d" % self.request.user.pk
cache = get_cache("default")
toplist = cache.get(cache_key)
if not toplist:
files = cache.get(cache_key)
if not files:
try:
toplist = Store(self.request.user).toplist()
store = Store(self.request.user)
toplist = store.toplist()
quota = store.get_quota()
files = {'toplist': toplist, 'quota': quota}
except Exception:
logger.exception("Unable to get tolist for %s",
unicode(self.request.user))
toplist = []
cache.set(cache_key, toplist, 300)
files = {'toplist': []}
cache.set(cache_key, files, 300)
context['toplist'] = toplist
context['files'] = files
else:
context['no_store'] = True
......@@ -3232,13 +3235,16 @@ def store_new_directory(request):
@require_POST
@login_required
def store_refresh_toplist(request):
cache_key = "toplist-%d" % request.user.pk
cache_key = "files-%d" % request.user.pk
cache = get_cache("default")
try:
toplist = Store(request.user).toplist()
store = Store(request.user)
toplist = store.toplist()
quota = store.get_quota()
files = {'toplist': toplist, 'quota': quota}
except Exception:
logger.exception("Can't get toplist of %s", unicode(request.user))
toplist = []
cache.set(cache_key, toplist, 300)
files = {'toplist': []}
cache.set(cache_key, files, 300)
return redirect(reverse("dashboard.index"))
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