From b9845a2dc10ab70ffb1cecf8b37ea39b93019341 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Thu, 20 Jun 2013 14:28:35 +0530 Subject: [PATCH] Allowed superuser to edit posts in threads. Catch IntegrityError in TryCatchDecorator Check for duplicate title in threads --- brewman/brewman/models/messaging.py | 6 +++++ .../brewman/models/validation_exception.py | 4 +-- brewman/brewman/static/offline.appcache | 2 +- .../static/partial/message-detail.html | 4 +-- .../static/scripts/angular_directive.js | 24 ++++++++---------- brewman/brewman/static/scripts/message.js | 11 +++++--- brewman/brewman/views/messaging.py | 25 +++++++++++++++---- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/brewman/brewman/models/messaging.py b/brewman/brewman/models/messaging.py index 7e08d012..27c64cab 100644 --- a/brewman/brewman/models/messaging.py +++ b/brewman/brewman/models/messaging.py @@ -73,6 +73,10 @@ class Thread(Base): def by_id(cls, id): return DBSession.query(cls).filter(cls.id == id).first() + @classmethod + def by_title(cls, title): + return DBSession.query(cls).filter(cls.title == title).first() + @classmethod def list(cls): return DBSession.query(cls).all() @@ -102,6 +106,8 @@ class Post(Base): @classmethod def by_id(cls, id): + if not isinstance(id, uuid.UUID): + id = uuid.UUID(id) return DBSession.query(cls).filter(cls.id == id).first() @classmethod diff --git a/brewman/brewman/models/validation_exception.py b/brewman/brewman/models/validation_exception.py index 17ce7c97..29607b9f 100644 --- a/brewman/brewman/models/validation_exception.py +++ b/brewman/brewman/models/validation_exception.py @@ -1,5 +1,5 @@ from pyramid.response import Response -from sqlalchemy.exc import OperationalError +from sqlalchemy.exc import OperationalError, IntegrityError import transaction class ValidationError(Exception): @@ -18,7 +18,7 @@ def TryCatchFunction(f): def _decorator(self, *args, **kwargs): try: return f(self, *args, **kwargs) - except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError) as ex: + except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError, IntegrityError) as ex: transaction.abort() response = Response("Failed validation: {0}".format(str(ex))) response.status_int = 500 diff --git a/brewman/brewman/static/offline.appcache b/brewman/brewman/static/offline.appcache index 8a4cb039..1cd19418 100644 --- a/brewman/brewman/static/offline.appcache +++ b/brewman/brewman/static/offline.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# version 2013-06-07.1 +# version 2013-06-19.1 CACHE: /partial/404.html diff --git a/brewman/brewman/static/partial/message-detail.html b/brewman/brewman/static/partial/message-detail.html index a366c673..0f38de66 100644 --- a/brewman/brewman/static/partial/message-detail.html +++ b/brewman/brewman/static/partial/message-detail.html @@ -44,14 +44,14 @@