app/soc/views/helper/access.py
changeset 2543 4c95d717a976
parent 2538 c82fbf7fbad0
child 2583 3a8275049403
equal deleted inserted replaced
2542:a9dec4763c6b 2543:4c95d717a976
  1569     self.checkMembership('write', survey.prefix,
  1569     self.checkMembership('write', survey.prefix,
  1570                          survey.write_access, django_args)
  1570                          survey.write_access, django_args)
  1571 
  1571 
  1572   @denySidebar
  1572   @denySidebar
  1573   @allowDeveloper
  1573   @allowDeveloper
  1574   def checkIsSurveyTakeable(self, django_args, survey_logic):
  1574   def checkIsSurveyTakeable(self, django_args, survey_logic, check_time=True):
  1575     """Checks if the survey specified in django_args can be taken.
  1575     """Checks if the survey specified in django_args can be taken.
  1576 
  1576 
  1577     Uses survey.taking_access to map that string onto a check. Also checks for
  1577     Uses survey.taking_access to map that string onto a check. Also checks for
  1578     survey start and end.
  1578     survey start and end.
  1579 
  1579 
  1584       student: user is student for the program
  1584       student: user is student for the program
  1585       user: valid user on the website
  1585       user: valid user on the website
  1586 
  1586 
  1587     Args:
  1587     Args:
  1588       survey_logic: SurveyLogic instance (or subclass)
  1588       survey_logic: SurveyLogic instance (or subclass)
       
  1589       check_time: iff True checks if the current date is between the survey
       
  1590         start and end date.
  1589     """
  1591     """
  1590 
  1592 
  1591     if django_args['prefix'] != 'program':
  1593     if django_args['prefix'] != 'program':
  1592       # TODO: update when generic surveys are allowed
  1594       # TODO: update when generic surveys are allowed
  1593       return self.deny(django_args)
  1595       return self.deny(django_args)
  1594 
  1596 
  1595     # get the survey from django_args
  1597     # get the survey from django_args
  1596     survey = survey_logic.getFromKeyFieldsOr404(django_args)
  1598     survey = survey_logic.getFromKeyFieldsOr404(django_args)
  1597 
  1599 
  1598     # check if the survey can be taken now
  1600     # check if the survey can be taken now
  1599     if not timeline_helper.isActivePeriod(survey, 'survey'):
  1601     if check_time and not timeline_helper.isActivePeriod(survey, 'survey'):
  1600       raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG)
  1602       raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG)
  1601 
  1603 
  1602     # retrieve the role that is allowed to take this survey
  1604     # retrieve the role that is allowed to take this survey
  1603     role = survey.taking_access
  1605     role = survey.taking_access
  1604 
  1606