forked from shaba/openuds
Fixing up things
This commit is contained in:
parent
46af1b57dd
commit
feccd388c4
@ -118,6 +118,7 @@ encoding//src/uds/core/util/__init__.py=utf-8
|
||||
encoding//src/uds/core/util/connection.py=utf-8
|
||||
encoding//src/uds/core/util/html.py=utf-8
|
||||
encoding//src/uds/core/util/log.py=utf-8
|
||||
encoding//src/uds/core/util/middleware/__init__.py=utf-8
|
||||
encoding//src/uds/core/util/modfinder.py=utf-8
|
||||
encoding//src/uds/core/util/net.py=utf-8
|
||||
encoding//src/uds/core/util/request.py=utf-8
|
||||
|
@ -15,7 +15,7 @@ SITE_ROOT = '/'.join(os.path.dirname(os.path.realpath(__file__)).split('/')[:-1]
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
MINIFY = False
|
||||
|
||||
|
||||
ADMINS = (
|
||||
# ('Your Name', 'your_email@example.com'),
|
||||
@ -118,6 +118,7 @@ STATICFILES_DIRS = (
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
'compressor.finders.CompressorFinder',
|
||||
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
|
||||
)
|
||||
|
||||
@ -175,9 +176,22 @@ INSTALLED_APPS = (
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'south',
|
||||
'compress',
|
||||
'uds',
|
||||
)
|
||||
|
||||
# Compressor settings (for css/js)
|
||||
COMPRESS_ENABLED = True
|
||||
COMPRESS_OUTPUT_DIR = 'cache'
|
||||
COMPRESS_PRECOMPILERS = (
|
||||
('text/coffeescript', 'coffee --compile --stdio'),
|
||||
('text/less', 'lessc {infile} {outfile}'),
|
||||
('text/x-sass', 'sass {infile} {outfile}'),
|
||||
('text/x-scss', 'sass --scss {infile} {outfile}'),
|
||||
('text/stylus', 'stylus < {infile} > {outfile}'),
|
||||
('text/foobar', 'path.to.MyPrecompilerFilter'),
|
||||
)
|
||||
|
||||
# See http://docs.djangoproject.com/en/dev/topics/logging for
|
||||
# more details on how to customize your logging configuration.
|
||||
LOGDIR = SITE_ROOT + '/' + 'log'
|
||||
|
@ -71,7 +71,7 @@ class DownloadsManager(object):
|
||||
@param path: path to file
|
||||
@params zip: If download as zip
|
||||
'''
|
||||
_id = str(uuid.uuid5(self._namespace, name))
|
||||
_id = uuid.uuid5(self._namespace, str(name))
|
||||
self._downloadables[_id] = {'name': name, 'comment': comment, 'path': path, 'mime': mime}
|
||||
|
||||
def getDownloadables(self):
|
||||
|
@ -77,12 +77,12 @@ class AutoAttributes(Serializable):
|
||||
self.declare(**kwargs)
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name.startswith('_') and self.dict.has_key(name[1:]):
|
||||
if name.startswith('_') and name[1:] in self.dict:
|
||||
return self.dict[name[1:]].getValue()
|
||||
return object.__getattribute__(self, name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name.startswith('_') and self.dict.has_key(name[1:]):
|
||||
if name.startswith('_') and name[1:] in self.dict:
|
||||
self.dict[name[1:]].setValue(value)
|
||||
else:
|
||||
object.__setattr__(self, name, value)
|
||||
@ -102,7 +102,7 @@ class AutoAttributes(Serializable):
|
||||
# We keep original data (maybe incomplete)
|
||||
for pair in data.decode(AutoAttributes.ACODEC).split('\2'):
|
||||
k, v = pair.split('\1')
|
||||
self.dict[k] = cPickle.loads(v)
|
||||
self.dict[k] = cPickle.loads(str(v))
|
||||
|
||||
def __str__(self):
|
||||
str_ = '<AutoAttribute '
|
||||
|
@ -62,7 +62,7 @@ class Cache(object):
|
||||
expired = now > c.created + timedelta(seconds=c.validity)
|
||||
if expired:
|
||||
return defValue
|
||||
val = cPickle.loads(c.value.decode(Cache.CODEC))
|
||||
val = cPickle.loads(c.value.decode(Cache.CODEC).encode('utf-8'))
|
||||
return val
|
||||
except dbCache.DoesNotExist:
|
||||
logger.debug('key not found')
|
||||
|
@ -88,7 +88,7 @@ class Storage(object):
|
||||
return self.readData(skey)
|
||||
|
||||
def getPickle(self, skey):
|
||||
return cPickle.loads(self.readData(skey))
|
||||
return cPickle.loads(self.readData(skey).encode('uft-8'))
|
||||
|
||||
def remove(self, skey):
|
||||
try:
|
||||
|
@ -157,4 +157,4 @@ def checkBrowser(user_agent, browser):
|
||||
# debug setting in context
|
||||
def context(request):
|
||||
from django.conf import settings
|
||||
return {'DEBUG': settings.DEBUG, 'MINIFY': settings.MINIFY}
|
||||
return {'DEBUG': settings.DEBUG}
|
||||
|
@ -1,3 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2013 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import logging
|
||||
|
||||
|
@ -31,7 +31,4 @@
|
||||
'''
|
||||
import counters
|
||||
|
||||
|
||||
counters._initializeData()
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import cairo
|
||||
@ -45,6 +46,7 @@ CHART_TYPE_LINE, CHART_TYPE_AREA, CHART_TYPE_BAR = xrange(3)
|
||||
|
||||
__typeTitles = None
|
||||
|
||||
|
||||
def make(obj, counterType, **kwargs):
|
||||
|
||||
width, height = (kwargs.get('width', 800), kwargs.get('height', 600))
|
||||
@ -59,23 +61,23 @@ def make(obj, counterType, **kwargs):
|
||||
|
||||
limit = width
|
||||
|
||||
dataset1 = tuple((int(time.mktime(x[0].timetuple())), x[1]) for x in counters.getCounters(obj, counterType, since=since, to=to, limit=limit, use_max = kwargs.get('use_max', False)))
|
||||
dataset1 = tuple((int(time.mktime(x[0].timetuple())), x[1]) for x in counters.getCounters(obj, counterType, since=since, to=to, limit=limit, use_max=kwargs.get('use_max', False)))
|
||||
|
||||
if len(dataset1) == 0:
|
||||
dataset1 = ( (getSqlDatetime(True)-3600, 0), (getSqlDatetime(True), 0) )
|
||||
dataset1 = ((getSqlDatetime(True) - 3600, 0), (getSqlDatetime(True), 0))
|
||||
|
||||
firstLast = (dataset1[0][0], getSqlDatetime(True))
|
||||
|
||||
xLabelFormat = '%y-%m-%d'
|
||||
diffInterval = firstLast[1] - firstLast[0]
|
||||
if diffInterval <= 60*60*24: # Less than one day
|
||||
if diffInterval <= 60 * 60 * 24: # Less than one day
|
||||
xLabelFormat = '%H:%M'
|
||||
elif diffInterval <= 60*60*24*7:
|
||||
elif diffInterval <= 60 * 60 * 24 * 7:
|
||||
xLabelFormat = '%A'
|
||||
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
|
||||
|
||||
dataset = ( ( counters.getCounterTitle(counterType).encode('iso-8859-1', errors='ignore'), dataset1 ),)
|
||||
dataset = ((counters.getCounterTitle(counterType).encode('iso-8859-1', errors='ignore'), dataset1),)
|
||||
|
||||
options = {
|
||||
'axis': {
|
||||
@ -118,4 +120,3 @@ def make(obj, counterType, **kwargs):
|
||||
surface.write_to_png(output)
|
||||
|
||||
return output.getvalue()
|
||||
|
||||
|
@ -40,6 +40,7 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Posible counters, note that not all are used by every posible type
|
||||
# FIRST_COUNTER_TYPE, LAST_COUNTER_TYPE are just a placeholder for sanity checks
|
||||
(
|
||||
@ -52,7 +53,7 @@ __transDict = None
|
||||
__typeTitles = None
|
||||
|
||||
|
||||
def addCounter(obj, counterType, counterValue, stamp = None):
|
||||
def addCounter(obj, counterType, counterValue, stamp=None):
|
||||
'''
|
||||
Adds a counter stat to specified object
|
||||
|
||||
@ -63,7 +64,7 @@ def addCounter(obj, counterType, counterValue, stamp = None):
|
||||
note: Runtime checks are done so if we try to insert an unssuported stat, this won't be inserted and it will be logged
|
||||
'''
|
||||
if type(obj) not in __caWrite.get(counterType, ()):
|
||||
logger.error('Type {0} does not accepts counter of type {1}',format(type(obj), counterValue))
|
||||
logger.error('Type {0} does not accepts counter of type {1}', format(type(obj), counterValue))
|
||||
return False
|
||||
|
||||
return statsManager().addCounter(__transDict[type(obj)], obj.id, counterType, counterValue, stamp)
|
||||
@ -109,14 +110,15 @@ def getCounters(obj, counterType, **kwargs):
|
||||
else:
|
||||
owner_ids = None
|
||||
|
||||
|
||||
for i in statsManager().getCounters(__transDict[type(obj)], counterType, owner_ids, since, to, limit, use_max):
|
||||
val = (datetime.datetime.fromtimestamp(i.stamp), i.value)
|
||||
yield val
|
||||
|
||||
|
||||
def getCounterTitle(counterType):
|
||||
return __typeTitles.get(counterType, '').title()
|
||||
|
||||
|
||||
# Data initialization
|
||||
def _initializeData():
|
||||
'''
|
||||
@ -138,7 +140,6 @@ def _initializeData():
|
||||
CT_INUSE: (DeployedService,),
|
||||
}
|
||||
|
||||
|
||||
# OBtain ids from variups type of object to retrieve stats
|
||||
def get_Id(obj):
|
||||
return obj.id
|
||||
@ -173,12 +174,11 @@ def _initializeData():
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _getIds(obj):
|
||||
to = type(obj)
|
||||
|
||||
if to is DeployedService:
|
||||
return to.id;
|
||||
return to.id
|
||||
|
||||
if to is Service:
|
||||
return (i.id for i in obj.userServices.all())
|
||||
@ -195,9 +195,9 @@ def _initializeData():
|
||||
# Dict to convert objects to owner types
|
||||
# Dict for translations
|
||||
__transDict = {
|
||||
DeployedService : OT_DEPLOYED,
|
||||
Service : OT_SERVICE,
|
||||
Provider : OT_PROVIDER
|
||||
DeployedService: OT_DEPLOYED,
|
||||
Service: OT_SERVICE,
|
||||
Provider: OT_PROVIDER
|
||||
}
|
||||
|
||||
# Titles of types
|
||||
@ -207,4 +207,3 @@ def _initializeData():
|
||||
CT_LOAD: _('Load'),
|
||||
CT_STORAGE: _('Storage')
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
{% load l10n i18n static html5 REST %}{% spaceless %}
|
||||
{% load l10n i18n static compress html5 REST %}{% spaceless %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
{% get_available_languages as LANGUAGES %}
|
||||
<!DOCTYPE html>{% endspaceless %}
|
||||
@ -11,7 +11,8 @@
|
||||
|
||||
<link href="{% get_static_prefix %}img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
|
||||
{% if MINIFY != True %}
|
||||
<!-- minified css from: bootstrap, font-awesome, bootstrap-formhelper, bootstrap-select, bootstrap-switch, datatables, tabletools, tabletools.botstrap, uds CSSs -->
|
||||
{% compress css %}
|
||||
<!-- Bootstrap -->
|
||||
<link href="{% get_static_prefix %}adm/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<link href="{% get_static_prefix %}adm/css/font-awesome.min.css" rel="stylesheet" media="screen">
|
||||
@ -26,10 +27,7 @@
|
||||
<link href="{% get_static_prefix %}adm/css/tables.css" rel="stylesheet" media="screen">
|
||||
<link href="{% get_static_prefix %}adm/css/buttons.css" rel="stylesheet" media="screen">
|
||||
<link href="{% get_static_prefix %}adm/css/uds-admin.css" rel="stylesheet" media="screen">
|
||||
{% else %}
|
||||
<!-- minified css from: bootstrap, font-awesome, bootstrap-formhelper, bootstrap-select, bootstrap-switch, datatables, tabletools, tabletools.botstrap, uds CSSs -->
|
||||
<link href="{% get_static_prefix %}adm/css/admin.min.css" rel="stylesheet" media="screen">
|
||||
{% endif %}
|
||||
{% endcompress %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -44,8 +42,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{% url 'uds.web.views.jsCatalog' LANGUAGE_CODE %}"></script>
|
||||
|
||||
{% compress js %}
|
||||
<script src="{% get_static_prefix %}adm/js/jquery-2.0.3.min.js"></script>
|
||||
|
||||
<script>
|
||||
@ -62,7 +62,8 @@
|
||||
}(window.api = window.api || {}, jQuery));
|
||||
</script>
|
||||
|
||||
{% if MINIFY != True %}
|
||||
<!-- minified js from: 'jquery.cookie', 'bootstrap.min', 'bootstrap-switch.min', 'bootstrap-select.min', 'jquery.validate.min', 'jquery.blockUI', 'flot',
|
||||
'jquery.dataTables.min', 'TableTools.min', 'Blob', 'FileSaver', 'ZeroClipboard', 'dataTables.bootstrap', 'handlebars-v1.1.2', UDS admin JS's -->
|
||||
<script src="{% get_static_prefix %}adm/js/jquery.cookie.js"></script>
|
||||
<script src="{% get_static_prefix %}adm/js/bootstrap.min.js"></script>
|
||||
<script src="{% get_static_prefix %}adm/js/bootstrap-switch.min.js"></script>
|
||||
@ -117,12 +118,6 @@
|
||||
<script src="{% get_static_prefix %}adm/js/gui-d-servicespools.js"></script>
|
||||
<script src="{% get_static_prefix %}adm/js/gui-d-config.js"></script>
|
||||
|
||||
{% else %}
|
||||
<!-- minified js from: 'jquery.cookie', 'bootstrap.min', 'bootstrap-switch.min', 'bootstrap-select.min', 'jquery.validate.min', 'jquery.blockUI', 'flot',
|
||||
'jquery.dataTables.min', 'TableTools.min', 'Blob', 'FileSaver', 'ZeroClipboard', 'dataTables.bootstrap', 'handlebars-v1.1.2', UDS admin JS's -->
|
||||
<script src="{% get_static_prefix %}adm/js/admin.min.js"></script>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
// set default error function
|
||||
@ -132,6 +127,8 @@
|
||||
});
|
||||
</script>
|
||||
{% block js %}{% endblock %}
|
||||
{% endcompress %}
|
||||
|
||||
{% js_template_path 'uds/admin/tmpl' %}
|
||||
<!-- preloading of templates -->
|
||||
<!-- page contents -->
|
||||
|
@ -1,4 +1,4 @@
|
||||
{% load l10n i18n static html5 %}{% spaceless %}
|
||||
{% load l10n i18n static html5 compress %}{% spaceless %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
{% get_available_languages as LANGUAGES %}
|
||||
<!DOCTYPE html>{% endspaceless %}
|
||||
@ -14,13 +14,16 @@
|
||||
{% block icon %}<link href="{% get_static_prefix %}img/favicon.png" rel="icon" type="image/x-icon" />{% endblock %}
|
||||
|
||||
<!-- Bootstrap -->
|
||||
{% compress css %}
|
||||
<link href="{% get_static_prefix %}css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<link href="{% get_static_prefix %}css/font-awesome.min.css" rel="stylesheet" media="screen">
|
||||
{% endcompress %}
|
||||
|
||||
{% ifbrowser ie<9 %}
|
||||
<script src="{% get_static_prefix %}/js/respond.min.js"></script>
|
||||
{% endifbrowser %}
|
||||
|
||||
{% compress css %}
|
||||
<link href="{% get_static_prefix %}css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
|
||||
<link href="{% get_static_prefix %}css/bootstrap-formhelpers.min.css" rel="stylesheet" media="screen">
|
||||
<link href="{% get_static_prefix %}css/bootstrap-select.min.css" rel="stylesheet" media="screen">
|
||||
@ -33,11 +36,15 @@
|
||||
<link href="{% get_static_prefix %}css/bootstrap-switch.css" rel="stylesheet" media="screen">
|
||||
<link href="{% get_static_prefix %}css/uds-html5.css" rel="stylesheet" media="screen">
|
||||
|
||||
{% endcompress %}
|
||||
|
||||
{% compress css %}
|
||||
{% ifbrowser ie<9 %}
|
||||
<script src="{% get_static_prefix %}/js/html5shiv.js"></script>
|
||||
{% endifbrowser %}
|
||||
|
||||
{% block css %}{% endblock %}
|
||||
{% endcompress %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -75,6 +82,7 @@
|
||||
</footer>
|
||||
|
||||
<script src="{% url 'uds.web.views.jsCatalog' LANGUAGE_CODE %}"></script>
|
||||
{% compress js %}
|
||||
<script src="{% get_static_prefix %}js/jquery-1.10.2.min.js"></script>
|
||||
<script src="{% get_static_prefix %}js/jquery.cookie.js"></script>
|
||||
<script src="{% get_static_prefix %}js/bootstrap.min.js"></script>
|
||||
@ -88,5 +96,7 @@
|
||||
</script>
|
||||
|
||||
{% block js %}{% endblock %}
|
||||
{% endcompress %}
|
||||
|
||||
</body>
|
||||
</html>
|
@ -30,6 +30,7 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.http import HttpResponseRedirect
|
||||
@ -80,7 +81,7 @@ def errorString(errorId):
|
||||
|
||||
|
||||
def errorView(request, idError):
|
||||
return HttpResponseRedirect( reverse('uds.web.views.error', kwargs = { 'idError': scrambleId(request, idError) }) )
|
||||
return HttpResponseRedirect(reverse('uds.web.views.error', kwargs={'idError': scrambleId(request, idError)}))
|
||||
|
||||
|
||||
def exceptionView(request, exception):
|
||||
|
@ -30,9 +30,12 @@
|
||||
'''
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from functools import wraps
|
||||
import base64, random, string
|
||||
import base64
|
||||
import random
|
||||
import string
|
||||
|
||||
import logging
|
||||
|
||||
@ -41,6 +44,7 @@ logger = logging.getLogger(__name__)
|
||||
SCRAMBLE_SES = 'scrSid'
|
||||
SCRAMBLE_LEN = 10
|
||||
|
||||
|
||||
# Decorator to make easier protect pages
|
||||
def transformId(view_func):
|
||||
'''
|
||||
@ -64,7 +68,8 @@ def transformId(view_func):
|
||||
def scrambleId(request, id_):
|
||||
if request.session.get(SCRAMBLE_SES) == None:
|
||||
request.session[SCRAMBLE_SES] = ''.join(random.choice(string.letters) for _ in xrange(SCRAMBLE_LEN))
|
||||
return base64.b64encode(str(id_) + request.session.get(SCRAMBLE_SES)).encode('hex')
|
||||
return base64.b64encode(unicode(id_) + request.session.get(SCRAMBLE_SES)).encode('hex')
|
||||
|
||||
|
||||
def unscrambleId(request, id_):
|
||||
idd = base64.b64decode(id_.decode('hex'))
|
||||
|
Loading…
Reference in New Issue
Block a user