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

    context = {
        'img_url': img_url,
        'events_link': self.data.redirect.events().url(),
        }

    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

    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
파일: responses.py 프로젝트: ajaksu/Melange
def getUniversalContext(request):
  """Constructs a template context dict will many common variables defined.
  
  Args:
    request: the Django HTTP request object

  Returns:
    a new context dict containing:
    
    {
      'request': the Django HTTP request object passed in by the caller
      'account': the logged-in Google Account if there is one
      'user': the User entity corresponding to the Google Account in
        context['account']
      'is_admin': True if users.is_current_user_admin() is True
      'is_debug': True if system.isDebug() is True
      'sign_in': a Google Account login URL
      'sign_out': a Google Account logout URL
      'sidebar_menu_html': an HTML string that renders the sidebar menu
    }
  """

  account = accounts.getCurrentAccount()
  user = None
  is_admin = False

  context = {}
  context['request'] = request

  if account:
    user = user_logic.getForAccount(account)
    is_admin = user_logic.isDeveloper(account=account, user=user)

  context['account'] = account
  context['user'] = user
  context['is_admin'] = is_admin

  context['is_local'] = system.isLocal()
  context['is_debug'] = system.isDebug()
  context['sign_in'] = users.create_login_url(request.path)
  context['sign_out'] = users.create_logout_url(request.path)

  context['sidebar_menu_items'] = callback.getCore().getSidebar(account, user)

  context['gae_version'] = system.getAppVersion()
  context['soc_release'] = system.getMelangeVersion()

  settings = site.logic.getSingleton()

  context['ga_tracking_num'] = settings.ga_tracking_num
  context['gmaps_api_key'] = settings.gmaps_api_key
  context['site_name'] = settings.site_name
  context['site_notice'] = settings.site_notice
  context['tos_link'] = redirects.getToSRedirect(settings)
  context['in_maintenance'] = timeline.isActivePeriod(site, 'maintenance')
 
  return context
예제 #4
0
파일: context.py 프로젝트: adviti/melange
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  
  """
  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 system.isSecondaryHostname(data):
    google_api_key = data.site.secondary_google_api_key
  else:
    google_api_key = data.site.google_api_key

  if data.user and oauth_helper.getAccessToken(data.user):
    gdata_is_logged_in = 'true'
  else:
    gdata_is_logged_in = 'false'

  css_path = '/'.join([
      'soc', 'content', system.getMelangeVersion(), 'css', 'v2',
      data.css_path])

  return {
      'app_version': system.getMelangeVersion(),
      '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,
      'gdata_is_logged_in': gdata_is_logged_in,
      'css_path': css_path
  }
예제 #5
0
파일: proposal.py 프로젝트: adviti/melange
  def jsonContext(self):
    assert self.request.GET['field'] == 'google_document'

    term = self.request.GET['term'].encode('utf-8')
    service = oauth_helper.createDocsServiceWithAccessToken(self.data)
    feed = gdocs_helper.findDocuments(service, title=term,
                                      categories=['document'])
    data = []
    for entry in feed.entry:
      img_url = ("/soc/content/%s/images/gdocs-%s-icon.png"
                 % (system.getMelangeVersion(), entry.GetDocumentType()))
      data.append({
          'id': entry.resourceId.text,
          'value': entry.title.text.decode('utf-8'),
          'label': "<img src='%s'/> %s"
                   % (img_url, entry.title.text.decode('utf-8'))
          })

    return data
예제 #6
0
def getUniversalContext(request):
    """Constructs a template context dict will many common variables defined.

  Args:
    request: the Django HTTP request object

  Returns:
    a new context dict containing:

    {
      'request': the Django HTTP request object passed in by the caller
      'account': the logged-in Google Account if there is one
      'user': the User entity corresponding to the Google Account in
        context['account']
      'is_admin': True if users.is_current_user_admin() is True
      'is_debug': True if system.isDebug() is True
      'sign_in': a Google Account login URL
      'sign_out': a Google Account logout URL
      'sidebar_menu_html': an HTML string that renders the sidebar menu
    }
  """

    core = callback.getCore()

    context = core.getRequestValue('context', {})

    if context:
        return context

    account = accounts.getCurrentAccount()
    user = None
    is_admin = False

    context['request'] = request

    if account:
        user = user_logic.getForAccount(account)
        is_admin = user_logic.isDeveloper(account=account, user=user)

    context['account'] = account
    context['user'] = user
    context['is_admin'] = is_admin

    context['is_local'] = system.isLocal()
    context['is_debug'] = system.isDebug()
    context['sign_in'] = users.create_login_url(request.path)
    context['sign_out'] = users.create_logout_url(request.path)

    context['sidebar_menu_items'] = core.getSidebar(account, user)

    context['gae_version'] = system.getAppVersion()
    context['soc_release'] = system.getMelangeVersion()

    settings = site.logic.getSingleton()

    context['ga_tracking_num'] = settings.ga_tracking_num
    context['gmaps_api_key'] = settings.gmaps_api_key
    context['site_name'] = settings.site_name
    context['site_notice'] = settings.site_notice
    context['tos_link'] = redirects.getToSRedirect(settings)
    context['in_maintenance'] = timeline.isActivePeriod(
        settings, 'maintenance')

    # Only one xsrf_token is generated per request.
    xsrf_secret_key = site.logic.getXsrfSecretKey(settings)
    context['xsrf_token'] = xsrfutil.getGeneratedTokenForCurrentUser(
        xsrf_secret_key)

    core.setRequestValue('context', context)

    return context