1
0
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:
sam
2012-05-22 14:39:34 +02:00
parent 780c50f971
commit 6860778f47
4 changed files with 45 additions and 36 deletions

View File

@ -23,16 +23,16 @@ from bottle import (Bottle, run, static_file, view, request)
import clize
from paste import Paste
from utils import drop_privileges, dmerge, get_pastes_count
from utils import drop_privileges, dmerge
app = Bottle()
GLOBAL_CONTEXT = {
'settings': settings,
'pastes_count': get_pastes_count(),
'pastes_count': Paste.get_pastes_count(),
'refresh_counter': datetime.now()
}
@app.route('/')
@view('home')
@ -66,17 +66,20 @@ def create_paste():
expiration = request.forms.get('expiration', u'burn_after_reading')
paste = Paste(expiration=expiration, content=content)
paste.save()
# display counter
if settings.DISPLAY_COUNTER:
#increment paste counter
paste.increment_counter()
# if refresh time elapsed pick up new counter value
if GLOBAL_CONTEXT['refresh_counter'] + timedelta(seconds=settings.REFRESH_COUNTER) < datetime.now():
GLOBAL_CONTEXT['pastes_count'] = get_pastes_count()
GLOBAL_CONTEXT['refresh_counter'] = datetime.now()
now = datetime.now()
timeout = (GLOBAL_CONTEXT['refresh_counter']
+ timedelta(seconds=settings.REFRESH_COUNTER))
if timeout < now:
GLOBAL_CONTEXT['pastes_count'] = Paste.get_pastes_count()
GLOBAL_CONTEXT['refresh_counter'] = now
return {'status': 'ok',