Пример #1
0
    def _getTimeDependentEntries(self, ghop_program_entity, params, id, user):
        """Returns a list with time dependent menu items.
    """

        from soc.modules.ghop.logic.models.org_app_survey import logic as \
            org_app_logic

        items = []

        timeline_entity = ghop_program_entity.timeline

        org_app_survey = org_app_logic.getForProgram(ghop_program_entity)

        if org_app_survey and \
            timeline_helper.isActivePeriod(timeline_entity, 'org_signup'):
            # add the organization signup link
            items += [
                (redirects.getTakeSurveyRedirect(org_app_survey,
                                                 {'url_name': 'ghop/org_app'}),
                 "Apply to become an Organization", 'any_access')
            ]

        if user and org_app_survey and timeline_helper.isAfterEvent(
                timeline_entity, 'org_signup_start'):

            main_admin_fields = {
                'main_admin': user,
                'survey': org_app_survey,
            }

            backup_admin_fields = {
                'backup_admin': user,
                'survey': org_app_survey
            }

            org_app_record_logic = org_app_logic.getRecordLogic()

            if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
                org_app_record_logic.getForFields(backup_admin_fields, unique=True):
                # add the 'List my Organization Applications' link
                items += [(redirects.getListSelfRedirect(
                    org_app_survey, {'url_name': 'ghop/org_app'}),
                           "List My Organization Applications", 'any_access')]

        # get the student entity for this user and program
        filter = {
            'user': user,
            'scope': ghop_program_entity,
            'status': ['active', 'inactive']
        }
        student_entity = ghop_student_logic.logic.getForFields(filter,
                                                               unique=True)

        if student_entity:
            items += self._getStudentEntries(ghop_program_entity,
                                             student_entity, params, id, user,
                                             'ghop')
        else:
            # if a user has a task assigned, he or she still may list it
            filter = {
                'user': user,
                'program': ghop_program_entity,
            }
            if user and ghop_task_logic.logic.getForFields(filter,
                                                           unique=True):
                items += [(ghop_redirects.getListStudentTasksRedirect(
                    ghop_program_entity, {'url_name': 'ghop/student'}),
                           "List my Tasks", 'any_access')]

            filter['status'] = 'AwaitingRegistration'
            if ghop_task_logic.logic.getForFields(filter, unique=True):
                if timeline_helper.isActivePeriod(timeline_entity,
                                                  'student_signup'):
                    # this user does not have a role yet for this program
                    items += [('/ghop/student/apply/%s' %
                               (ghop_program_entity.key().id_or_name()),
                               "Register as a Student", 'any_access')]

            # get mentor and org_admin entity for this user and program
            filter = {
                'user': user,
                'program': ghop_program_entity,
                'status': 'active'
            }
            mentor_entity = ghop_mentor_logic.logic.getForFields(filter,
                                                                 unique=True)
            org_admin_entity = ghop_org_admin_logic.logic.getForFields(
                filter, unique=True)

            if mentor_entity or org_admin_entity:
                items += self._getOrganizationEntries(ghop_program_entity,
                                                      org_admin_entity,
                                                      mentor_entity, params,
                                                      id, user)

        if timeline_helper.isAfterEvent(timeline_entity, 'org_signup_start'):
            url = redirects.getAcceptedOrgsRedirect(ghop_program_entity,
                                                    params)
            # add a link to list all the organizations
            items += [(url, "List participating Organizations", 'any_access')]

        return items
Пример #2
0
def sendSurveyReminderForProject(request, *args, **kwargs):
  """Sends a reminder mail for a given StudentProject and Survey.

  A reminder is only send if no record is on file for the given Survey and 
  StudentProject.

  Expects the following to be present in the POST dict:
    survey_key: specifies the key name for the ProjectSurvey to send reminders
                for
    survey_type: either project or grading depending on the type of Survey
    project_key: key which specifies the project to send a reminder for

  Args:
    request: Django Request object
  """

  from soc.logic import mail_dispatcher
  from soc.logic.models.org_admin import logic as org_admin_logic
  from soc.logic.models.site import logic as site_logic
  from soc.logic.models.student_project import logic as student_project_logic
  from soc.logic.models.survey import grading_logic
  from soc.logic.models.survey import project_logic
  from soc.views.helper import redirects

  post_dict = request.POST

  project_key = post_dict.get('project_key')
  survey_key = post_dict.get('survey_key')
  survey_type = post_dict.get('survey_type')

  if not (project_key and survey_key and survey_type):
    # invalid task data, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid sendSurveyReminderForProject data: %s' % post_dict)

  # set logic depending on survey type specified in POST
  if survey_type == 'project':
    survey_logic = project_logic
  elif survey_type == 'grading':
    survey_logic = grading_logic

  # retrieve the project and survey
  student_project = student_project_logic.getFromKeyName(project_key)

  if not student_project:
    # no existing project found, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid project specified %s:' % project_key)

  survey = survey_logic.getFromKeyName(survey_key)

  if not survey:
    # no existing survey found, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid survey specified %s:' % survey_key)

  # try to retrieve an existing record
  record_logic = survey_logic.getRecordLogic()

  fields = {'project': student_project,
            'survey': survey}
  record_entity = record_logic.getForFields(fields, unique=True)

  if not record_entity:
    # send reminder email because we found no record

    student_entity = student_project.student
    site_entity = site_logic.getSingleton()

    if survey_type == 'project':
      survey_redirect = redirects.getTakeSurveyRedirect(
          survey,{'url_name': 'project_survey'})
      to_role = student_entity
      mail_template = 'soc/project_survey/mail/reminder_gsoc.html'
    elif survey_type == 'grading':
      survey_redirect = redirects.getTakeSurveyRedirect(
          survey,{'url_name': 'grading_project_survey'})
      to_role = student_project.mentor
      mail_template = 'soc/grading_project_survey/mail/reminder_gsoc.html'

    survey_url = "http://%(host)s%(redirect)s" % {
      'redirect': survey_redirect,
      'host': os.environ['HTTP_HOST'],
      }

    # set the context for the mail template
    mail_context = {
        'student_name': student_entity.name(),
        'project_title': student_project.title,
        'survey_url': survey_url,
        'survey_end': survey.survey_end,
        'to_name': to_role.name(),
        'site_name': site_entity.site_name,
    }

    # set the sender
    (sender, sender_address) = mail_dispatcher.getDefaultMailSender()
    mail_context['sender'] = sender_address
    # set the receiver and subject
    mail_context['to'] = to_role.email
    mail_context['subject'] = 'Evaluation Survey "%s" Reminder' %(survey.title)

    # find all org admins for the project's organization
    org_entity = student_project.scope

    fields = {'scope': org_entity,
              'status': 'active'}
    org_admin_entities = org_admin_logic.getForFields(fields)

    # collect email addresses for all found org admins
    org_admin_addresses = []

    for org_admin_entity in org_admin_entities:
      org_admin_addresses.append(org_admin_entity.email)

    if org_admin_addresses:
      mail_context['cc'] = org_admin_addresses

    # send out the email
    mail_dispatcher.sendMailFromTemplate(mail_template, mail_context)

  # return OK
  return http.HttpResponse()
Пример #3
0
    def _getTimeDependentEntries(self, gci_program_entity, params, id, user):
        """Returns a list with time dependent menu items.
    """

        items = []

        timeline_entity = gci_program_entity.timeline

        # add show ranking item
        if timeline_helper.isAfterEvent(timeline_entity,
                                        'tasks_publicly_visible'):
            items += [(gci_redirects.getShowRankingRedirect(
                gci_program_entity,
                {'url_name': 'gci/program'}), 'Show Ranking', 'any_access')]

        mentor_entity = None
        org_admin_entity = None

        org_app_survey = org_app_logic.getForProgram(gci_program_entity)

        if org_app_survey and \
            timeline_helper.isActivePeriod(org_app_survey, 'survey'):
            # add the organization signup link
            items += [
                (redirects.getTakeSurveyRedirect(org_app_survey,
                                                 {'url_name': 'gci/org_app'}),
                 "Apply to become an Organization", 'any_access')
            ]

        if user and org_app_survey and timeline_helper.isAfterEvent(
                org_app_survey, 'survey_start'):

            main_admin_fields = {
                'main_admin': user,
                'survey': org_app_survey,
            }

            backup_admin_fields = {
                'backup_admin': user,
                'survey': org_app_survey
            }

            org_app_record_logic = org_app_logic.getRecordLogic()

            if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
                org_app_record_logic.getForFields(backup_admin_fields, unique=True):
                # add the 'List my Organization Applications' link
                items += [(redirects.getListSelfRedirect(
                    org_app_survey, {'url_name': 'gci/org_app'}),
                           "List My Organization Applications", 'any_access')]

        # get the student entity for this user and program
        filter = {
            'user': user,
            'scope': gci_program_entity,
            'status': ['active', 'inactive']
        }
        student_entity = gci_student_logic.logic.getForFields(filter,
                                                              unique=True)

        # students can register after successfully completing their first
        # task. So if a user has completed one task he is still a student
        filter = {
            'user': user,
            'program': gci_program_entity,
        }
        has_completed_task = gci_task_logic.logic.getForFields(filter,
                                                               unique=True)

        if student_entity or (user and has_completed_task):
            items += self._getStudentEntries(gci_program_entity,
                                             student_entity, params, id, user,
                                             'gci')
        else:
            # get mentor and org_admin entity for this user and program
            filter = {
                'user': user,
                'program': gci_program_entity,
                'status': 'active'
            }
            mentor_entity = gci_mentor_logic.logic.getForFields(filter,
                                                                unique=True)
            org_admin_entity = gci_org_admin_logic.logic.getForFields(
                filter, unique=True)

            if timeline_helper.isAfterEvent(
                    timeline_entity,
                    'accepted_organization_announced_deadline'):
                if mentor_entity or org_admin_entity:
                    items += self._getOrganizationEntries(
                        gci_program_entity, org_admin_entity, mentor_entity,
                        params, id, user)
                if timeline_helper.isBeforeEvent(timeline_entity,
                                                 'program_end'):
                    # add apply to become a mentor link
                    items += [('/gci/org/apply_mentor/%s' %
                               (gci_program_entity.key().id_or_name()),
                               "Apply to become a Mentor", 'any_access')]

        if timeline_helper.isAfterEvent(
                timeline_entity, 'accepted_organization_announced_deadline'):
            url = redirects.getAcceptedOrgsRedirect(gci_program_entity, params)
            # add a link to list all the organizations
            items += [(url, "List participating Organizations", 'any_access')]

        user_fields = {'user': user, 'status': 'active'}
        host_entity = host_logic.getForFields(user_fields, unique=True)

        # for org admins this link should be visible only after accepted
        # organizations are announced and for other public after the tasks
        # are public but for program host it must be visible always
        if (host_entity or ((org_admin_entity or mentor_entity)
                            and timeline_helper.isAfterEvent(
                                timeline_entity, 'tasks_publicly_visible'))
                or (timeline_helper.isAfterEvent(timeline_entity,
                                                 'tasks_publicly_visible'))):
            url = gci_redirects.getListAllTasksRedirect(
                gci_program_entity, params)
            # add a link to list all the organizations
            items += [(url, "List all tasks", 'any_access')]

            if user:
                # add a link to show all tasks of interest
                items += [(gci_redirects.getListMyTasksRedirect(
                    gci_program_entity,
                    params), 'List my Tasks', 'any_access')]

        return items
Пример #4
0
    def getMenusForScope(self, entity, params, id, user):
        """List featured surveys if after the survey_start date
    and before survey_end an iff the current user has the right taking access.

    Args:
      entity: entity which is the scope for a Survey
      params: params from the requesting View
      id: GAE user instance for the current user
      user: User entity from the current user
    """

        # only list surveys for registered users
        if not user:
            return []

        survey_params = self.getParams().copy()
        survey_logic = survey_params['logic']
        record_logic = survey_logic.getRecordLogic()

        # filter all featured surveys for the given entity
        filter = {
            'prefix': params['document_prefix'],
            'scope_path': entity.key().id_or_name(),
            'is_featured': True,
        }

        survey_entities = survey_logic.getForFields(filter)
        submenus = []

        # get the rights checker
        rights = self._params['rights']
        rights.setCurrentUser(id, user)

        # cache ACL
        survey_rights = {}

        # add a link to all featured active surveys the user can take
        for survey_entity in survey_entities:

            if survey_entity.taking_access not in survey_rights:
                # we have not determined if this user has the given type of access

                # check if the current user is allowed to visit the take Survey page
                allowed_to_take = False

                try:
                    rights.checkIsSurveyTakeable(
                        {
                            'key_name': survey_entity.key().name(),
                            'prefix': survey_entity.prefix,
                            'scope_path': survey_entity.scope_path,
                            'link_id': survey_entity.link_id,
                            'user': user
                        },
                        survey_logic,
                        check_time=False)
                    allowed_to_take = True
                except:
                    pass

                # cache ACL for a given entity.taking_access
                survey_rights[survey_entity.taking_access] = allowed_to_take

                if not allowed_to_take:
                    # not allowed to take this survey
                    continue

            elif not survey_rights[survey_entity.taking_access]:
                # we already determined that the user doens't have access to this type
                continue

            if not timeline.isActivePeriod(survey_entity, 'survey'):
                # this survey is not active right now
                continue

            # check if any SurveyRecord is available for this survey
            filter = {'survey': survey_entity, 'user': user}

            survey_record = record_logic.getForFields(filter, unique=True)

            if survey_record:
                taken_status = ""
            else:
                # no SurveyRecord available so we mark the survey as new
                taken_status = "(new)"

            submenu = (redirects.getTakeSurveyRedirect(survey_entity,
                                                       survey_params),
                       'Survey ' + taken_status + ': ' +
                       survey_entity.short_name, 'show')

            submenus.append(submenu)
        return submenus
Пример #5
0
  def getMenusForScope(self, entity, params, id, user):
    """List featured surveys if after the survey_start date 
    and before survey_end an iff the current user has the right taking access.

    Args:
      entity: entity which is the scope for a Survey
      params: params from the requesting View
      id: GAE user instance for the current user
      user: User entity from the current user
    """

    # only list surveys for registered users
    if not user:
      return []

    survey_params = self.getParams().copy()
    survey_logic = survey_params['logic']
    record_logic = survey_logic.getRecordLogic()

    # filter all featured surveys for the given entity
    filter = {
        'prefix' : params['url_name'],
        'scope_path': entity.key().id_or_name(),
        'is_featured': True,
        }

    survey_entities = survey_logic.getForFields(filter)
    submenus = []

    # get the rights checker
    rights = self._params['rights']
    rights.setCurrentUser(id, user)

    # cache ACL
    survey_rights = {}

    # add a link to all featured active surveys the user can take
    for survey_entity in survey_entities:

      if survey_entity.taking_access not in survey_rights:
        # we have not determined if this user has the given type of access

        # check if the current user is allowed to visit the take Survey page
        allowed_to_take = False

        try:
          rights.checkIsSurveyTakeable(
              {'key_name': survey_entity.key().name(),
               'prefix': survey_entity.prefix,
               'scope_path': survey_entity.scope_path,
               'link_id': survey_entity.link_id,
               'user': user},
              survey_logic,
              check_time=False)
          allowed_to_take = True
        except:
          pass

        # cache ACL for a given entity.taking_access
        survey_rights[survey_entity.taking_access] = allowed_to_take

        if not allowed_to_take:
          # not allowed to take this survey
          continue

      elif not survey_rights[survey_entity.taking_access]:
        # we already determined that the user doens't have access to this type
        continue

      if not timeline.isActivePeriod(survey_entity, 'survey'):
        # this survey is not active right now
        continue

      # check if any SurveyRecord is available for this survey
      filter = {'survey': survey_entity,
                'user': user}

      survey_record = record_logic.getForFields(filter, unique=True)

      if survey_record:
        taken_status = ""
      else:
        # no SurveyRecord available so we mark the survey as new
        taken_status = "(new)"

      submenu = (redirects.getTakeSurveyRedirect(survey_entity, survey_params),
                 'Survey ' + taken_status + ': ' + survey_entity.short_name,
                 'show')

      submenus.append(submenu)
    return submenus
Пример #6
0
  def _getTimeDependentEntries(self, gci_program_entity, params, id, user):
    """Returns a list with time dependent menu items.
    """

    items = []

    timeline_entity = gci_program_entity.timeline

    # add show ranking item
    if timeline_helper.isAfterEvent(timeline_entity, 'tasks_publicly_visible'):
      items += [(gci_redirects.getShowRankingRedirect(
           gci_program_entity, {'url_name': 'gci/program'}),
           'Show Ranking', 'any_access')]

    mentor_entity = None
    org_admin_entity = None

    org_app_survey = org_app_logic.getForProgram(gci_program_entity)

    if org_app_survey and \
        timeline_helper.isActivePeriod(org_app_survey, 'survey'):
      # add the organization signup link
      items += [
          (redirects.getTakeSurveyRedirect(
               org_app_survey, {'url_name': 'gci/org_app'}),
          "Apply to become an Organization", 'any_access')]

    if user and org_app_survey and timeline_helper.isAfterEvent(
        org_app_survey, 'survey_start'):

      main_admin_fields = {
          'main_admin': user,
          'survey': org_app_survey,
          }

      backup_admin_fields = {
          'backup_admin': user,
          'survey': org_app_survey
          }

      org_app_record_logic = org_app_logic.getRecordLogic()

      if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
          org_app_record_logic.getForFields(backup_admin_fields, unique=True):
        # add the 'List my Organization Applications' link
        items += [
            (redirects.getListSelfRedirect(org_app_survey,
                                           {'url_name' : 'gci/org_app'}),
             "List My Organization Applications", 'any_access')]

    # get the student entity for this user and program
    filter = {'user': user,
              'scope': gci_program_entity,
              'status': ['active', 'inactive']}
    student_entity = gci_student_logic.logic.getForFields(filter, unique=True)

    # students can register after successfully completing their first
    # task. So if a user has completed one task he is still a student
    filter = {
        'user': user,
        'program': gci_program_entity,
        }
    has_completed_task = gci_task_logic.logic.getForFields(
        filter, unique=True)

    if student_entity or (user and has_completed_task):
      items += self._getStudentEntries(gci_program_entity, student_entity,
                                       params, id, user, 'gci')
    else:
      # get mentor and org_admin entity for this user and program
      filter = {
          'user': user,
          'program': gci_program_entity,
          'status': 'active'
          }
      mentor_entity = gci_mentor_logic.logic.getForFields(filter, unique=True)
      org_admin_entity = gci_org_admin_logic.logic.getForFields(
          filter, unique=True)

      if timeline_helper.isAfterEvent(
          timeline_entity, 'accepted_organization_announced_deadline'):
        if mentor_entity or org_admin_entity:
          items += self._getOrganizationEntries(
              gci_program_entity, org_admin_entity,
              mentor_entity, params, id, user)
        if timeline_helper.isBeforeEvent(timeline_entity, 'program_end'):
          # add apply to become a mentor link
          items += [
              ('/gci/org/apply_mentor/%s' % (
                  gci_program_entity.key().id_or_name()),
                  "Apply to become a Mentor", 'any_access')]

    if timeline_helper.isAfterEvent(
        timeline_entity, 'accepted_organization_announced_deadline'):
      url = redirects.getAcceptedOrgsRedirect(
          gci_program_entity, params)
      # add a link to list all the organizations
      items += [(url, "List participating Organizations", 'any_access')]

    user_fields = {
        'user': user,
        'status': 'active'
        }
    host_entity = host_logic.getForFields(user_fields, unique=True)

    # for org admins this link should be visible only after accepted
    # organizations are announced and for other public after the tasks
    # are public but for program host it must be visible always
    if (host_entity or
        ((org_admin_entity or mentor_entity) and timeline_helper.isAfterEvent(
        timeline_entity, 'tasks_publicly_visible')) or
        (timeline_helper.isAfterEvent(
        timeline_entity, 'tasks_publicly_visible'))):
      url = gci_redirects.getListAllTasksRedirect(
          gci_program_entity, params)
      # add a link to list all the organizations
      items += [(url, "List all tasks", 'any_access')]

      if user:
        # add a link to show all tasks of interest
        items += [(gci_redirects.getListMyTasksRedirect(
            gci_program_entity, params),
            'List my Tasks', 'any_access')]

    return items
Пример #7
0
def sendSurveyReminderForProject(request, *args, **kwargs):
    """Sends a reminder mail for a given StudentProject and Survey.

  A reminder is only send if no record is on file for the given Survey and 
  StudentProject.

  Expects the following to be present in the POST dict:
    survey_key: specifies the key name for the ProjectSurvey to send reminders
                for
    survey_type: either project or grading depending on the type of Survey
    project_key: key which specifies the project to send a reminder for

  Args:
    request: Django Request object
  """

    from soc.logic import mail_dispatcher
    from soc.logic.models.site import logic as site_logic
    from soc.views.helper import redirects

    from soc.modules.gsoc.logic.models.org_admin import logic as org_admin_logic
    from soc.modules.gsoc.logic.models.student_project import logic as \
        student_project_logic
    from soc.modules.gsoc.logic.models.survey import grading_logic
    from soc.modules.gsoc.logic.models.survey import project_logic

    post_dict = request.POST

    project_key = post_dict.get('project_key')
    survey_key = post_dict.get('survey_key')
    survey_type = post_dict.get('survey_type')

    if not (project_key and survey_key and survey_type):
        # invalid task data, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid sendSurveyReminderForProject data: %s' % post_dict)

    # set logic depending on survey type specified in POST
    if survey_type == 'project':
        survey_logic = project_logic
    elif survey_type == 'grading':
        survey_logic = grading_logic

    # retrieve the project and survey
    student_project = student_project_logic.getFromKeyName(project_key)

    if not student_project:
        # no existing project found, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid project specified %s:' % project_key)

    survey = survey_logic.getFromKeyName(survey_key)

    if not survey:
        # no existing survey found, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid survey specified %s:' % survey_key)

    # try to retrieve an existing record
    record_logic = survey_logic.getRecordLogic()

    fields = {'project': student_project, 'survey': survey}
    record_entity = record_logic.getForFields(fields, unique=True)

    if not record_entity:
        # send reminder email because we found no record

        student_entity = student_project.student
        site_entity = site_logic.getSingleton()

        if survey_type == 'project':
            survey_redirect = redirects.getTakeSurveyRedirect(
                survey, {'url_name': 'gsoc/project_survey'})
            to_role = student_entity
            mail_template = 'soc/project_survey/mail/reminder_gsoc.html'
        elif survey_type == 'grading':
            survey_redirect = redirects.getTakeSurveyRedirect(
                survey, {'url_name': 'gsoc/grading_project_survey'})
            to_role = student_project.mentor
            mail_template = 'soc/grading_project_survey/mail/reminder_gsoc.html'

        survey_url = "http://%(host)s%(redirect)s" % {
            'redirect': survey_redirect,
            'host': system.getHostname(),
        }

        # set the context for the mail template
        mail_context = {
            'student_name': student_entity.name(),
            'project_title': student_project.title,
            'survey_url': survey_url,
            'survey_end': survey.survey_end,
            'to_name': to_role.name(),
            'site_name': site_entity.site_name,
        }

        # set the sender
        (_, sender_address) = mail_dispatcher.getDefaultMailSender()
        mail_context['sender'] = sender_address
        # set the receiver and subject
        mail_context['to'] = to_role.email
        mail_context['subject'] = 'Evaluation Survey "%s" Reminder' % (
            survey.title)

        # find all org admins for the project's organization
        org_entity = student_project.scope

        fields = {'scope': org_entity, 'status': 'active'}
        org_admin_entities = org_admin_logic.getForFields(fields)

        # collect email addresses for all found org admins
        org_admin_addresses = []

        for org_admin_entity in org_admin_entities:
            org_admin_addresses.append(org_admin_entity.email)

        if org_admin_addresses:
            mail_context['cc'] = org_admin_addresses

        # send out the email
        mail_dispatcher.sendMailFromTemplate(mail_template, mail_context)

    # return OK
    return http.HttpResponse()
Пример #8
0
    def _getTimeDependentEntries(self, program_entity, params, id, user):
        """Returns a list with time dependent menu items.
    """

        from soc.modules.gsoc.logic.models.org_app_survey import logic as \
            org_app_logic

        items = []

        timeline_entity = program_entity.timeline

        org_app_survey = org_app_logic.getForProgram(program_entity)

        if org_app_survey and \
            timeline_helper.isActivePeriod(timeline_entity, 'org_signup'):
            # add the organization signup link
            items += [
                (redirects.getTakeSurveyRedirect(org_app_survey,
                                                 {'url_name': 'gsoc/org_app'}),
                 "Apply to become an Organization", 'any_access')
            ]

        if user and org_app_survey and timeline_helper.isAfterEvent(
                timeline_entity, 'org_signup_start'):

            main_admin_fields = {
                'main_admin': user,
                'survey': org_app_survey,
            }

            backup_admin_fields = {
                'backup_admin': user,
                'survey': org_app_survey
            }

            org_app_record_logic = org_app_logic.getRecordLogic()

            if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
                org_app_record_logic.getForFields(backup_admin_fields, unique=True):
                # add the 'List my Organization Applications' link
                items += [(redirects.getListSelfRedirect(
                    org_app_survey, {'url_name': 'gsoc/org_app'}),
                           "List My Organization Applications", 'any_access')]

        # get the student entity for this user and program
        filter = {
            'user': user,
            'scope': program_entity,
            'status': ['active', 'inactive']
        }
        student_entity = student_logic.getForFields(filter, unique=True)

        if student_entity:
            items += self._getStudentEntries(program_entity, student_entity,
                                             params, id, user, 'gsoc')

        # get mentor and org_admin entity for this user and program
        filter = {
            'user': user,
            'program': program_entity,
            'status': ['active', 'inactive']
        }
        mentor_entity = mentor_logic.getForFields(filter, unique=True)
        org_admin_entity = org_admin_logic.getForFields(filter, unique=True)

        if mentor_entity or org_admin_entity:
            items += self._getOrganizationEntries(program_entity,
                                                  org_admin_entity,
                                                  mentor_entity, params, id,
                                                  user)

        if user and not (student_entity or mentor_entity or org_admin_entity):
            if timeline_helper.isActivePeriod(timeline_entity,
                                              'student_signup'):
                # this user does not have a role yet for this program
                items += [('/gsoc/student/apply/%s' %
                           (program_entity.key().id_or_name()),
                           "Register as a Student", 'any_access')]

        deadline = 'accepted_organization_announced_deadline'

        if timeline_helper.isAfterEvent(timeline_entity, deadline):
            url = redirects.getAcceptedOrgsRedirect(program_entity, params)
            # add a link to list all the organizations
            items += [(url, "List participating Organizations", 'any_access')]

            if not student_entity and \
                timeline_helper.isBeforeEvent(timeline_entity, 'program_end'):
                # add apply to become a mentor link
                items += [('/gsoc/org/apply_mentor/%s' %
                           (program_entity.key().id_or_name()),
                           "Apply to become a Mentor", 'any_access')]

        deadline = 'accepted_students_announced_deadline'

        if timeline_helper.isAfterEvent(timeline_entity, deadline):
            items += [(redirects.getListProjectsRedirect(
                program_entity, {'url_name': 'gsoc/program'}),
                       "List all Student Projects", 'any_access')]

        return items
Пример #9
0
  def _getTimeDependentEntries(self, program_entity, params, id, user):
    """Returns a list with time dependent menu items.
    """

    items = []

    timeline_entity = program_entity.timeline

    org_app_survey = org_app_logic.getForProgram(program_entity)

    if org_app_survey and \
        timeline_helper.isActivePeriod(org_app_survey, 'survey'):
      # add the organization signup link
      items += [
          (redirects.getTakeSurveyRedirect(
               org_app_survey, {'url_name': 'gsoc/org_app'}),
          "Apply to become an Organization", 'any_access')]

    if user and org_app_survey and timeline_helper.isAfterEvent(
        org_app_survey, 'survey_start'):

      main_admin_fields = {
          'main_admin': user,
          'survey': org_app_survey,
          }

      backup_admin_fields = {
          'backup_admin': user,
          'survey': org_app_survey
          }

      org_app_record_logic = org_app_logic.getRecordLogic()

      if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
          org_app_record_logic.getForFields(backup_admin_fields, unique=True):
        # add the 'List my Organization Applications' link
        items += [
            (redirects.getListSelfRedirect(org_app_survey,
                                           {'url_name' : 'gsoc/org_app'}),
             "List My Organization Applications", 'any_access')]

    # get the student entity for this user and program
    filter = {
        'user': user,
        'scope': program_entity,
        'status': ['active', 'inactive']
        }
    student_entity = student_logic.getForFields(filter, unique=True)

    if student_entity:
      items += self._getStudentEntries(program_entity, student_entity,
                                       params, id, user, 'gsoc')

    # get mentor and org_admin entity for this user and program
    filter = {
        'user': user,
        'program': program_entity,
        'status': ['active', 'inactive']
        }
    mentor_entity = mentor_logic.getForFields(filter, unique=True)
    org_admin_entity = org_admin_logic.getForFields(filter, unique=True)

    if mentor_entity or org_admin_entity:
      items += self._getOrganizationEntries(program_entity, org_admin_entity,
                                            mentor_entity, params, id, user)

    if not (student_entity or mentor_entity or org_admin_entity):
      if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'):
        # this user does not have a role yet for this program
        items += [
            ('/gsoc/student/apply/%s' % (program_entity.key().id_or_name()),
            "Register as a Student", 'any_access')]

    deadline = 'accepted_organization_announced_deadline'

    if timeline_helper.isAfterEvent(timeline_entity, deadline):
      url = redirects.getAcceptedOrgsRedirect(program_entity, params)
      # add a link to list all the organizations
      items += [(url, "List participating Organizations", 'any_access')]

      if not student_entity and \
          timeline_helper.isBeforeEvent(timeline_entity, 'program_end'):
        # add apply to become a mentor link
        items += [
            ('/gsoc/org/apply_mentor/%s' % (program_entity.key().id_or_name()),
           "Apply to become a Mentor", 'any_access')]

    deadline = 'accepted_students_announced_deadline'

    if timeline_helper.isAfterEvent(timeline_entity, deadline):
      items += [(redirects.getListProjectsRedirect(program_entity,
          {'url_name':'gsoc/program'}),
          "List all Student Projects", 'any_access')]

    return items