mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Prevent 0bin to crash if the locale formatting is not supported. Moved get_pastes_count into the Paste class. Added 0bin version as query parameter in the scrip and css tags URL
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import locale
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
@@ -205,6 +206,27 @@ class Paste(object):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_pastes_count(cls):
|
||||||
|
"""
|
||||||
|
Return the number of created pastes.
|
||||||
|
(must have option DISPLAY_COUNTER enabled for the pastes to be
|
||||||
|
be counted)
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_ALL, 'en_US')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
counter_file = os.path.join(settings.PASTE_FILES_ROOT, 'counter')
|
||||||
|
try:
|
||||||
|
count = long(open(counter_file).read(50))
|
||||||
|
except (IOError, OSError):
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
return locale.format("%d", long(count), grouping=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
"""
|
"""
|
||||||
Delete the paste file.
|
Delete the paste file.
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ from bottle import (Bottle, run, static_file, view, request)
|
|||||||
import clize
|
import clize
|
||||||
|
|
||||||
from paste import Paste
|
from paste import Paste
|
||||||
from utils import drop_privileges, dmerge, get_pastes_count
|
from utils import drop_privileges, dmerge
|
||||||
|
|
||||||
|
|
||||||
app = Bottle()
|
app = Bottle()
|
||||||
GLOBAL_CONTEXT = {
|
GLOBAL_CONTEXT = {
|
||||||
'settings': settings,
|
'settings': settings,
|
||||||
'pastes_count': get_pastes_count(),
|
'pastes_count': Paste.get_pastes_count(),
|
||||||
'refresh_counter': datetime.now()
|
'refresh_counter': datetime.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,9 +74,12 @@ def create_paste():
|
|||||||
paste.increment_counter()
|
paste.increment_counter()
|
||||||
|
|
||||||
# if refresh time elapsed pick up new counter value
|
# if refresh time elapsed pick up new counter value
|
||||||
if GLOBAL_CONTEXT['refresh_counter'] + timedelta(seconds=settings.REFRESH_COUNTER) < datetime.now():
|
now = datetime.now()
|
||||||
GLOBAL_CONTEXT['pastes_count'] = get_pastes_count()
|
timeout = (GLOBAL_CONTEXT['refresh_counter']
|
||||||
GLOBAL_CONTEXT['refresh_counter'] = datetime.now()
|
+ timedelta(seconds=settings.REFRESH_COUNTER))
|
||||||
|
if timeout < now:
|
||||||
|
GLOBAL_CONTEXT['pastes_count'] = Paste.get_pastes_count()
|
||||||
|
GLOBAL_CONTEXT['refresh_counter'] = now
|
||||||
|
|
||||||
|
|
||||||
return {'status': 'ok',
|
return {'status': 'ok',
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import os
|
|||||||
import glob
|
import glob
|
||||||
import tempfile
|
import tempfile
|
||||||
import sys
|
import sys
|
||||||
import locale
|
|
||||||
|
|
||||||
import default_settings
|
import default_settings
|
||||||
sys.path.append(default_settings.LIBS_DIR)
|
sys.path.append(default_settings.LIBS_DIR)
|
||||||
@@ -54,23 +53,6 @@ def dmerge(*args):
|
|||||||
return dictionary
|
return dictionary
|
||||||
|
|
||||||
|
|
||||||
def get_pastes_count():
|
|
||||||
"""
|
|
||||||
Return the number of pastes created (must have option DISPLAY_COUNTER enabled)
|
|
||||||
"""
|
|
||||||
locale.setlocale(locale.LC_ALL, 'en_US')
|
|
||||||
counter_path = settings.PASTE_FILES_ROOT
|
|
||||||
counter_file = os.path.join(counter_path, 'counter')
|
|
||||||
try:
|
|
||||||
with open(counter_file, "r") as f:
|
|
||||||
count = f.read(50)
|
|
||||||
f.close
|
|
||||||
except IOError:
|
|
||||||
count = 0
|
|
||||||
|
|
||||||
return locale.format("%d", long(float(count)), grouping=True)
|
|
||||||
|
|
||||||
|
|
||||||
class SettingsContainer(object):
|
class SettingsContainer(object):
|
||||||
"""
|
"""
|
||||||
Singleton containing the settings for the whole app
|
Singleton containing the settings for the whole app
|
||||||
|
|||||||
@@ -12,11 +12,13 @@
|
|||||||
<link rel="shortcut icon" href="/favicon.ico">
|
<link rel="shortcut icon" href="/favicon.ico">
|
||||||
|
|
||||||
%if settings.COMPRESSED_STATIC_FILES:
|
%if settings.COMPRESSED_STATIC_FILES:
|
||||||
<link href="/static/css/style.min.css" rel="stylesheet" />
|
<link href="/static/css/style.min.css?{{ settings.VERSION }}"
|
||||||
|
rel="stylesheet" />
|
||||||
%else:
|
%else:
|
||||||
<link href="/static/css/prettify.css" rel="stylesheet" />
|
<link href="/static/css/prettify.css" rel="stylesheet" />
|
||||||
<link href="/static/css/bootstrap.css" rel="stylesheet">
|
<link href="/static/css/bootstrap.css" rel="stylesheet">
|
||||||
<link href="/static/css/style.css" rel="stylesheet">
|
<link href="/static/css/style.css?{{ settings.VERSION }}"
|
||||||
|
rel="stylesheet">
|
||||||
%end
|
%end
|
||||||
|
|
||||||
<!-- Le HTML5 shim, for IE7-8 support of HTML5 elements -->
|
<!-- Le HTML5 shim, for IE7-8 support of HTML5 elements -->
|
||||||
@@ -25,11 +27,11 @@
|
|||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
%if settings.COMPRESSED_STATIC_FILES:
|
%if settings.COMPRESSED_STATIC_FILES:
|
||||||
<script src="/static/js/main.min.js"></script>
|
<script src="/static/js/main.min.js?{{ settings.VERSION }}"></script>
|
||||||
%else:
|
%else:
|
||||||
<script src="/static/js/jquery-1.7.2.min.js"></script>
|
<script src="/static/js/jquery-1.7.2.min.js"></script>
|
||||||
<script src="/static/js/sjcl.js"></script>
|
<script src="/static/js/sjcl.js"></script>
|
||||||
<script src="/static/js/behavior.js"></script>
|
<script src="/static/js/behavior.js?{{ settings.VERSION }}"></script>
|
||||||
%end
|
%end
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -144,7 +146,7 @@
|
|||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
%if settings.COMPRESSED_STATIC_FILES:
|
%if settings.COMPRESSED_STATIC_FILES:
|
||||||
<script src="/static/js/additional.min.js"></script>
|
<script src="/static/js/additional.min.js?{{ settings.VERSION }}"></script>
|
||||||
%else:
|
%else:
|
||||||
<script src="/static/js/jquery.elastic.source.js"></script>
|
<script src="/static/js/jquery.elastic.source.js"></script>
|
||||||
<script src="/static/js/lzw.js"></script>
|
<script src="/static/js/lzw.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user