Python pyramid.events.subscriber() Examples
The following are 1
code examples of pyramid.events.subscriber().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyramid.events
, or try the search function
.
Example #1
Source File: subscribers.py From nova-ideo with GNU Affero General Public License v3.0 | 4 votes |
def init_application(event): app = event.object registry = app.registry request = Request.blank('/application_created') # path is meaningless request.registry = registry manager.push({'registry': registry, 'request': request}) # Set up sms service backend registry.registerAdapter( factory=OvhService, required=(IRequest,), provided=ISMSService) root = app.root_factory(request) # A transaction.commit() just happened here if this is the first time we # start. This is just after all RootAdded subscribers are executed. request.root = root # other init functions if getattr(root, 'locale', None) is None: try: # This code is actually an evolve step for old novaideo instances. # The root.locale is set in the RootAdded subscriber above # for new instances. root.locale = registry.settings.get('pyramid.default_locale_name') transaction.commit() except ConflictError: # We have a conflict error in case of serveral workers, just abort transaction.abort() init_contents(registry) # there is no changes in ZODB here # invite initial user if first deployment if getattr(root, 'first_invitation_to_add', False): # LOGO_FILENAME='marianne.svg' for example logo = os.getenv('LOGO_FILENAME', '') if logo: logo_path = os.path.join( os.path.dirname(__file__), 'static', 'images', logo) if os.path.exists(logo_path): buf = open(logo_path, mode='rb') log_file = File( fp=buf, filename=logo, mimetype='image/svg+xml') root.setproperty('picture', log_file) title = os.getenv('INITIAL_USER_TITLE', '') first_name = os.getenv('INITIAL_USER_FIRSTNAME', '') last_name = os.getenv('INITIAL_USER_LASTNAME', '') email = os.getenv('INITIAL_USER_EMAIL', '') phone = os.getenv('INITIAL_USER_PHONE', '') if first_name and last_name and (phone or email): _invite_first_user( root, request, title, first_name, last_name, email, phone) del root.first_invitation_to_add # This is a change in ZODB, but it's ok, it is executed only the first # time when we only have one worker. transaction.commit() manager.pop()