예제 #1
0
  def context(self):
    if self.current_timeline == 'kickoff_period':
      img_url = ("/soc/content/%s/images/gsoc/image-map-kickoff.png"
                 % system.getMelangeVersion())
    elif self.current_timeline in ['org_signup_period', 'orgs_announced_period']:
      img_url = ("/soc/content/%s/images/gsoc/image-map-org-apps.png"
                 % system.getMelangeVersion())
    elif self.current_timeline == 'student_signup_period':
      img_url = ("/soc/content/%s/images/gsoc/image-map-student-apps.png"
                 % system.getMelangeVersion())
    elif self.current_timeline == 'coding_period':
      img_url = ("/soc/content/%s/images/gsoc/image-map-on-season.png"
                 % system.getMelangeVersion())
    else:
      img_url = ("/soc/content/%s/images/gsoc/image-map-off-season.png"
                 % system.getMelangeVersion())

    context = {'img_url': img_url}

    events_page_key = (
        program_model.GSoCProgram.events_page.get_value_for_datastore(
            self.data.program))
    if events_page_key:
      context['events_link'] = links.LINKER.program(
          self.data.program, 'gsoc_events')

    if self.next_deadline_msg and self.next_deadline_datetime:
      context['next_deadline_msg'] = self.next_deadline_msg
      context['next_deadline_datetime'] = self.next_deadline_datetime

    context['new_widget'] = self.new_widget

    return context
예제 #2
0
  def testGetMelangeVersion(self):
    """Tests if the Melange part of GAE version is returned."""
    try:
      expected_version = os.environ['CURRENT_VERSION_ID'] = 'testing-version'
      self.assertEqual(system.getMelangeVersion(), expected_version)
    finally:
      if self.default_current_version_id is None:
        del os.environ['CURRENT_VERSION_ID']
      else:
        os.environ['CURRENT_VERSION_ID'] = self.default_current_version_id

    try:
      os.environ['CURRENT_VERSION_ID'] = 'melange_version.testing'
      expected_version = 'melange_version'
      self.assertEqual(system.getMelangeVersion(), expected_version)
    finally:
      if self.default_current_version_id is None:
        del os.environ['CURRENT_VERSION_ID']
      else:
        os.environ['CURRENT_VERSION_ID'] = self.default_current_version_id

    try:
      expected_version = os.environ['CURRENT_VERSION_ID'] = ''
      self.assertEqual(system.getMelangeVersion(), expected_version)
    finally:
      if self.default_current_version_id is None:
        del os.environ['CURRENT_VERSION_ID']
      else:
        os.environ['CURRENT_VERSION_ID'] = self.default_current_version_id
예제 #3
0
    def testGetMelangeVersion(self):
        """Tests if the Melange part of GAE version is returned."""
        try:
            expected_version = os.environ[
                'CURRENT_VERSION_ID'] = 'testing-version'
            self.assertEqual(system.getMelangeVersion(), expected_version)
        finally:
            if self.default_current_version_id is None:
                del os.environ['CURRENT_VERSION_ID']
            else:
                os.environ[
                    'CURRENT_VERSION_ID'] = self.default_current_version_id

        try:
            os.environ['CURRENT_VERSION_ID'] = 'melange_version.testing'
            expected_version = 'melange_version'
            self.assertEqual(system.getMelangeVersion(), expected_version)
        finally:
            if self.default_current_version_id is None:
                del os.environ['CURRENT_VERSION_ID']
            else:
                os.environ[
                    'CURRENT_VERSION_ID'] = self.default_current_version_id

        try:
            expected_version = os.environ['CURRENT_VERSION_ID'] = ''
            self.assertEqual(system.getMelangeVersion(), expected_version)
        finally:
            if self.default_current_version_id is None:
                del os.environ['CURRENT_VERSION_ID']
            else:
                os.environ[
                    'CURRENT_VERSION_ID'] = self.default_current_version_id
예제 #4
0
    def context(self):
        if self.current_timeline == 'kickoff_period':
            img_url = ("/soc/content/%s/images/gsoc/image-map-kickoff.png" %
                       system.getMelangeVersion())
        elif self.current_timeline in [
                'org_signup_period', 'orgs_announced_period'
        ]:
            img_url = ("/soc/content/%s/images/gsoc/image-map-org-apps.png" %
                       system.getMelangeVersion())
        elif self.current_timeline == 'student_signup_period':
            img_url = (
                "/soc/content/%s/images/gsoc/image-map-student-apps.png" %
                system.getMelangeVersion())
        elif self.current_timeline == 'coding_period':
            img_url = ("/soc/content/%s/images/gsoc/image-map-on-season.png" %
                       system.getMelangeVersion())
        else:
            img_url = ("/soc/content/%s/images/gsoc/image-map-off-season.png" %
                       system.getMelangeVersion())

        context = {'img_url': img_url}

        events_page_key = (
            program_model.GSoCProgram.events_page.get_value_for_datastore(
                self.data.program))
        if events_page_key:
            context['events_link'] = links.LINKER.program(
                self.data.program, 'gsoc_events')

        if self.next_deadline_msg and self.next_deadline_datetime:
            context['next_deadline_msg'] = self.next_deadline_msg
            context['next_deadline_datetime'] = self.next_deadline_datetime

        context['new_widget'] = self.new_widget

        return context
예제 #5
0
def default(data):
  """Returns a context dictionary with default values set.

  The following values are available:
      app_version: the current version string of the application
      is_local: whether we are running locally
      posted: if this was a post/redirect-after-post request
      xsrf_token: the xstrf_token for this request
      google_api_key: the google api key for this website
      ga_tracking_num: the google tracking number for this website
      ds_write_disabled: if datastore writes are disabled
      css_path: part of the path to the css files to distinguish modules
  """
  app_version = system.getMelangeVersion()

  posted = data.request.POST or 'validated' in data.request.GET

  xsrf_secret_key = site.xsrfSecretKey(data.site)
  xsrf_token = xsrfutil.getGeneratedTokenForCurrentUser(xsrf_secret_key)

  if site.isSecondaryHostname(data):
    google_api_key = data.site.secondary_google_api_key
  else:
    google_api_key = data.site.google_api_key

  css_path = '/'.join([
      'soc', 'content', app_version, 'css', data.css_path])

  return {
      'app_version': app_version,
      'is_local': system.isLocal(),
      'posted': posted,
      'xsrf_token': xsrf_token,
      'google_api_key': google_api_key,
      'ga_tracking_num': data.site.ga_tracking_num,
      'ds_write_disabled': data.ds_write_disabled,
      'css_path': css_path,
      'site_description': data.site.description,
  }
예제 #6
0
def default(data):
    """Returns a context dictionary with default values set.

  The following values are available:
      app_version: the current version string of the application
      is_local: whether we are running locally
      posted: if this was a post/redirect-after-post request
      xsrf_token: the xstrf_token for this request
      google_api_key: the google api key for this website
      ga_tracking_num: the google tracking number for this website
      ds_write_disabled: if datastore writes are disabled
      css_path: part of the path to the css files to distinguish modules
  """
    app_version = system.getMelangeVersion()

    posted = data.request.POST or 'validated' in data.request.GET

    xsrf_secret_key = site.xsrfSecretKey(data.site)
    xsrf_token = xsrfutil.getGeneratedTokenForCurrentUser(xsrf_secret_key)

    if site.isSecondaryHostname(data):
        google_api_key = data.site.secondary_google_api_key
    else:
        google_api_key = data.site.google_api_key

    css_path = '/'.join(['soc', 'content', app_version, 'css', data.css_path])

    return {
        'app_version': app_version,
        'is_local': system.isLocal(),
        'posted': posted,
        'xsrf_token': xsrf_token,
        'google_api_key': google_api_key,
        'ga_tracking_num': data.site.ga_tracking_num,
        'ds_write_disabled': data.ds_write_disabled,
        'css_path': css_path,
        'site_description': data.site.description,
    }
예제 #7
0
def _handle(status, style_file, message=None):
    """Returns an appropriate http.HttpResponse.

  Args:
    status: A numeric HTTP status code.
    style_file: One of _USER_ERROR_STYLE or _SERVER_ERROR_STYLE.
    message: An optional message for the user. If not provided, the
      standard text for the given HTTP status code will be used.

  Returns:
    An appropriate http.HttpResponse.
  """
    message = httplib.responses.get(status, "") if message is None else message
    context = {
        "app_version": system.getMelangeVersion(),
        "code": status,
        "message": message,
        "page_name": httplib.responses[status],
        "style_file": style_file,
    }
    content = loader.render_to_string(_TEMPLATE, dictionary=context)

    return http.HttpResponse(content=content, status=status)
예제 #8
0
def _handle(status, style_file, message=None):
    """Returns an appropriate http.HttpResponse.

  Args:
    status: A numeric HTTP status code.
    style_file: One of _USER_ERROR_STYLE or _SERVER_ERROR_STYLE.
    message: An optional message for the user. If not provided, the
      standard text for the given HTTP status code will be used.

  Returns:
    An appropriate http.HttpResponse.
  """
    message = httplib.responses.get(status, '') if message is None else message
    context = {
        'app_version': system.getMelangeVersion(),
        'code': status,
        'message': message,
        'page_name': httplib.responses[status],
        'style_file': style_file,
    }
    content = loader.render_to_string(_TEMPLATE, dictionary=context)

    return http.HttpResponse(content=content, status=status)