Beispiel #1
0
def _GetSecretKey(request):
    """Gets the XSRF secret key from the request context.

  This function sets the key if it is not present.

  Args:
    request: A django.http.HttpRequest.

  Returns:
    The XSRF secret key for the request.
  """
    if not hasattr(request, 'site'):
        request.site = site.singleton()
    return site.xsrfSecretKey(request.site)
Beispiel #2
0
def _GetSecretKey(request):
  """Gets the XSRF secret key from the request context.

  This function sets the key if it is not present.

  Args:
    request: A django.http.HttpRequest.

  Returns:
    The XSRF secret key for the request.
  """
  if not hasattr(request, 'site'):
    request.site = site.singleton()
  return site.xsrfSecretKey(request.site)
Beispiel #3
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  
  """
  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
  }
Beispiel #4
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,
    }
Beispiel #5
0
 def _getSecretKey(self, request):
   """Gets the XSRF secret key from the request context."""
   if not hasattr(request, 'site'):
     request.site = site.singleton()
   return site.xsrfSecretKey(request.site)