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
def sendMail(context): """Sends out an email using context to supply the needed information. Args: context : The context supplied to the email message (dictionary) 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 try: # send the message message.send() except (mail.Error, OverQuotaError), exception: import logging logging.info(context) logging.exception(exception)
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
def testIsDebug(self): """Tests if Melange is running in debug mode. """ self.assertTrue(system.isDebug()) try: os.environ['CURRENT_VERSION_ID'] = 'devvin.testing-version' self.assertTrue(system.isDebug()) 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'] = 'nondevvin.testing-version' self.assertTrue(system.isDebug()) 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
def djangoURLPatterns(self): """Returns the URL pattern for the legacy views. """ patterns = [ ] from soc.tasks.updates import role_conversion patterns += role_conversion.getDjangoURLPatterns() if system.isDebug(): patterns += [ ('^seed_db$', 'soc.models.seed_db.seed'), ('^clear_db$', 'soc.models.seed_db.clear'), ('^reseed_db$', 'soc.models.seed_db.reseed'), ] return patterns
def djangoURLPatterns(self): """Returns the URL pattern for the legacy views. """ patterns = [ ] from soc.tasks.updates import role_conversion from soc.modules.gsoc.views.models import timeline patterns += role_conversion.getDjangoURLPatterns() patterns += timeline.view.getDjangoURLPatterns() if system.isDebug(): patterns += [ ('^seed_db$', 'soc.models.seed_db.seed'), ('^clear_db$', 'soc.models.seed_db.clear'), ('^reseed_db$', 'soc.models.seed_db.reseed'), ] return patterns
def sendMail(context): """Sends out an email using context to supply the needed information. Args: context : The context supplied to the email message (dictionary) 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 mailer.spawnMailTask(context)
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