1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

Added refresh timer for counter

This commit is contained in:
max 2012-05-21 23:21:06 +07:00
parent 26fd2d0913
commit 7e4a12a263
2 changed files with 15 additions and 3 deletions

View File

@ -53,9 +53,11 @@ PORT = "8000"
USER = None
GROUP = None
# Display a tiny counter for pastes created
# Display a tiny counter for pastes created.
# Be carreful if your site have to many pastes this can hurt your hard drive performances.
# Refresh counter interval. Default to every minute after a paste.
DISPLAY_COUNTER = True
REFRESH_COUNTER = 60 * 1
# Names/links to insert in the menu bar.
# Any link with "mailto:" will be escaped to prevent spam

View File

@ -29,9 +29,10 @@ from utils import drop_privileges, dmerge, get_pastes_count
app = Bottle()
GLOBAL_CONTEXT = {
'settings': settings,
'pastes_count': get_pastes_count()
'pastes_count': get_pastes_count(),
'refresh_counter': datetime.now()
}
@app.route('/')
@view('home')
@ -66,8 +67,17 @@ def create_paste():
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()
return {'status': 'ok',
'paste': paste.uuid}