Esempio n. 1
0
class QueryView(object):
    """Provides a mean of defining/deriving additional metadata from a
    DataConcept and/or it's associated DataField for use downstream by a
    client application. A _default_ QueryView reference can defined for
    `DataConcept` via it's `queryview` field.

    To implement, override the `process` method and return a `dict` that can
    be serialized downstream.

    Additional context _may_ be supplied (but not guaranteed to be supplied)
    via the `context` dict such as the `request` object while be processed
    during an HTTP request/response cycle.

    `QueryView`s are not client specific. It is assumed that clients can make
    use of as little or as much metadata as they choose. That being said, if
    multiple clients are being used, it may be important to namespace the
    relevant metadata so to not cause key collisions.
    """
    def __call__(self, concept, **context):
        return self.process(concept, **context)

    def __unicode__(self):
        return u'{0}'.format(self.name)

    def process(self, concept, **context):
        return {}


registry = loader.Registry(default=QueryView)
loader.autodiscover('queryviews')
Esempio n. 2
0
from django.conf import settings
from avocado.core.loader import autodiscover
from .utils import Channel, job, ManifestReader

PIPELINE_CACHE_ALIAS = getattr(settings, 'VARIFY_PIPELINE_CACHE_ALIAS', 'varify.pipeline')

# Creates a pipeline component registry. `pipeline` modules or packages in
# apps that are _installed_ will be autoloaded which enables auto-registering
# components to the pipeline.
autodiscover('pipeline')
Esempio n. 3
0
        It should be noted that no checks are performed to prevent the same
        name being used for annotations.
        """
        operator, value = \
            self.validate(field, roperator, rvalue, tree, **kwargs)
        condition = self._condition(field, operator, value, tree)
        language = self.language(field, operator, value, **kwargs)

        return {
            'field': field.pk,
            'operator': roperator,
            'value': rvalue,
            'cleaned_data': {
                'value': value,
                'operator': operator,
                'language': language,
            },
            'query_modifiers': {
                'condition': condition,
                'annotations': None,
                'extra': None,
            }
        }


registry = loader.Registry(default=Translator)

# this will be invoked when it is imported by models.py to use the
# registry choices
loader.autodiscover('translators')
Esempio n. 4
0
        It should be noted that no checks are performed to prevent the same
        name being used for annotations.
        """
        operator, value = self.validate(field, roperator, rvalue, tree, **kwargs)
        condition = self._condition(field, operator, value, tree)
        language = self.language(field, operator, value, **kwargs)

        return {
            'id': field.pk,
            'operator': roperator,
            'value': rvalue,
            'cleaned_data': {
                'value': value,
                'operator': operator,
                'language': language,
            },
            'query_modifiers': {
                'condition': condition,
                'annotations': None,
                'extra': None,
            }
        }


registry = loader.Registry(default=Translator)

# this will be invoked when it is imported by models.py to use the
# registry choices
loader.autodiscover('translators')
Esempio n. 5
0
registry.register(Exact, Exact.uid)
registry.register(NotExact, NotExact.uid)

# String operators
registry.register(InsensitiveExact, InsensitiveExact.uid)
registry.register(Contains, Contains.uid)
registry.register(InsensitiveContains, InsensitiveContains.uid)
registry.register(InsensitiveNotExact, InsensitiveNotExact.uid)
registry.register(NotContains, NotContains.uid)
registry.register(NotInsensitiveContains, NotInsensitiveContains.uid)

# Null
registry.register(Null, Null.uid)
registry.register(NotNull, NotNull.uid)

# Numerical or lexicographical comparison
registry.register(LessThan, LessThan.uid)
registry.register(GreaterThan, GreaterThan.uid)
registry.register(LessThanOrEqual, LessThanOrEqual.uid)
registry.register(GreaterThanOrEqual, GreaterThanOrEqual.uid)

# List
registry.register(InList, InList.uid)
registry.register(NotInList, NotInList.uid)

# Range
registry.register(Range, Range.uid)
registry.register(NotRange, NotRange.uid)

loader.autodiscover('operators')
Esempio n. 6
0
from avocado.core import loader
from avocado.conf import OPTIONAL_DEPS
from _csv import CSVExporter
from _sas import SASExporter
from _r import RExporter
from _json import JSONExporter
from _html import HTMLExporter

registry = loader.Registry(register_instance=False)

registry.register(CSVExporter, 'csv')
registry.register(SASExporter, 'sas')
registry.register(RExporter, 'r')
registry.register(JSONExporter, 'json')
registry.register(HTMLExporter, 'html')

if OPTIONAL_DEPS['openpyxl']:
    from _excel import ExcelExporter
    registry.register(ExcelExporter, 'excel')

loader.autodiscover('exporters')
Esempio n. 7
0
from django.conf import settings
from avocado.core.loader import autodiscover
from .utils import Channel, job, ManifestReader  # noqa

PIPELINE_CACHE_ALIAS = \
    getattr(settings, 'VARIFY_PIPELINE_CACHE_ALIAS', 'vdw.pipeline')

# Creates a pipeline component registry. `pipeline` modules or packages in
# apps that are _installed_ will be autoloaded which enables auto-registering
# components to the pipeline.
autodiscover('pipeline')
Esempio n. 8
0
                return float(value)
            except (ValueError, TypeError):
                pass

        raise ExpectedFormatterException('cannot be converted into a number')

    def to_coded(self, value, field, context):
        # Attempts to convert value to its coded representation
        if field:
            coded_values = field.coded_values()

            if coded_values is not None:
                return coded_values.get(value)

        raise ExpectedFormatterException('field does not support coded values')

    def to_raw(self, value, field, context):
        return value


class RawFormatter(Formatter):
    def __init__(self, *args, **kwargs):
        kwargs.pop('formats', None)
        kwargs['formats'] = ('raw',)

        return super(RawFormatter, self).__init__(*args, **kwargs)


registry = loader.Registry(default=Formatter, register_instance=False)
loader.autodiscover('formatters')
Esempio n. 9
0
registry.register(InsensitiveExact, InsensitiveExact.uid)
registry.register(Contains, Contains.uid)
registry.register(InsensitiveContains, InsensitiveContains.uid)
registry.register(InsensitiveNotExact, InsensitiveNotExact.uid)
registry.register(NotContains, NotContains.uid)
registry.register(NotInsensitiveContains, NotInsensitiveContains.uid)
registry.register(Regex, Regex.uid)
registry.register(NotRegex, NotRegex.uid)
registry.register(InsensitiveRegex, InsensitiveRegex.uid)
registry.register(NotInsensitiveRegex, NotInsensitiveRegex.uid)

# Null
registry.register(Null, Null.uid)
registry.register(NotNull, NotNull.uid)

# Numerical or lexicographical comparison
registry.register(LessThan, LessThan.uid)
registry.register(GreaterThan, GreaterThan.uid)
registry.register(LessThanOrEqual, LessThanOrEqual.uid)
registry.register(GreaterThanOrEqual, GreaterThanOrEqual.uid)

# List
registry.register(InList, InList.uid)
registry.register(NotInList, NotInList.uid)

# Range
registry.register(Range, Range.uid)
registry.register(NotRange, NotRange.uid)

loader.autodiscover('operators')
Esempio n. 10
0
from avocado.core import loader
from avocado.conf import OPTIONAL_DEPS
from _base import BaseExporter  # noqa
from _csv import CSVExporter
from _sas import SASExporter
from _r import RExporter
from _json import JSONExporter
from _html import HTMLExporter  # noqa

registry = loader.Registry(register_instance=False)

registry.register(CSVExporter, CSVExporter.short_name.lower())
registry.register(SASExporter, SASExporter.short_name.lower())
registry.register(RExporter, RExporter.short_name.lower())
registry.register(JSONExporter, JSONExporter.short_name.lower())
# registry.register(HTMLExporter, HTMLExporter.short_name.lower())

if OPTIONAL_DEPS['openpyxl']:
    from _excel import ExcelExporter
    registry.register(ExcelExporter, ExcelExporter.short_name.lower())

loader.autodiscover('exporters')
Esempio n. 11
0
                return float(value)
            except (ValueError, TypeError):
                pass

        raise ExpectedFormatterException('cannot be converted into a number')

    def to_coded(self, value, field, context):
        # Attempts to convert value to its coded representation
        if field:
            coded_values = field.coded_values()

            if coded_values is not None:
                return coded_values.get(value)

        raise ExpectedFormatterException('field does not support coded values')

    def to_raw(self, value, field, context):
        return value


class RawFormatter(Formatter):
    def __init__(self, *args, **kwargs):
        kwargs.pop('formats', None)
        kwargs['formats'] = ('raw', )

        return super(RawFormatter, self).__init__(*args, **kwargs)


registry = loader.Registry(default=Formatter, register_instance=False)
loader.autodiscover('formatters')