Added new access method that can check if a given event has taken place already.
authorLennard de Rijk <ljvderijk@gmail.com>
Wed, 18 Mar 2009 16:14:29 +0000
changeset 1922 800ec7253cf4
parent 1921 d92c5f08f24d
child 1923 ba42b6cda8cc
Added new access method that can check if a given event has taken place already. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/views/helper/access.py
--- 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