コード例 #1
0
ファイル: app.py プロジェクト: danroberts/wrook
def onRequest(self):
	'''
	Initialization method triggered before a request is processed.
	'''
	import os
	import datetime
	import random
	from feathers import webapp
	from feathers import membership

	#TODO: Figure out if this should be somewhere else than in the global scope
	webapp.currentRequest = self
	# Use to reference the ongoing request without having to do injection
	self.Model = {}
	self.MasterTemplate = os.path.join(os.path.dirname(__file__), "views/template-main-e.html") # Sets the default template to be used by hosted modules
	self.MasterTemplateStylesheets = os.path.join(os.path.dirname(__file__), "views/stylesheets.html") # Sets the default template to be used by hosted modules
	self.MasterTemplateScripts = os.path.join(os.path.dirname(__file__), "views/scripts.html") # Sets the default template to be used by hosted modules
	self.TemplateBase = os.path.join(os.path.dirname(__file__), "views/template-main.html") # Sets the default template to be used by hosted modules
	self.TemplateBase2 = os.path.join(os.path.dirname(__file__), "views/template-main2.html") # Sets the default template to be used by hosted modules
	self.CurrentMember = membership.loginFromCookies(self) # Load the current member from the google authentication and add it to the requesthandler
	self.CurrentTheme = getDefaultTheme() # Set the default theme as the current theme
	self.AppConfig = getWrookAppConfig() # Load the application config from the database
	if self.CurrentMember: translation.activate(self.CurrentMember.PreferedLanguage) # If the is a current member, his prefered language is activated
	else: translation.activate("en") # If not, the default language is set to english
	self.Model.update({
		'random': random.random(),
		'templateMain': self.MasterTemplate,
		'templateScripts': self.MasterTemplateScripts,
		'templateStylesheets': self.MasterTemplateStylesheets,
		'templateBase': self.TemplateBase,
		'now': datetime.datetime.now(), # Add the current time tot the model
		'currentMember': self.CurrentMember, # Add the current user to the model
		'currentTheme': self.CurrentTheme, # Add the default theme to the model
		'appConfig': self.AppConfig # Add the app config to the model
		})
コード例 #2
0
ファイル: app.py プロジェクト: wrook/wrook
    def onRequest(self, isSetup=False):
        """
		Initialization method triggered before a request is processed.
		"""
        import os
        import datetime
        import random
        from feathers import membership

        self.Model = {}

        self.application = Application.active_instance
        self.addons = self.application.addons()
        # Set current execution context of addons to the currrent request
        self.addons.context = self

        # Store the current environment in the model (ex.: google or dev)
        environ = getEnvironment()

        # Add model data needed before the appConfig
        self.Model.update({"environment": environ, "addons": self.addons})

        config = getWrookAppConfig()

        # Load the application config from the database and attach it to the request
        # If a valid and completed config cant be found, the user is sent to the initial setup

        if config:
            self.AppConfig = config
            if config.SetupComplete:

                # TODO: Figure out if this should be somewhere else than in the global scope
                # 				webapp.currentRequest = self

                # Use to reference the ongoing request without having to do injection
                self.MasterTemplate = os.path.join(
                    os.path.dirname(__file__), "views/template-main-e.html"
                )  # Sets the default template to be used by hosted modules
                self.MasterTemplateStylesheets = os.path.join(
                    os.path.dirname(__file__), "views/stylesheets.html"
                )  # Sets the default template to be used by hosted modules
                self.MasterTemplateScripts = os.path.join(
                    os.path.dirname(__file__), "views/scripts.html"
                )  # Sets the default template to be used by hosted modules
                self.TemplateBase = os.path.join(
                    os.path.dirname(__file__), "views/template-main.html"
                )  # Sets the default template to be used by hosted modules
                self.MasterTemplate2 = "template-main-e2.html"
                self.TemplateBase2 = "template-main-e2.html"  # Sets the default template to be used by hosted modules
                self.CurrentMember = membership.loginFromCookies(
                    self
                )  # Load the current member from the google authentication and add it to the requesthandler
                self.CurrentTheme = getDefaultTheme()  # Set the default theme as the current theme
                if self.CurrentMember:
                    translation.activate(
                        self.CurrentMember.PreferedLanguage
                    )  # If the is a current member, his prefered language is activated
                else:
                    translation.activate("en")  # If not, the default language is set to english
                self.Model.update(
                    {
                        "random": random.random(),
                        "templateMain": self.MasterTemplate,
                        "templateMain2": self.MasterTemplate2,
                        "templateScripts": self.MasterTemplateScripts,
                        "templateStylesheets": self.MasterTemplateStylesheets,
                        "templateBase": self.TemplateBase,
                        "templateBase2": self.TemplateBase2,
                        "now": datetime.datetime.now(),  # Add the current time to the model
                        "currentMember": self.CurrentMember,  # Add the current user to the model
                        "currentTheme": self.CurrentTheme,  # Add the default theme to the model
                        "appConfig": self.AppConfig,  # Add the app config to the model
                        "application": self.application,
                    }
                )
                return
        if not isSetup:
            self.redirect("/admin/setup")