Example #1
0
    def context(self, data, check, mutator):
        """See base.RequestHandler.context for specification."""
        form_data = data.url_ndb_org.to_dict()

        # initialize list of tags as comma separated list of values
        form_data["tags"] = ", ".join(form_data["tags"])

        if data.url_ndb_org.contact:
            form_data.update(data.url_ndb_org.contact.to_dict())

        form = _formToEditOrgProfile(request_data=data, data=data.POST or form_data)

        # add a reminder if no application has been submitted and it is still
        # before the deadline
        if not org_logic.getApplicationResponse(data.url_ndb_org.key) and time_utils.isBefore(data.org_app.survey_end):
            url = links.LINKER.organization(data.url_ndb_org.key, urls.UrlNames.ORG_APPLICATION_SUBMIT)
            deadline = data.org_app.survey_end
            org_application_reminder = OrgApplicationReminder(url, deadline)
        else:
            org_application_reminder = None

        return {
            "page_name": ORG_PROFILE_EDIT_PAGE_NAME,
            "forms": [form],
            "error": bool(form.errors),
            "tabs": tabs.orgTabs(data, selected_tab_id=tabs.ORG_PROFILE_TAB_ID),
            "org_application_reminder": org_application_reminder,
        }
Example #2
0
  def context(self, data, check, mutator):
    """See base.RequestHandler.context for specification."""
    form_data = data.url_ndb_org.to_dict()

    # initialize list of tags as comma separated list of values
    form_data['tags'] = ', '.join(form_data['tags'])

    if data.url_ndb_org.contact:
      form_data.update(data.url_ndb_org.contact.to_dict())

    form = _formToEditOrgProfile(request_data=data, data=data.POST or form_data)

    # add a reminder if no application has been submitted and it is still
    # before the deadline
    if (not org_logic.getApplicationResponse(data.url_ndb_org.key) and
        time_utils.isBefore(data.org_app.survey_end)):
      url = links.LINKER.organization(
          data.url_ndb_org.key, urls.UrlNames.ORG_APPLICATION_SUBMIT)
      deadline = data.org_app.survey_end
      org_application_reminder = OrgApplicationReminder(url, deadline)
    else:
      org_application_reminder = None

    return {
        'page_name': ORG_PROFILE_EDIT_PAGE_NAME,
        'forms': [form],
        'error': bool(form.errors),
        'tabs': tabs.orgTabs(data, selected_tab_id=tabs.ORG_PROFILE_TAB_ID),
        'org_application_reminder': org_application_reminder,
        }
Example #3
0
  def beforeProgramStart(self):
    """Returns a bool indicating whether the program start date has passed
    or not.

    Returns:
      True if he current data is before program start date; False otherwise
    """
    return time.isBefore(self.timeline.program_start)
Example #4
0
  def beforeStudentSignup(self):
    """Returns a bool indicating whether the student signup start date
    has already passed or not.

    Returns:
      True if he current data is before student signup date; False otherwise
    """
    return time.isBefore(self.studentSignupStart())
Example #5
0
    def state(self):
        """Returns state of the period with respect to the current moment in time.

    For the period bounded at both start and end,there are
    three possibilities. The current moment may be:
    - before the period
    - in the period
    - after the period

    For a period with no start date defined, the current moment may be:
    - in the period
    - after the period

    For period with no end date defined, the current moment may be:
    - before the period
    - in the period

    Returns:
      A constant representing the current state of the period. Can be one of
      PRE_PERIOD_STATE, IN_PERIOD_STATE or POST_PERIOD_STATE.
    """
        # unbounded period
        if not self.start and not self.end:
            return IN_PERIOD_STATE

        # period right-unbounded
        elif self.start and not self.end:
            if time.isBefore(self.start):
                return PRE_PERIOD_STATE
            else:
                return IN_PERIOD_STATE

        # period left-unbounded
        elif not self.start and self.end:
            if time.isAfter(self.end):
                return POST_PERIOD_STATE
            else:
                return IN_PERIOD_STATE

        # period bounded
        elif time.isBefore(self.start):
            return PRE_PERIOD_STATE
        elif time.isAfter(self.end):
            return POST_PERIOD_STATE
        else:
            return IN_PERIOD_STATE
Example #6
0
  def state(self):
    """Returns state of the period with respect to the current moment in time.

    For the period bounded at both start and end,there are
    three possibilities. The current moment may be:
    - before the period
    - in the period
    - after the period

    For a period with no start date defined, the current moment may be:
    - in the period
    - after the period

    For period with no end date defined, the current moment may be:
    - before the period
    - in the period

    Returns:
      A constant representing the current state of the period. Can be one of
      PRE_PERIOD_STATE, IN_PERIOD_STATE or POST_PERIOD_STATE.
    """
    # unbounded period
    if not self.start and not self.end:
      return IN_PERIOD_STATE

    # period right-unbounded
    elif self.start and not self.end:
      if time.isBefore(self.start):
        return PRE_PERIOD_STATE
      else:
        return IN_PERIOD_STATE

    # period left-unbounded
    elif not self.start and self.end:
      if time.isAfter(self.end):
        return POST_PERIOD_STATE
      else:
        return IN_PERIOD_STATE

    # period bounded
    elif time.isBefore(self.start):
      return PRE_PERIOD_STATE
    elif time.isAfter(self.end):
      return POST_PERIOD_STATE
    else:
      return IN_PERIOD_STATE
Example #7
0
  def canCreateTaskWithRequiredRole(self, required_role):
    """Checks whether the currently logged in user can create or edit
    a task, when the specified role is required.
    """
    if required_role == 'mentor':
      valid_org_keys = [o.key() for o in self.data.mentor_for]
    elif required_role == 'org_admin':
      valid_org_keys = [o.key() for o in self.data.org_admin_for]
    else:
      raise ValueError('Invalid required_role argument ' + str(required_role))

    if self.data.organization.key() not in valid_org_keys:
      raise exception.Forbidden(message=DEF_NO_TASK_CREATE_PRIV % (
          self.data.organization.name))

    if (time.isBefore(self.data.timeline.orgsAnnouncedOn()) \
        or self.data.timeline.tasksClaimEnded()):
      raise exception.Forbidden(message=access_checker.DEF_PAGE_INACTIVE)
Example #8
0
 def timelineAllowsTaskEditing(self):
   """Returns True/False depending on whether orgs can edit task depending
   on where in the program timeline we are currently in.
   """
   return not (time.isBefore(self.data.timeline.orgsAnnouncedOn()) or
               self.data.timeline.tasksClaimEnded())
Example #9
0
 def beforeStudentsAnnounced(self):
   return time.isBefore(self.studentsAnnouncedOn())
Example #10
0
 def surveyPeriod(self, survey):
   start = survey.survey_start
   end = survey.survey_end
   return time.isAfter(start) and time.isBefore(end)
Example #11
0
 def beforeStudentSignupStart(self):
   return time.isBefore(self.studentSignupStart())
Example #12
0
 def beforeOrgSignupStart(self):
   return not self.org_app or time.isBefore(self.orgSignupStart())
Example #13
0
 def beforeStudentsAnnounced(self):
     return time.isBefore(self.studentsAnnouncedOn())
Example #14
0
 def testForNone(self):
   """Tests that False is returned for None."""
   self.assertFalse(time.isBefore(None))
Example #15
0
 def testIsNotBefore(self):
   """Tests that False is returned if it is after the examined date."""
   self.assertFalse(time.isBefore(timeline_utils.past()))
Example #16
0
 def testIsBefore(self):
   """Tests that True is returned if it is before the examined date."""
   self.assertTrue(time.isBefore(timeline_utils.future()))