Exemplo n.º 1
0
    def __init__(self, suite, name=None):
        """Create a new instance of the application.

        Args:
            suite (sondra.suite.Suite): The suite with which to register the application.
            name (str): If supplied, this is the name of the app.  Otherwise, the name is the same as the classname
              The application slug is the slugified version of the name.
        """
        self.suite = suite
        self.name = name or self.__class__.__name__
        self.slug = utils.camelcase_slugify(self.name)
        self.db = utils.convert_camelcase(self.name)
        self.connection = suite.connections[self.connection]
        self.collections = {}
        self._url = '/'.join((self.suite.base_url, self.slug))
        self.log = logging.getLogger(self.name)
        self.application = self

        signals.pre_registration.send(self.__class__, instance=self)
        suite.register_application(self)
        signals.post_registration.send(self.__class__, instance=self)

        signals.pre_init.send(self.__class__, instance=self)
        for name, collection_class in self.__class__:
            self.collections[name] = collection_class(self)
        signals.post_init.send(self.__class__, instance=self)
Exemplo n.º 2
0
    def __init__(self, suite, name=None):
        """Create a new instance of the application.

        Args:
            suite (sondra.suite.Suite): The suite with which to register the application.
            name (str): If supplied, this is the name of the app.  Otherwise, the name is the same as the classname
              The application slug is the slugified version of the name.
        """
        self.suite = suite
        self.name = name or self.__class__.__name__
        self.title = utils.split_camelcase(self.name)
        self.slug = utils.camelcase_slugify(self.name)
        if suite.db_prefix:
            self.db = suite.db_prefix + utils.convert_camelcase(self.name)
        else:
            self.db = utils.convert_camelcase(self.name)
        self._collections = {}
        self._url = '/'.join((self.suite.url, self.slug))
        self.log = logging.getLogger(self.name)
        self.application = self

        signals.pre_registration.send(self.__class__, instance=self)
        self.log.info("Registering application {0}".format(self.slug))
        suite.register_application(self)
        signals.post_registration.send(self.__class__, instance=self)

        signals.pre_init.send(self.__class__, instance=self)
        for collection_class in self.collections:
            name = collection_class.slug
            self.log.info("Creating collection for {0}/{1}".format(self.slug, collection_class.slug))
            if name in self._collections:
                raise ApplicationException(name + " already exists in " + self.name)
            coll = collection_class(self)

            # inherit definitions from this suite
            if self.suite.definitions and 'definitions' not in coll.schema:
                coll.schema['definitions'] = {}
            for k, v in self.suite.definitions.items():
                if k not in coll.schema['definitions']:
                    coll.schema['definitions'][k] = v

            # inherit definitions from this application
            if self.definitions and 'definitions' not in coll.schema:
                coll.schema['definitions'] = {}
            for k, v in self.definitions.items():
                if k not in coll.schema['definitions']:
                    coll.schema['definitions'][k] = v

            coll.document_class.specials = SchemaParser(coll.schema, coll.schema['definitions'])()

            self._collections[name] = coll
        signals.post_init.send(self.__class__, instance=self)
Exemplo n.º 3
0
    def __init__(cls, name, bases, nmspc):
        super(CollectionMetaclass, cls).__init__(name, bases, nmspc)
        cls.exposed_methods = {}
        for base in bases:
            if hasattr(base, 'exposed_methods'):
                cls.exposed_methods.update(base.exposed_methods)
        for name, method in (n for n in nmspc.items() if hasattr(n[1], 'exposed')):
                cls.exposed_methods[name] = method

        cls.name = utils.convert_camelcase(cls.__name__)

        cls.schema = deepcopy(cls.document_class.schema)

        if 'description' not in cls.schema and cls.__doc__:
            cls.schema['description'] = cls.__doc__

        if "title" not in cls.schema:
            cls.schema['title'] = cls.__name__

        if "definitions" in cls.schema:
            cls.schema['definitions'].update(cls.definitions)
        else:
            cls.schema['definitions'] = cls.definitions

        if 'id' in cls.schema['properties']:
            raise CollectionException('Document schema should not have an "id" property')

        if not cls.primary_key:
            cls.schema['properties']['id'] = {"type": "string"}

        cls.schema["methods"] = [m.slug for m in cls.exposed_methods.values()]
        cls.schema["documentMethods"] = [m.slug for m in cls.document_class.exposed_methods.values()]

        _validator.check_schema(cls.schema)

        if not hasattr(cls, 'application') or cls.application is None:
            cls.abstract = True
        else:
            cls.abstract = False

        if not cls.abstract:
            cls.slug = utils.camelcase_slugify(cls.__name__)
            cls.application.register_collection(cls)
Exemplo n.º 4
0
    def __init__(cls, name, bases, nmspc):
        super(CollectionMetaclass, cls).__init__(name, bases, nmspc)
        cls.exposed_methods = {}
        cls.title = cls.title or cls.__name__
        cls.name = utils.convert_camelcase(cls.__name__)

        for base in bases:
            if hasattr(base, 'exposed_methods'):
                cls.exposed_methods.update(base.exposed_methods)
        for name, method in (n for n in nmspc.items() if hasattr(n[1], 'exposed')):
                cls.exposed_methods[name] = method

        if cls.document_class and (cls.document_class is not Document):
            cls.abstract = False
            cls.schema = deepcopy(cls.document_class.schema)

            if cls.primary_key == 'id':
                cls.schema['properties']['id'] = {"type": "string", "description": "The primary key.", "title": "ID"}
                cls.document_class.schema['properties']['id'] = {"type": "string", "description": "The primary key.", "title": "ID"}

            cls.schema["methods"] = {}
            for m in cls.exposed_methods.values():
                cls.schema['methods'][m.slug] = method_schema(False, m)

            cls.schema['documentMethods'] = {}
            for m in cls.document_class.exposed_methods.values():
                cls.schema["documentMethods"][m.slug] = method_schema(None, m)

            cls.schema['primary_key'] = 'id' if not cls.primary_key else cls.primary_key

            if not 'description' in cls.schema:
                cls.schema['description'] = cls.document_class.__doc__ or 'No Description Provided.'

            if not 'title' in cls.schema:
                cls.schema['title'] = split_camelcase(cls.document_class.__name__)

            _validator.check_schema(cls.schema)

            cls.slug = utils.camelcase_slugify(cls.__name__)

        else:
            cls.abstract = True
Exemplo n.º 5
0
    def __init__(cls, name, bases, nmspc):
        super(CollectionMetaclass, cls).__init__(name, bases, nmspc)
        cls.exposed_methods = {}
        cls.title = cls.title or cls.__name__
        cls.name = utils.convert_camelcase(cls.__name__)

        for base in bases:
            if hasattr(base, 'exposed_methods'):
                cls.exposed_methods.update(base.exposed_methods)
        for name, method in (n for n in nmspc.items() if hasattr(n[1], 'exposed')):
                cls.exposed_methods[name] = method

        if cls.document_class and (cls.document_class is not Document):
            cls.abstract = False
            cls.schema = deepcopy(cls.document_class.schema)

            if cls.primary_key == 'id':
                cls.schema['properties']['id'] = {"type": "string", "description": "The primary key.", "title": "ID"}
                cls.document_class.schema['properties']['id'] = {"type": "string", "description": "The primary key.", "title": "ID"}

            cls.schema["methods"] = {}
            for m in cls.exposed_methods.values():
                cls.schema['methods'][m.slug] = method_schema(False, m)

            cls.schema['documentMethods'] = {}
            for m in cls.document_class.exposed_methods.values():
                cls.schema["documentMethods"][m.slug] = method_schema(None, m)

            cls.schema['primary_key'] = 'id' if not cls.primary_key else cls.primary_key

            if not 'description' in cls.schema:
                cls.schema['description'] = cls.document_class.__doc__ or 'No Description Provided.'

            if not 'title' in cls.schema:
                cls.schema['title'] = split_camelcase(cls.document_class.__name__)

            _validator.check_schema(cls.schema)

            cls.slug = utils.camelcase_slugify(cls.__name__)

        else:
            cls.abstract = True