Example #1
0
 def add_static(self,
                sps,
                not_compile=[],
                url_path="/",
                merge=True,
                build=True):
     static_path = []
     for sp in sps:
         try:
             sp = Importer.module_path(sp)
         except:
             pass
         try:
             static_path.append(sp)
             static_builder = StaticBuilder(sp, not_compile)
             if build:
                 static_builder.build()
             if build:
                 self.wsgi_app = SharedDataMiddleware(
                     self.wsgi_app, {url_path: sp + "/build"}, cache=False)
             else:
                 self.wsgi_app = SharedDataMiddleware(self.wsgi_app,
                                                      {url_path: sp},
                                                      cache=False)
         except:
             pass
     if merge:
         self.options["views"]["static_path"] = self.options["views"][
             "static_path"] + static_path
     else:
         self.options["views"]["static_path"] = static_path
Example #2
0
    def load(plugin_path):
        try:
            plugin_path = Importer.module_path(plugin_path)  # maybe plugin_path is module name
        except:
            pass

        def cb(p):
            if mimetypes.guess_type(p)[0] == "text/x-python":
                Importer.import_module_by_path(p)

        Dir.walk(plugin_path, cb)
Example #3
0
    def load(plugin_path):
        try:
            plugin_path = Importer.module_path(
                plugin_path)  # maybe plugin_path is module name
        except:
            pass

        def cb(p):
            if mimetypes.guess_type(p)[0] == "text/x-python":
                Importer.import_module_by_path(p)

        Dir.walk(plugin_path, cb)
Example #4
0
	def add_translation_paths(self, paths):
		if not paths:
			return
		for tr_path in paths:
			try:
				tr_path = Importer.module_path(tr_path)
			except:
				pass
			try:
				self.app.templates_environment.install_gettext_translations(gettext.translation("messages", tr_path, codeset="UTF-8"))
				gettext.install("messages", tr_path, codeset="UTF-8")
			except:
				pass
Example #5
0
	def add_translation_paths(self, paths):
		if not paths:
			return
		for tr_path in paths:
			try:
				tr_path = Importer.module_path(tr_path)
			except:
				pass
			try:
				self.app.templates_environment.install_gettext_translations(gettext.translation("messages", tr_path, codeset="UTF-8"))
				gettext.install("messages", tr_path, codeset="UTF-8")
			except:
				pass
Example #6
0
	def add_static(self, sps, url_path="/", merge=True):
		static_path = []
		for sp in sps:
			try:
				sp = Importer.module_path(sp)
			except:
				pass
			try:
				static_path.append(sp)
				static_builder = StaticBuilder(sp)
				static_builder.build()
				self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {url_path : sp + "/build"}, cache=False)
			except:
				pass
		if merge:
			self.options["views"]["static_path"] = self.options["views"]["static_path"] + static_path
		else:
			self.options["views"]["static_path"] = static_path
Example #7
0
	def add_template_paths(self, paths, prefix=""):
		tps = []
		for tp in paths:
			loader = None
			try:
				if Importer.module_path(tp): #if it module path
					loader = PackageLoader(tp, "")
			except:
				loader = FileSystemLoader(tp)
			if loader:
				if prefix:
					tps.append(PrefixLoader({prefix: loader}))
				else:
					tps.append(loader)
		if hasattr(self.app, "templates_environment"):
			for tl in tps:
				self.app.templates_environment.loader.loaders.append(tl)
		else:
			self.app.templates_environment = Environment(loader=ChoiceLoader(tps), extensions=self.options["views"]["templates_extensions"])
Example #8
0
	def add_template_paths(self, paths, prefix=""):
		tps = []
		for tp in paths:
			loader = None
			try:
				if Importer.module_path(tp): #if it module path
					loader = PackageLoader(tp, "")
			except:
				loader = FileSystemLoader(tp)
			if loader:
				if prefix:
					tps.append(PrefixLoader({prefix: loader}))
				else:
					tps.append(loader)
		if hasattr(self.app, "templates_environment"):
			for tl in tps:
				self.app.templates_environment.loader.loaders.append(tl)
		else:
			self.app.templates_environment = Environment(loader=ChoiceLoader(tps), extensions=self.options["views"]["templates_extensions"])