# HG changeset patch # User Sverre Rabbelier # Date 1235505100 0 # Node ID c417a4188e7308eaf64205cf3b623a9002849ced # Parent 430df988d3953126df006a3cd1862314598c50b8 Added a checkHasAny method A simple 'OR' for checkers. Patch by: Sverre Rabbelier diff -r 430df988d395 -r c417a4188e73 app/soc/views/helper/access.py --- a/app/soc/views/helper/access.py Tue Feb 24 19:49:27 2009 +0000 +++ b/app/soc/views/helper/access.py Tue Feb 24 19:51:40 2009 +0000 @@ -426,6 +426,29 @@ if not self.hasMembership(roles, django_args): raise out_of_band.AccessViolation(message_fmt) + def checkHasAny(self, django_args, checks): + """Checks if any of the checks passes. + + If none of the specified checks passes, the exception that the first of the + checks raised is reraised. + """ + + first = None + + for checker_name, args in checks: + try: + self.doCheck(checker_name, django_args, args) + break + except out_of_band.Error, e: + # store the first esception + first = first if first else e + else: + # one check passed, all is well + return + + # none passed, re-raise the first exception + raise first + def allow(self, django_args): """Never raises an alternate HTTP response. (an access no-op, basically).