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 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.
|
||||
|
Reference in New Issue
Block a user