Ejemplo n.º 1
0
 def page_class_plugin_mixin(self, page_class, plugin_webpage_classes):
     """Mixin the current class with the *plugin_webpage_classes* attribute
     
     :param page_class: TODO
     :param plugin_webpage_classes: TODO"""
     for plugin_webpage_class in plugin_webpage_classes:
         classMixin(page_class, plugin_webpage_class, only_callables=False)
Ejemplo n.º 2
0
 def page_class_plugin_mixin(self, page_class, plugin_webpage_classes):
     """Mixin the current class with the *plugin_webpage_classes* attribute
     
     :param page_class: TODO
     :param plugin_webpage_classes: TODO"""
     for plugin_webpage_class in plugin_webpage_classes:
         classMixin(page_class, plugin_webpage_class, only_callables=False)
Ejemplo n.º 3
0
 def loadTableScript(self, page, table=None, respath=None, class_name=None):
     """TODO
     
     :param page: TODO
     :param table: the :ref:`database table <table>` name on which the query will be executed,
                   in the form ``packageName.tableName`` (packageName is the name of the
                   :ref:`package <packages>` to which the table belongs to)
     :param respath: TODO
     :param class_name: TODO
     """
     class_name = class_name or 'Main'
     application = self.gnrapp
     if ':' in respath:
         table, respath = respath.split(':')
     if isinstance(table, basestring):
         table = application.db.table(table)
     if not table:
         tablename = '_default'
         modName = os.path.join('tables', tablename, *(respath.split('/')))
     else:
         tablename = table.name
         pkgname = table.pkg.name
         modName = os.path.join('tables', '_packages', pkgname, tablename,
                                *(respath.split('/')))
     resourceDirs = page.resourceDirs
     modPathList = self.getResourceList(resourceDirs, modName, 'py')
     if not modPathList and table is not None:
         resourceDirs = self.package_resourceDirs(table.pkg.name)
         modName = os.path.join('tables', tablename, *(respath.split('/')))
         modPathList = self.getResourceList(resourceDirs, modName, 'py')
         if not modPathList:
             tablename = '_default'
             resourceDirs = page.resourceDirs
             modName = os.path.join('tables', tablename,
                                    *(respath.split('/')))
             modPathList = self.getResourceList(resourceDirs, modName, 'py')
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         basePath = modPathList.pop(0)
         resource_module = gnrImport(basePath, avoidDup=True)
         resource_class = getattr(resource_module, class_name, None)
         for modPath in modPathList:
             resource_module = gnrImport(modPath, avoidDup=True)
             resource_class = cloneClass('CustomResource', resource_class)
             custom_resource_class = getattr(resource_module, class_name,
                                             None)
             if resource_class:
                 classMixin(resource_class,
                            custom_resource_class,
                            only_callables=False)
         resource_obj = resource_class(page=page, resource_table=table)
         return resource_obj
     else:
         raise GnrWebServerError('Cannot import component %s' % modName)
Ejemplo n.º 4
0
 def get_page_class(self, path=None, pkg=None):
     """add???
     
     :param path: add???. Default value is ``None``
     :param pkg: add???. Default value is ``None``
     :returns: add???
     """
     if pkg == '*':
         module_path = os.path.join(self.site_path, path)
         pkg = self.site.config['packages?default']
     else:
         module_path = os.path.join(self.gnrapp.packages[pkg].packageFolder, 'webpages', path)
         
     # if module_path in self.page_factories:
     #    return self.page_factories[module_path]
     page_module = gnrImport(module_path, avoidDup=True)
     page_factory = getattr(page_module, 'page_factory', GnrWebPage)
     custom_class = getattr(page_module, 'GnrCustomWebPage')
     py_requires = splitAndStrip(getattr(custom_class, 'py_requires', ''), ',')
     plugin_webpage_classes = self.plugin_webpage_classes(path, pkg=pkg)
     for plugin_webpage_class in plugin_webpage_classes:
         plugin_py_requires = splitAndStrip(getattr(plugin_webpage_class, 'py_requires', ''), ',')
         py_requires.extend(plugin_py_requires)
     page_class = cloneClass('GnrCustomWebPage', page_factory)
     page_class.__module__ = page_module
     self.page_class_base_mixin(page_class, pkg=pkg)
     page_class.dojo_version = getattr(custom_class, 'dojo_version', None) or self.site.config[
                                                                              'dojo?version'] or '11'
     page_class.theme = getattr(custom_class, 'theme', None) or self.site.config['dojo?theme'] or 'tundra'
     page_class.gnrjsversion = getattr(custom_class, 'gnrjsversion', None) or self.site.config[
                                                                              'gnrjs?version'] or '11'
     page_class.maintable = getattr(custom_class, 'maintable', None)
     page_class.recordLock = getattr(custom_class, 'recordLock', None)
     page_class.user_polling = int(
             getattr(custom_class, 'user_polling', None) or self.site.config['polling?user'] or 3)
     page_class.auto_polling = int(
             getattr(custom_class, 'auto_polling', None) or self.site.config['polling?auto'] or 30)
     page_class.eagers = getattr(custom_class, 'eagers', {})
     page_class.css_requires = []
     page_class.js_requires = splitAndStrip(getattr(custom_class, 'js_requires', ''), ',')
     page_class.pageOptions = getattr(custom_class, 'pageOptions', {})
     page_class.auth_tags = getattr(custom_class, 'auth_tags', '')
     page_class.resourceDirs = self.page_class_resourceDirs(page_class, module_path, pkg=pkg)
     self.page_pyrequires_mixin(page_class, py_requires)
     classMixin(page_class, custom_class, only_callables=False)
     page_class.css_requires.extend([x for x in splitAndStrip(getattr(custom_class, 'css_requires', ''), ',') if x])
     page_class.tpldirectories = page_class.resourceDirs + [
             self.gnr_static_handler.path(page_class.gnrjsversion, 'tpl')]
     page_class._packageId = pkg
     self.page_class_plugin_mixin(page_class, plugin_webpage_classes)
     self.page_class_custom_mixin(page_class, path, pkg=pkg)
     self.page_factories[module_path] = page_class
     return page_class
Ejemplo n.º 5
0
 def loadTableScript(self, page, table=None, respath=None, class_name=None):
     """TODO
     
     :param page: TODO
     :param table: the :ref:`database table <table>` name on which the query will be executed,
                   in the form ``packageName.tableName`` (packageName is the name of the
                   :ref:`package <packages>` to which the table belongs to)
     :param respath: TODO
     :param class_name: TODO
     """
     class_name = class_name or 'Main'
     application = self.gnrapp
     if ':' in respath:
         table, respath = respath.split(':')
     if isinstance(table, basestring):
         table = application.db.table(table)
     if not table:
         tablename = '_default'
         modName = os.path.join('tables', tablename, *(respath.split('/')))
     else:
         tablename = table.name
         pkgname = table.pkg.name
         modName = os.path.join('tables','_packages',pkgname, tablename, *(respath.split('/')))
     resourceDirs = page.resourceDirs
     modPathList = self.getResourceList(resourceDirs, modName, 'py')
     if not modPathList and table is not None:
         resourceDirs = self.package_resourceDirs(table.pkg.name)
         modName = os.path.join('tables', tablename, *(respath.split('/')))
         modPathList = self.getResourceList(resourceDirs, modName, 'py')
         if not modPathList:
             tablename = '_default'
             resourceDirs = page.resourceDirs
             modName = os.path.join('tables', tablename, *(respath.split('/')))
             modPathList = self.getResourceList(resourceDirs, modName, 'py')
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         basePath = modPathList.pop(0)
         resource_module = gnrImport(basePath, avoidDup=True)
         resource_class = getattr(resource_module, class_name, None)
         for modPath in modPathList:
             resource_module = gnrImport(modPath, avoidDup=True)
             resource_class =cloneClass('CustomResource', resource_class)
             custom_resource_class = getattr(resource_module, class_name, None)
             if resource_class:
                 classMixin(resource_class, custom_resource_class, only_callables=False)
         resource_obj = resource_class(page=page, resource_table=table)
         return resource_obj
     else:
         raise GnrWebServerError('Cannot import component %s' % modName)
Ejemplo n.º 6
0
 def page_class_custom_mixin(self, page_class, path, pkg=None):
     """Look in the instance custom folder for a file named as the current webpage
     
     :param page_class: TODO
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     path = path.split(os.path.sep)
     if pkg:
         customPagePath = os.path.join(self.gnrapp.customFolder, pkg, 'webpages', *path)
         if os.path.isfile(customPagePath):
             component_page_module = gnrImport(customPagePath, avoidDup=True)
             component_page_class = getattr(component_page_module, 'WebPage', None)
             if component_page_class:
                 classMixin(page_class, component_page_class, only_callables=False)
Ejemplo n.º 7
0
 def page_class_custom_mixin(self, page_class, path, pkg=None):
     """Look in the instance custom folder for a file named as the current webpage
     
     :param page_class: TODO
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     path = path.split(os.path.sep)
     if pkg:
         customPagePath = os.path.join(self.gnrapp.customFolder, pkg, 'webpages', *path)
         if os.path.isfile(customPagePath):
             component_page_module = gnrImport(customPagePath, avoidDup=True)
             component_page_class = getattr(component_page_module, 'WebPage', None)
             if component_page_class:
                 classMixin(page_class, component_page_class, only_callables=False)
Ejemplo n.º 8
0
 def mixinResource(self, kls, resourceDirs, *path):        
     """TODO
     
     :param kls: TODO
     :param resourceDirs: TODO
     :param \*path: TODO"""
     path = os.path.join(*path)
     if ':' in path:
         modName, clsName = path.split(':')
     else:
         modName, clsName = path, '*'
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         for modPath in modPathList:
             classMixin(kls, '%s:%s' % (modPath, clsName), only_callables=False, site=self)
     else:
         raise GnrMixinError('Cannot import component %s' % modName)
Ejemplo n.º 9
0
 def mixinResource(self, kls, resourceDirs, *path):        
     """TODO
     
     :param kls: TODO
     :param resourceDirs: TODO
     :param \*path: TODO"""
     path = os.path.join(*path)
     if ':' in path:
         modName, clsName = path.split(':')
     else:
         modName, clsName = path, '*'
     modPathList = self.getResourceList(resourceDirs, modName, 'py') or []
     if modPathList:
         modPathList.reverse()
         for modPath in modPathList:
             classMixin(kls, '%s:%s' % (modPath, clsName), only_callables=False, site=self)
     else:
         raise GnrMixinError('Cannot import component %s' % modName)
Ejemplo n.º 10
0
 def page_class_base_mixin(self, page_class, pkg=None):
     """Look for custom classes in the package
     
     :param page_class: TODO
     :param pkg: the :ref:`package <packages>` object"""
     if pkg:
         package = self.gnrapp.packages[pkg]
     if package and package.webPageMixin:
         classMixin(page_class, package.webPageMixin, only_callables=False) # first the package standard
     if self.gnrapp.webPageCustom:
         classMixin(page_class, self.gnrapp.webPageCustom, only_callables=False) # then the application custom
     if package and package.webPageMixinCustom:
         classMixin(page_class, package.webPageMixinCustom, only_callables=False) # finally the package custom
Ejemplo n.º 11
0
 def page_class_base_mixin(self, page_class, pkg=None):
     """Look for custom classes in the package
     
     :param page_classe: add???
     :param pkg: add???. Default value is ``None``
     """
     if pkg:
         package = self.gnrapp.packages[pkg]
     if package and package.webPageMixin:
         classMixin(page_class, package.webPageMixin, only_callables=False) # first the package standard
     if self.gnrapp.webPageCustom:
         classMixin(page_class, self.gnrapp.webPageCustom, only_callables=False) # then the application custom
     if package and package.webPageMixinCustom:
         classMixin(page_class, package.webPageMixinCustom, only_callables=False) # finally the package custom
Ejemplo n.º 12
0
 def page_class_base_mixin(self, page_class, pkg=None):
     """Look for custom classes in the package
     
     :param page_class: TODO
     :param pkg: the :ref:`package <packages>` object"""
     package = None
     if pkg:
         package = self.gnrapp.packages[pkg]
     if package and package.webPageMixin:
         classMixin(page_class, package.webPageMixin, only_callables=False) # first the package standard
     if self.gnrapp.webPageCustom:
         classMixin(page_class, self.gnrapp.webPageCustom, only_callables=False) # then the application custom
     if package and package.webPageMixinCustom:
         classMixin(page_class, package.webPageMixinCustom, only_callables=False) # finally the package custom
Ejemplo n.º 13
0
 def page_class_base_mixin(self, page_class, pkg=None):
     """Look for custom classes in the package
     
     :param page_classe: add???
     :param pkg: add???. Default value is ``None``
     """
     if pkg:
         package = self.gnrapp.packages[pkg]
     if package and package.webPageMixin:
         classMixin(page_class, package.webPageMixin,
                    only_callables=False)  # first the package standard
     if self.gnrapp.webPageCustom:
         classMixin(page_class,
                    self.gnrapp.webPageCustom,
                    only_callables=False)  # then the application custom
     if package and package.webPageMixinCustom:
         classMixin(page_class,
                    package.webPageMixinCustom,
                    only_callables=False)  # finally the package custom
Ejemplo n.º 14
0
 def get_page_class(self, path=None, pkg=None, plugin=None,request_args=None,request_kwargs=None):
     """TODO
     
     :param path: TODO
     :param pkg: the :ref:`package <packages>` object"""
     if pkg == '*':
         module_path = os.path.join(self.site_path, path)
         pkg = self.site.config['packages?default']
     else:
         if plugin:
             module_path= os.path.join(self.gnrapp.packages[pkg].plugins[plugin].webpages_path, path)
         else:
             module_path = os.path.join(self.gnrapp.packages[pkg].packageFolder, 'webpages', path)
         
     # if module_path in self.page_factories:
     #    return self.page_factories[module_path]
     page_module = gnrImport(module_path, avoidDup=True)
     page_factory = getattr(page_module, 'page_factory', GnrWebPage)
     custom_class = getattr(page_module, 'GnrCustomWebPage')
     mainPkg = pkg
     if hasattr(custom_class,'getMainPackage'):
         kw = dict()
         if 'page_id' in request_kwargs:
             kw = self.site.register.pageStore(request_kwargs['page_id']).getItem('pageArgs') or dict()
             kw.update(request_kwargs)
         mainPkg = custom_class.getMainPackage(request_args=request_args,request_kwargs=kw)
     py_requires = splitAndStrip(getattr(custom_class, 'py_requires', ''), ',')
     plugin_webpage_classes = self.plugin_webpage_classes(path, pkg=mainPkg)
     for plugin_webpage_class in plugin_webpage_classes:
         plugin_py_requires = splitAndStrip(getattr(plugin_webpage_class, 'py_requires', ''), ',')
         py_requires.extend(plugin_py_requires)
     page_class = cloneClass('GnrCustomWebPage', page_factory)
     page_class.__module__ = page_module.__name__
     self.page_class_base_mixin(page_class, pkg=mainPkg)
     page_class.dojo_version = getattr(custom_class, 'dojo_version', None) or self.site.config[
                                                                              'dojo?version'] or '11'
     page_class.theme = getattr(custom_class, 'theme', None) or self.site.config['dojo?theme'] or 'tundra'
     page_class.gnrjsversion = getattr(custom_class, 'gnrjsversion', None) or self.site.config[
                                                                              'gnrjs?version'] or '11'
     page_class.maintable = getattr(custom_class, 'maintable', None)
     page_class.recordLock = getattr(custom_class, 'recordLock', None)
     page_class.user_polling = int(
             getattr(custom_class, 'user_polling', None) or self.site.config['polling?user'] or 3)
     page_class.auto_polling = int(
             getattr(custom_class, 'auto_polling', None) or self.site.config['polling?auto'] or 30)
     if hasattr(custom_class,'polling_enabled'):
         page_class.polling_enabled = getattr(custom_class, 'polling_enabled')
     page_class.eagers = getattr(custom_class, 'eagers', {})
     page_class.css_requires = []
     page_class.js_requires = splitAndStrip(getattr(custom_class, 'js_requires', ''), ',')
     page_class.pageOptions = getattr(custom_class, 'pageOptions', {})
     page_class.auth_tags = getattr(custom_class, 'auth_tags', '')
     page_class.resourceDirs = self.page_class_resourceDirs(page_class, module_path, pkg=mainPkg)
     self.page_pyrequires_mixin(page_class, py_requires)
     classMixin(page_class, custom_class, only_callables=False)
     page_class.css_requires.extend([x for x in splitAndStrip(getattr(custom_class, 'css_requires', ''), ',') if x])
     page_class.tpldirectories = page_class.resourceDirs + [
             self.gnr_static_handler.path(page_class.gnrjsversion, 'tpl')]
     page_class._packageId = mainPkg
     self.page_class_plugin_mixin(page_class, plugin_webpage_classes)
     self.page_class_custom_mixin(page_class, path, pkg=mainPkg)
     self.page_factories[module_path] = page_class
     return page_class
Ejemplo n.º 15
0
    def get_page_class(self, path=None, pkg=None):
        """add???
        
        :param path: add???. Default value is ``None``
        :param pkg: add???. Default value is ``None``
        :returns: add???
        """
        if pkg == '*':
            module_path = os.path.join(self.site_path, path)
            pkg = self.site.config['packages?default']
        else:
            module_path = os.path.join(self.gnrapp.packages[pkg].packageFolder,
                                       'webpages', path)

        # if module_path in self.page_factories:
        #    return self.page_factories[module_path]
        page_module = gnrImport(module_path, avoidDup=True)
        page_factory = getattr(page_module, 'page_factory', GnrWebPage)
        custom_class = getattr(page_module, 'GnrCustomWebPage')
        py_requires = splitAndStrip(getattr(custom_class, 'py_requires', ''),
                                    ',')
        plugin_webpage_classes = self.plugin_webpage_classes(path, pkg=pkg)
        for plugin_webpage_class in plugin_webpage_classes:
            plugin_py_requires = splitAndStrip(
                getattr(plugin_webpage_class, 'py_requires', ''), ',')
            py_requires.extend(plugin_py_requires)
        page_class = cloneClass('GnrCustomWebPage', page_factory)
        page_class.__module__ = page_module
        self.page_class_base_mixin(page_class, pkg=pkg)
        page_class.dojo_version = getattr(
            custom_class, 'dojo_version',
            None) or self.site.config['dojo?version'] or '11'
        page_class.theme = getattr(
            custom_class, 'theme',
            None) or self.site.config['dojo?theme'] or 'tundra'
        page_class.gnrjsversion = getattr(
            custom_class, 'gnrjsversion',
            None) or self.site.config['gnrjs?version'] or '11'
        page_class.maintable = getattr(custom_class, 'maintable', None)
        page_class.recordLock = getattr(custom_class, 'recordLock', None)
        page_class.user_polling = int(
            getattr(custom_class, 'user_polling', None)
            or self.site.config['polling?user'] or 3)
        page_class.auto_polling = int(
            getattr(custom_class, 'auto_polling', None)
            or self.site.config['polling?auto'] or 30)
        page_class.eagers = getattr(custom_class, 'eagers', {})
        page_class.css_requires = []
        page_class.js_requires = splitAndStrip(
            getattr(custom_class, 'js_requires', ''), ',')
        page_class.pageOptions = getattr(custom_class, 'pageOptions', {})
        page_class.auth_tags = getattr(custom_class, 'auth_tags', '')
        page_class.resourceDirs = self.page_class_resourceDirs(page_class,
                                                               module_path,
                                                               pkg=pkg)
        self.page_pyrequires_mixin(page_class, py_requires)
        classMixin(page_class, custom_class, only_callables=False)
        page_class.css_requires.extend([
            x for x in splitAndStrip(getattr(custom_class, 'css_requires', ''),
                                     ',') if x
        ])
        page_class.tpldirectories = page_class.resourceDirs + [
            self.gnr_static_handler.path(page_class.gnrjsversion, 'tpl')
        ]
        page_class._packageId = pkg
        self.page_class_plugin_mixin(page_class, plugin_webpage_classes)
        self.page_class_custom_mixin(page_class, path, pkg=pkg)
        self.page_factories[module_path] = page_class
        return page_class
Ejemplo n.º 16
0
    def get_page_class(self, basepath=None,relpath=None, pkg=None, plugin=None,request_args=None,request_kwargs=None):
        """TODO
        
        :param path: TODO
        :param pkg: the :ref:`package <packages>` object"""

        module_path = os.path.join(basepath,relpath)
        page_module = gnrImport(module_path, avoidDup=True,silent=False)
        page_factory = getattr(page_module, 'page_factory', GnrWebPage)
        custom_class = getattr(page_module, 'GnrCustomWebPage')
        mainPkg = pkg
        if hasattr(custom_class,'getMainPackage'):
            kw = dict()
            if 'page_id' in request_kwargs:
                kw = self.site.register.pageStore(request_kwargs['page_id']).getItem('pageArgs') or dict()
                kw.update(request_kwargs)
            mainPkg = custom_class.getMainPackage(request_args=request_args,request_kwargs=kw)
        py_requires = splitAndStrip(getattr(custom_class, 'py_requires', ''), ',')
        plugin_webpage_classes = self.plugin_webpage_classes(relpath, pkg=mainPkg)
        for plugin_webpage_class in plugin_webpage_classes:
            plugin_py_requires = splitAndStrip(getattr(plugin_webpage_class, 'py_requires', ''), ',')
            py_requires.extend(plugin_py_requires)
        page_class = cloneClass('GnrCustomWebPage', page_factory)
        page_class.__module__ = page_module.__name__
        self.page_class_base_mixin(page_class, pkg=mainPkg)
        package_py_requires = splitAndStrip(getattr(page_class, 'package_py_requires', ''), ',')
        package_js_requires = splitAndStrip(getattr(page_class, 'package_js_requires', ''), ',')
        package_css_requires = splitAndStrip(getattr(page_class, 'package_css_requires', ''), ',') 
        if package_py_requires:
            py_requires = uniquify(package_py_requires + py_requires)
        page_class.dojo_version = getattr(custom_class, 'dojo_version', None) or self.site.config[
                                                                                 'dojo?version'] or '11'
        page_class.theme = getattr(custom_class, 'theme', None) or self.site.config['dojo?theme'] or 'tundra'
        page_class.gnrjsversion = getattr(custom_class, 'gnrjsversion', None) or self.site.config[
                                                                                 'gnrjs?version'] or '11'
        page_class.maintable = getattr(custom_class, 'maintable', None)
        page_class.recordLock = getattr(custom_class, 'recordLock', None)
        page_class.user_polling = int(
                getattr(custom_class, 'user_polling', None) or self.site.config['polling?user'] or 3)
        page_class.auto_polling = int(
                getattr(custom_class, 'auto_polling', None) or self.site.config['polling?auto'] or 30)
        if hasattr(custom_class,'polling_enabled'):
            page_class.polling_enabled = getattr(custom_class, 'polling_enabled')
        page_class.eagers = getattr(custom_class, 'eagers', {})
        page_class.css_requires = []
        page_class.js_requires = splitAndStrip(getattr(custom_class, 'js_requires', ''), ',')
        if package_js_requires:
            page_class.js_requires = uniquify(package_js_requires + page_class.js_requires)
        page_class.pageOptions = getattr(custom_class, 'pageOptions', {})
        page_class.auth_tags = getattr(custom_class, 'auth_tags', '')
        page_class.resourceDirs = self.page_class_resourceDirs(page_class, module_path, pkg=mainPkg)
        self.page_pyrequires_mixin(page_class, py_requires)
        classMixin(page_class, custom_class, only_callables=False)
        page_class.css_requires.extend([x for x in splitAndStrip(getattr(custom_class, 'css_requires', ''), ',') if x])
        if package_css_requires:
            page_class.css_requires = uniquify(page_class.css_requires+package_css_requires)
        page_class.tpldirectories = page_class.resourceDirs + [
                self.gnr_static_handler.path(page_class.gnrjsversion, 'tpl')]
        page_class._packageId = mainPkg
        self.page_class_plugin_mixin(page_class, plugin_webpage_classes)
        self.page_class_custom_mixin(page_class, relpath, pkg=mainPkg)
        self.page_factories[module_path] = page_class
        return page_class