Commit a30f9eb3 by Kálmán Viktor

dashboard: basic store

parent 7af38cf1
...@@ -271,7 +271,6 @@ LOCAL_APPS = ( ...@@ -271,7 +271,6 @@ LOCAL_APPS = (
'dashboard', 'dashboard',
'manager', 'manager',
'acl', 'acl',
'cloudstore',
) )
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
......
...@@ -82,9 +82,7 @@ def listfolder(neptun, path): ...@@ -82,9 +82,7 @@ def listfolder(neptun, path):
r = post_request(url, payload) r = post_request(url, payload)
if r.status_code == requests.codes.ok: if r.status_code == requests.codes.ok:
tupplelist = json.loads(r.content) tupplelist = json.loads(r.content)
for item in tupplelist: return tupplelist
item['MTIME'] = time.ctime(item['MTIME'])
return tupplelist
else: else:
raise Http404 raise Http404
......
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load store_tags %}
{% block title-page %}{% trans "Virtual machines" %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-12">
<ul id="store-list-list">
{% for f in root %}
<li class="store-list-item">
<div class="store-list-item-icon">
<i class="icon-{% if f.TYPE == "D" %}folder-open-alt{% else %}file-alt{% endif %}"></i>
</div>
{{ f.NAME }}
<div class="store-list-item-size">
{% if f.TYPE == "D" %}{% trans "directory" %}{% else %}{% bytes_to_megabytes f.SIZE %}MB{% endif %}
</div>
<div class="store-list-item-actions">
<span title="{% trans "Last modified:" %} {% timestamp_to_date f.MTIME %}"
class="btn btn-default btn-xs">
<i class="icon-time"></i>
</span>
<span class="btn btn-default btn-xs">
<i class="icon-cloud-download"></i>
</span>
</div>
<div class="clearfix"></div>
</li>
{% endfor %}
</ul>
</div>
</div>
<style>
#store-list-list {
list-style: none;
}
.store-list-item {
padding: 0 8px 0 8px;
cursor: pointer;
line-height: 35px;
height: 35px;
}
.store-list-item:hover {
background: rgba(0, 0, 0, 0.1);
}
.store-list-item-icon {
width: 20px;
display: inline-block;
text-align: center;
}
.store-list-item-size {
display: inline-block;
width: 70px;
text-align: right;
float: right;
}
.store-list-item-actions {
display: inline-block;
width: 100px;
text-align: center;
float: right;
}
</style>
{% endblock %}
{% block extra_js %}
<script src="{{ STATIC_URL}}dashboard/store.js"></script>
{% endblock %}
from datetime import datetime
from django import template
from django.utils.timesince import timesince
register = template.Library()
@register.simple_tag(name="bytes_to_megabytes")
def bytes_to_megabytes(size):
if size:
return size / (1024 * 1024)
else:
return 0
@register.simple_tag(name="timestamp_to_date")
def timestamp_to_date(timestamp):
date = datetime.fromtimestamp(float(timestamp))
if (datetime.now() - date).days < 1:
date = timesince(date)
return date
...@@ -37,6 +37,7 @@ from .views import ( ...@@ -37,6 +37,7 @@ from .views import (
get_vm_screenshot, get_vm_screenshot,
ProfileView, toggle_use_gravatar, UnsubscribeFormView, ProfileView, toggle_use_gravatar, UnsubscribeFormView,
UserKeyDelete, UserKeyDetail, UserKeyCreate, UserKeyDelete, UserKeyDetail, UserKeyCreate,
StoreList
) )
urlpatterns = patterns( urlpatterns = patterns(
...@@ -169,4 +170,7 @@ urlpatterns = patterns( ...@@ -169,4 +170,7 @@ urlpatterns = patterns(
url(r'^sshkey/create/$', url(r'^sshkey/create/$',
UserKeyCreate.as_view(), UserKeyCreate.as_view(),
name="dashboard.views.userkey-create"), name="dashboard.views.userkey-create"),
url(r"^store/list/$", StoreList.as_view(),
name="dashboard.views.store-list")
) )
...@@ -75,6 +75,8 @@ from storage.models import Disk ...@@ -75,6 +75,8 @@ from storage.models import Disk
from firewall.models import Vlan, Host, Rule from firewall.models import Vlan, Host, Rule
from .models import Favourite, Profile, GroupProfile from .models import Favourite, Profile, GroupProfile
from dashboard import store_api
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
saml_available = hasattr(settings, "SAML_CONFIG") saml_available = hasattr(settings, "SAML_CONFIG")
...@@ -2931,3 +2933,15 @@ class UserKeyCreate(LoginRequiredMixin, SuccessMessageMixin, CreateView): ...@@ -2931,3 +2933,15 @@ class UserKeyCreate(LoginRequiredMixin, SuccessMessageMixin, CreateView):
kwargs = super(UserKeyCreate, self).get_form_kwargs() kwargs = super(UserKeyCreate, self).get_form_kwargs()
kwargs['user'] = self.request.user kwargs['user'] = self.request.user
return kwargs return kwargs
class StoreList(LoginRequiredMixin, TemplateView):
template_name = "dashboard/store/list.html"
def get_context_data(self, *args, **kwargs):
context = super(StoreList, self).get_context_data(*args, **kwargs)
files = store_api.listfolder("test", "/")
dirs_first = sorted(files, key=lambda k: k['TYPE'])
context['root'] = dirs_first
return context
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