app/soc/views/helper/access.py
changeset 1922 800ec7253cf4
parent 1876 a77d4cdcc052
child 1995 768f533d91e3
--- a/app/soc/views/helper/access.py	Wed Mar 18 15:29:25 2009 +0000
+++ b/app/soc/views/helper/access.py	Wed Mar 18 16:14:29 2009 +0000
@@ -965,6 +965,40 @@
 
     raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG)
 
+  @allowDeveloper
+  @denySidebar
+  def checkisAfterEvent(self, django_args, event_name, key_name_arg):
+    """Checks if the given event has taken place for the given program.
+
+    Args:
+      django_args: a dictionary with django's arguments
+      event_name: the name of the event which is checked
+      key_name_arg: the entry in django_args that specifies the given program
+        keyname. If none is given the key_name is constructed from django_args
+        itself.
+
+    Raises:
+      AccessViolationResponse:
+      * if no active Program is found
+      * if the event has not taken place yet
+    """
+
+    if key_name_arg and key_name_arg in django_args:
+      key_name = django_args[key_name_arg]
+    else:
+      key_name = program_logic.getKeyNameFromFields(django_args)
+
+    program_entity = program_logic.getFromKeyName(key_name)
+
+    if not program_entity or (
+        program_entity.status in ['inactive', 'invalid']):
+      raise out_of_band.AccessViolation(message_fmt=DEF_SCOPE_INACTIVE_MSG)
+
+    if timeline_helper.isAfterEvent(program_entity.timeline, event_name):
+      return
+
+    raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG)
+
   def checkCanCreateOrgApp(self, django_args, period_name):
     """Checks to see if the program in the scope_path is accepting org apps