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

@ -2,6 +2,7 @@
import os
import hashlib
import locale
from datetime import datetime, timedelta
@ -112,10 +113,10 @@ class Paste(object):
return cls.load_from_file(cls.get_path(uuid))
def increment_counter(self):
"""
Increment pastes counter
Increment pastes counter
"""
# simple counter incrementation
@ -131,7 +132,7 @@ class Paste(object):
try:
#make lock file
flock = open(lock_file, "w")
flock.write('lock')
flock.write('lock')
flock.close()
# init counter (first time)
@ -205,6 +206,27 @@ class Paste(object):
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):
"""
Delete the paste file.