Commit 28fc85f7 by Kálmán Viktor

dashboard: allow no store

Closes #219
parent 79703087
......@@ -446,14 +446,14 @@ if graphite_host and graphite_port:
else:
GRAPHITE_URL = None
STORE_BASIC_AUTH = get_env_variable("STORE_BASIC_AUTH") == "True"
STORE_VERIFY_SSL = get_env_variable("STORE_VERIFY_SSL") == "True"
STORE_SSL_AUTH = get_env_variable("STORE_SSL_AUTH") == "True"
STORE_BASIC_AUTH = get_env_variable("STORE_BASIC_AUTH", "") == "True"
STORE_VERIFY_SSL = get_env_variable("STORE_VERIFY_SSL", "") == "True"
STORE_SSL_AUTH = get_env_variable("STORE_SSL_AUTH", "") == "True"
STORE_CLIENT_USER = get_env_variable("STORE_CLIENT_USER", "")
STORE_CLIENT_PASSWORD = get_env_variable("STORE_CLIENT_PASSWORD", "")
STORE_CLIENT_KEY = get_env_variable("STORE_CLIENT_KEY", "")
STORE_CLIENT_CERT = get_env_variable("STORE_CLIENT_CERT", "")
STORE_URL = get_env_variable("STORE_URL")
STORE_URL = get_env_variable("STORE_URL", "")
SESSION_COOKIE_NAME = "csessid%x" % (((getnode() // 139) ^
(getnode() % 983)) & 0xffff)
......@@ -22,6 +22,10 @@ class NotOkException(StoreApiException):
super(NotOkException, self).__init__(*args, **kwargs)
class NoStoreException(StoreApiException):
pass
class Store(object):
def __init__(self, user, default_timeout=0.5):
......@@ -35,6 +39,8 @@ class Store(object):
self.username = "u-%d" % user.pk
self.default_timeout = default_timeout
self.store_url = settings.STORE_URL
if not self.store_url:
raise NoStoreException
def _request(self, url, method=get, timeout=None,
raise_status_code=True, **kwargs):
......
......@@ -23,9 +23,11 @@
</div>
{% endif %}
{% if not no_store %}
<div class="col-lg-4 col-sm-6">
{% include "dashboard/store/index-files.html" %}
</div>
{% endif %}
{% if perms.vm.create_template %}
<div class="col-lg-4 col-sm-6">
......
......@@ -84,7 +84,7 @@ from storage.models import Disk
from firewall.models import Vlan, Host, Rule
from .models import Favourite, Profile, GroupProfile, FutureMember
from .store_api import Store, NotOkException
from .store_api import Store, NoStoreException
logger = logging.getLogger(__name__)
saml_available = hasattr(settings, "SAML_CONFIG")
......@@ -226,19 +226,22 @@ class IndexView(LoginRequiredMixin, TemplateView):
'operator', user).all()[:5]
# toplist
cache_key = "toplist-%d" % self.request.user.pk
cache = get_cache("default")
toplist = cache.get(cache_key)
if not toplist:
try:
toplist = Store(self.request.user).toplist()
except Exception:
logger.exception("Unable to get tolist for %s",
unicode(self.request.user))
toplist = []
cache.set(cache_key, toplist, 300)
if settings.STORE_URL:
cache_key = "toplist-%d" % self.request.user.pk
cache = get_cache("default")
toplist = cache.get(cache_key)
if not toplist:
try:
toplist = Store(self.request.user).toplist()
except Exception:
logger.exception("Unable to get tolist for %s",
unicode(self.request.user))
toplist = []
cache.set(cache_key, toplist, 300)
context['toplist'] = toplist
context['toplist'] = toplist
else:
context['no_store'] = True
return context
......@@ -3103,14 +3106,18 @@ class StoreList(LoginRequiredMixin, TemplateView):
return context
def get(self, *args, **kwargs):
if self.request.is_ajax():
context = self.get_context_data(**kwargs)
return render_to_response(
"dashboard/store/_list-box.html",
RequestContext(self.request, context),
)
else:
return super(StoreList, self).get(*args, **kwargs)
try:
if self.request.is_ajax():
context = self.get_context_data(**kwargs)
return render_to_response(
"dashboard/store/_list-box.html",
RequestContext(self.request, context),
)
else:
return super(StoreList, self).get(*args, **kwargs)
except NoStoreException:
messages.warning(self.request, _("No store."))
return redirect("/")
def create_up_directory(self, directory):
return normpath(join('/', directory, '..'))
......@@ -3122,7 +3129,7 @@ def store_download(request):
path = request.GET.get("path")
try:
url = Store(request.user).request_download(path)
except NotOkException:
except Exception:
messages.error(request, _("Something went wrong during download."))
logger.exception("Unable to download, "
"maybe it is already deleted")
......@@ -3183,6 +3190,12 @@ class StoreRemove(LoginRequiredMixin, TemplateView):
return context
def get(self, *args, **kwargs):
try:
return super(StoreRemove, self).get(*args, **kwargs)
except NoStoreException:
return redirect("/")
def post(self, *args, **kwargs):
path = self.request.POST.get("path")
try:
......@@ -3209,6 +3222,7 @@ def store_new_directory(request):
logger.exception("Unable to create folder %s in %s for %s",
name, path, unicode(request.user))
messages.error(request, _("Unable to create folder."))
return redirect("/")
return redirect("%s?directory=%s" % (
reverse("dashboard.views.store-list"), path))
......
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