Mercurial > kallithea
comparison rhodecode/model/db.py @ 2942:f53faff4487e beta
get_or_404 method does validation for ID beeing an INT
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 19 Oct 2012 23:44:35 +0200 |
parents | d439d408b415 |
children | 78227b65a358 |
comparison
equal
deleted
inserted
replaced
2941:d0c2299d08d4 | 2942:f53faff4487e |
---|---|
116 if id_: | 116 if id_: |
117 return cls.query().get(id_) | 117 return cls.query().get(id_) |
118 | 118 |
119 @classmethod | 119 @classmethod |
120 def get_or_404(cls, id_): | 120 def get_or_404(cls, id_): |
121 if id_: | 121 try: |
122 res = cls.query().get(id_) | 122 id_ = int(id_) |
123 if not res: | 123 except (TypeError, ValueError): |
124 raise HTTPNotFound | 124 raise HTTPNotFound |
125 return res | 125 |
126 res = cls.query().get(id_) | |
127 if not res: | |
128 raise HTTPNotFound | |
129 return res | |
126 | 130 |
127 @classmethod | 131 @classmethod |
128 def getAll(cls): | 132 def getAll(cls): |
129 return cls.query().all() | 133 return cls.query().all() |
130 | 134 |