##// END OF EJS Templates
core: no longer rely on webob exception inside get_or_404 function....
marcink -
r1956:a7a935de default
parent child Browse files
Show More
@@ -221,6 +221,7 b' class RepoAppView(BaseAppView):'
221 221
222 222 return default
223 223
224
224 225 class DataGridAppView(object):
225 226 """
226 227 Common class to have re-usable grid rendering components
@@ -55,7 +55,7 b' class AdminMainView(BaseAppView):'
55 55 """
56 56
57 57 pull_request_id = self.request.matchdict.get('pull_request_id')
58 pull_request = PullRequest.get_or_404(pull_request_id, pyramid_exc=True)
58 pull_request = PullRequest.get_or_404(pull_request_id)
59 59 repo_name = pull_request.target_repo.repo_name
60 60
61 61 raise HTTPFound(
@@ -159,7 +159,7 b' class AdminUsersView(BaseAppView, DataGr'
159 159 c = self.load_default_context()
160 160
161 161 user_id = self.request.matchdict.get('user_id')
162 c.user = User.get_or_404(user_id, pyramid_exc=True)
162 c.user = User.get_or_404(user_id)
163 163 self._redirect_for_default_user(c.user.username)
164 164
165 165 c.active = 'auth_tokens'
@@ -194,7 +194,7 b' class AdminUsersView(BaseAppView, DataGr'
194 194 c = self.load_default_context()
195 195
196 196 user_id = self.request.matchdict.get('user_id')
197 c.user = User.get_or_404(user_id, pyramid_exc=True)
197 c.user = User.get_or_404(user_id)
198 198
199 199 self._redirect_for_default_user(c.user.username)
200 200
@@ -227,14 +227,14 b' class AdminUsersView(BaseAppView, DataGr'
227 227 c = self.load_default_context()
228 228
229 229 user_id = self.request.matchdict.get('user_id')
230 c.user = User.get_or_404(user_id, pyramid_exc=True)
230 c.user = User.get_or_404(user_id)
231 231 self._redirect_for_default_user(c.user.username)
232 232 user_data = c.user.get_api_data()
233 233
234 234 del_auth_token = self.request.POST.get('del_auth_token')
235 235
236 236 if del_auth_token:
237 token = UserApiKeys.get_or_404(del_auth_token, pyramid_exc=True)
237 token = UserApiKeys.get_or_404(del_auth_token)
238 238 token_data = token.get_api_data()
239 239
240 240 AuthTokenModel().delete(del_auth_token, c.user.user_id)
@@ -257,7 +257,7 b' class AdminUsersView(BaseAppView, DataGr'
257 257 c = self.load_default_context()
258 258
259 259 user_id = self.request.matchdict.get('user_id')
260 c.user = User.get_or_404(user_id, pyramid_exc=True)
260 c.user = User.get_or_404(user_id)
261 261 self._redirect_for_default_user(c.user.username)
262 262
263 263 c.active = 'emails'
@@ -276,7 +276,7 b' class AdminUsersView(BaseAppView, DataGr'
276 276 c = self.load_default_context()
277 277
278 278 user_id = self.request.matchdict.get('user_id')
279 c.user = User.get_or_404(user_id, pyramid_exc=True)
279 c.user = User.get_or_404(user_id)
280 280 self._redirect_for_default_user(c.user.username)
281 281
282 282 email = self.request.POST.get('new_email')
@@ -307,7 +307,7 b' class AdminUsersView(BaseAppView, DataGr'
307 307 c = self.load_default_context()
308 308
309 309 user_id = self.request.matchdict.get('user_id')
310 c.user = User.get_or_404(user_id, pyramid_exc=True)
310 c.user = User.get_or_404(user_id)
311 311 self._redirect_for_default_user(c.user.username)
312 312
313 313 email_id = self.request.POST.get('del_email_id')
@@ -334,7 +334,7 b' class AdminUsersView(BaseAppView, DataGr'
334 334 c = self.load_default_context()
335 335
336 336 user_id = self.request.matchdict.get('user_id')
337 c.user = User.get_or_404(user_id, pyramid_exc=True)
337 c.user = User.get_or_404(user_id)
338 338 self._redirect_for_default_user(c.user.username)
339 339
340 340 c.active = 'ips'
@@ -357,7 +357,7 b' class AdminUsersView(BaseAppView, DataGr'
357 357 c = self.load_default_context()
358 358
359 359 user_id = self.request.matchdict.get('user_id')
360 c.user = User.get_or_404(user_id, pyramid_exc=True)
360 c.user = User.get_or_404(user_id)
361 361 # NOTE(marcink): this view is allowed for default users, as we can
362 362 # edit their IP white list
363 363
@@ -407,7 +407,7 b' class AdminUsersView(BaseAppView, DataGr'
407 407 c = self.load_default_context()
408 408
409 409 user_id = self.request.matchdict.get('user_id')
410 c.user = User.get_or_404(user_id, pyramid_exc=True)
410 c.user = User.get_or_404(user_id)
411 411 # NOTE(marcink): this view is allowed for default users, as we can
412 412 # edit their IP white list
413 413
@@ -436,7 +436,7 b' class AdminUsersView(BaseAppView, DataGr'
436 436 c = self.load_default_context()
437 437
438 438 user_id = self.request.matchdict.get('user_id')
439 c.user = User.get_or_404(user_id, pyramid_exc=True)
439 c.user = User.get_or_404(user_id)
440 440 c.data = c.user.group_member
441 441 self._redirect_for_default_user(c.user.username)
442 442 groups = [UserGroupModel.get_user_groups_as_dict(group.users_group)
@@ -456,7 +456,7 b' class AdminUsersView(BaseAppView, DataGr'
456 456 c = self.load_default_context()
457 457
458 458 user_id = self.request.matchdict.get('user_id')
459 c.user = User.get_or_404(user_id, pyramid_exc=True)
459 c.user = User.get_or_404(user_id)
460 460 self._redirect_for_default_user(c.user.username)
461 461
462 462 users_groups = set(self.request.POST.getall('users_group_id'))
@@ -484,7 +484,7 b' class AdminUsersView(BaseAppView, DataGr'
484 484 c = self.load_default_context()
485 485
486 486 user_id = self.request.matchdict.get('user_id')
487 c.user = User.get_or_404(user_id, pyramid_exc=True)
487 c.user = User.get_or_404(user_id)
488 488 self._redirect_for_default_user(c.user.username)
489 489 c.active = 'audit'
490 490
@@ -211,7 +211,7 b' class MyAccountView(BaseAppView, DataGri'
211 211 del_auth_token = self.request.POST.get('del_auth_token')
212 212
213 213 if del_auth_token:
214 token = UserApiKeys.get_or_404(del_auth_token, pyramid_exc=True)
214 token = UserApiKeys.get_or_404(del_auth_token)
215 215 token_data = token.get_api_data()
216 216
217 217 AuthTokenModel().delete(del_auth_token, c.user.user_id)
@@ -279,7 +279,7 b' class MyAccountView(BaseAppView, DataGri'
279 279
280 280 del_email_id = self.request.POST.get('del_email_id')
281 281 if del_email_id:
282 email = UserEmailMap.get_or_404(del_email_id, pyramid_exc=True).email
282 email = UserEmailMap.get_or_404(del_email_id).email
283 283 UserModel().delete_extra_email(c.user.user_id, del_email_id)
284 284 audit_logger.store_web(
285 285 'user.edit.email.delete', action_data={
@@ -492,7 +492,7 b' class RepoCommitsView(RepoAppView):'
492 492 commit_id = self.request.matchdict['commit_id']
493 493 comment_id = self.request.matchdict['comment_id']
494 494
495 comment = ChangesetComment.get_or_404(safe_int(comment_id))
495 comment = ChangesetComment.get_or_404(comment_id)
496 496 if not comment:
497 497 log.debug('Comment with id:%s not found, skipping', comment_id)
498 498 # comment already deleted in another call probably
@@ -987,7 +987,7 b' class PullrequestsController(BaseRepoCon'
987 987 @auth.CSRFRequired()
988 988 @jsonify
989 989 def delete_comment(self, repo_name, comment_id):
990 comment = ChangesetComment.get_or_404(safe_int(comment_id))
990 comment = ChangesetComment.get_or_404(comment_id)
991 991 if not comment:
992 992 log.debug('Comment with id:%s not found, skipping', comment_id)
993 993 # comment already deleted in another call probably
@@ -206,22 +206,17 b' class BaseModel(object):'
206 206 return cls.query().get(id_)
207 207
208 208 @classmethod
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
209 def get_or_404(cls, id_):
213 210 from pyramid.httpexceptions import HTTPNotFound
214 else:
215 from webob.exc import HTTPNotFound
216 211
217 212 try:
218 213 id_ = int(id_)
219 214 except (TypeError, ValueError):
220 raise HTTPNotFound
215 raise HTTPNotFound()
221 216
222 217 res = cls.query().get(id_)
223 218 if not res:
224 raise HTTPNotFound
219 raise HTTPNotFound()
225 220 return res
226 221
227 222 @classmethod
@@ -3776,16 +3771,12 b' class Gist(Base, BaseModel):'
3776 3771 return h.escape(self.gist_description)
3777 3772
3778 3773 @classmethod
3779 def get_or_404(cls, id_, pyramid_exc=False):
3780
3781 if pyramid_exc:
3774 def get_or_404(cls, id_):
3782 3775 from pyramid.httpexceptions import HTTPNotFound
3783 else:
3784 from webob.exc import HTTPNotFound
3785 3776
3786 3777 res = cls.query().filter(cls.gist_access_id == id_).scalar()
3787 3778 if not res:
3788 raise HTTPNotFound
3779 raise HTTPNotFound()
3789 3780 return res
3790 3781
3791 3782 @classmethod
General Comments 0
You need to be logged in to leave comments. Login now