##// END OF EJS Templates
models: allow different exception between pylons and pyramid for get_or_404 view.
marcink -
r1512:82b03f22 default
parent child Browse files
Show More
@@ -42,7 +42,6 b' from sqlalchemy.orm import ('
42 42 relationship, joinedload, class_mapper, validates, aliased)
43 43 from sqlalchemy.sql.expression import true
44 44 from beaker.cache import cache_region
45 from webob.exc import HTTPNotFound
46 45 from zope.cachedescriptors.property import Lazy as LazyProperty
47 46
48 47 from pylons import url
@@ -207,7 +206,14 b' class BaseModel(object):'
207 206 return cls.query().get(id_)
208 207
209 208 @classmethod
210 def get_or_404(cls, id_):
209 def get_or_404(cls, id_, pyramid_exc=False):
210 if pyramid_exc:
211 # NOTE(marcink): backward compat, once migration to pyramid
212 # this should only use pyramid exceptions
213 from pyramid.httpexceptions import HTTPNotFound
214 else:
215 from webob.exc import HTTPNotFound
216
211 217 try:
212 218 id_ = int(id_)
213 219 except (TypeError, ValueError):
@@ -3624,7 +3630,13 b' class Gist(Base, BaseModel):'
3624 3630 return '<Gist:[%s]%s>' % (self.gist_type, self.gist_access_id)
3625 3631
3626 3632 @classmethod
3627 def get_or_404(cls, id_):
3633 def get_or_404(cls, id_, pyramid_exc=False):
3634
3635 if pyramid_exc:
3636 from pyramid.httpexceptions import HTTPNotFound
3637 else:
3638 from webob.exc import HTTPNotFound
3639
3628 3640 res = cls.query().filter(cls.gist_access_id == id_).scalar()
3629 3641 if not res:
3630 3642 raise HTTPNotFound
General Comments 0
You need to be logged in to leave comments. Login now