Esempio n. 1
0
def sendMail(context, parent=None, run=True, transactional=True):
    """Sends out an email using context to supply the needed information.

  Args:
    context: The context supplied to the email message (dictionary)
    parent: The parent entity to use for when this mail is to be sent in a
            transaction.
    run: If true the mail will be sent otherwise the function that can sent
         the mail will be returned.
    transactional: Whether the task should be created transactionally.

  Raises:
    Error that corresponds with the first problem it finds iff the message
    is not properly initialized.

    List of all possible errors:
      http://code.google.com/appengine/docs/mail/exceptions.html
  """
    # construct the EmailMessage from the given context
    message = mail.EmailMessage(**context)
    message.check_initialized()

    # don't send out emails in non-local debug mode
    if not system.isLocal() and system.isDebug():
        return

    txn = mailer.getSpawnMailTaskTxn(context=context,
                                     parent=parent,
                                     transactional=transactional)
    if run:
        return db.RunInTransaction(txn)
    else:
        return txn
Esempio n. 2
0
def sendMail(context, parent=None, run=True, transactional=True):
  """Sends out an email using context to supply the needed information.

  Args:
    context: The context supplied to the email message (dictionary)
    parent: The parent entity to use for when this mail is to be sent in a
            transaction.
    run: If true the mail will be sent otherwise the function that can sent
         the mail will be returned.
    transactional: Whether the task should be created transactionally.

  Raises:
    Error that corresponds with the first problem it finds iff the message
    is not properly initialized.

    List of all possible errors:
      http://code.google.com/appengine/docs/mail/exceptions.html
  """
  # construct the EmailMessage from the given context
  message = mail.EmailMessage(**context)
  message.check_initialized()

  # don't send out emails in non-local debug mode
  if not system.isLocal() and system.isDebug():
    return

  txn = mailer.getSpawnMailTaskTxn(
      context=context, parent=parent, transactional=transactional)
  if run:
    return db.RunInTransaction(txn)
  else:
    return txn
Esempio n. 3
0
  def _fullUrl(self, url, full, secure):
    """Returns the full version of the url iff full.

    The full version starts with http:// and includes getHostname().
    """
    if (not full) and (system.isLocal() or not secure):
      return url

    # TODO(nathaniel): consider using scheme-relative urls here?
    protocol = 'https' if secure else 'http'
    hostname = site_logic.getHostname(self._data)

    return '%s://%s%s' % (protocol, hostname, url)
Esempio n. 4
0
def getAbsoluteUrl(relative_url, hostname, secure=False):
  """Constructs absolute URL based on the specified relative URL.

  Args:
    relative_url: Relative path to a resource.
    hostname: Name of the host.
    secure: Whether the URL should support HTTPS or not.

  Returns:
    A full path to the resource.
  """
  # TODO(nathaniel): consider using scheme-relative urls here?
  protocol = 'https' if secure and not system.isLocal() else 'http'

  return '%s://%s%s' % (protocol, hostname, relative_url)
Esempio n. 5
0
def getAbsoluteUrl(relative_url, hostname, secure=False):
    """Constructs absolute URL based on the specified relative URL.

  Args:
    relative_url: Relative path to a resource.
    hostname: Name of the host.
    secure: Whether the URL should support HTTPS or not.

  Returns:
    A full path to the resource.
  """
    # TODO(nathaniel): consider using scheme-relative urls here?
    protocol = 'https' if secure and not system.isLocal() else 'http'

    return '%s://%s%s' % (protocol, hostname, relative_url)
Esempio n. 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,
  }
Esempio n. 7
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,
    }
Esempio n. 8
0
 def testIsLocal(self):
   """Tests if the current Melange application is running locally."""
   self.assertTrue(system.isLocal())
Esempio n. 9
0
 def testIsLocal(self):
     """Tests if the current Melange application is running locally."""
     self.assertTrue(system.isLocal())