From c770457883a34ebc1672fe707f8753aacd0a0182 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 1 May 2012 20:20:10 +0700 Subject: [PATCH] merge --- settings.py | 2 +- src/paste.py | 16 +++++++--------- start.py | 14 +++++++++----- static/css/style.css | 4 ++++ views/paste.tpl | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/settings.py b/settings.py index 537cee6..e4e2866 100644 --- a/settings.py +++ b/settings.py @@ -29,4 +29,4 @@ GROUP = None # limit size of pasted text in bytes. Be carefull allowing too much size can slow down user's # browser -MAX_SIZE = 500 * 1000 \ No newline at end of file +MAX_SIZE = 1024 * 50 diff --git a/src/paste.py b/src/paste.py index 687d8b4..b2d8f27 100644 --- a/src/paste.py +++ b/src/paste.py @@ -153,15 +153,13 @@ class Paste(object): if self.expiration == "burn_after_reading": self.expiration = self.expiration + '#%s' % datetime.now() - # write the paste - try: - with open(self.path, 'w') as f: - f.write(unicode(self.expiration) + '\n') - f.write(self.content + '\n') - if self.comments: - f.write(comments) - except Exception as e: - import ipdb; ipdb.set_trace() + # write the paste + with open(self.path, 'w') as f: + f.write(unicode(self.expiration) + '\n') + f.write(self.content + '\n') + if self.comments: + f.write(comments) + return self diff --git a/start.py b/start.py index 3586504..839b962 100644 --- a/start.py +++ b/start.py @@ -54,11 +54,15 @@ def create_paste(): return '' if content: - expiration = request.forms.get('expiration', u'burn_after_reading') - paste = Paste(expiration=expiration, content=content) - paste.save() - return {'status': 'ok', - 'paste': paste.uuid} + # check size of the paste. if more than settings return error without saving paste. + # prevent from unusual use of the system. + # need to be improved + if len(content) < settings.MAX_SIZE: + expiration = request.forms.get('expiration', u'burn_after_reading') + paste = Paste(expiration=expiration, content=content) + paste.save() + return {'status': 'ok', + 'paste': paste.uuid} return {'status': 'error', 'message': u"Serveur error: the paste couldn't be saved. Please try later."} diff --git a/static/css/style.css b/static/css/style.css index e3addf0..efd437d 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -259,6 +259,10 @@ button.btn, input[type="submit"].btn { top:-4px; } +#alert-template { + display: none; +} + /** Progress bar */ .progress { diff --git a/views/paste.tpl b/views/paste.tpl index dd9739b..c2f5029 100644 --- a/views/paste.tpl +++ b/views/paste.tpl @@ -74,4 +74,4 @@ -%rebase base +%rebase base