示例#1
0
def models_list():
    # TODO: get models deprecation

    mlist = filterfalse(lambda m: model_settings(m).get('ignore', False),
                        models.get_models())

    return mlist
示例#2
0
def models_list():
    # TODO: get models deprecation

    mlist = filterfalse(
        lambda m: model_settings(m).get('ignore', False),
        models.get_models())

    return mlist
示例#3
0
def models_list():
    if django.get_version() <= '1.7':
        mlist = models.get_models()
    else:
        from django.apps import apps

        mlist = apps.get_models()

    mlist = filterfalse(
        lambda m: model_settings(m).get('ignore', False),
        mlist)

    return mlist
示例#4
0
def build_plugin_tree(plugins):
    """
    Accepts an iterable of plugins and assigns tuples, sorted by position, of
    children plugins to their respective parents.
    Returns a sorted list of root plugins.
    """
    cache = dict((p.pk, p) for p in plugins)
    by_parent_id = attrgetter('parent_id')
    nonroots = sorted(filter(by_parent_id, cache.values()),
                      key=attrgetter('parent_id', 'position'))
    families = ((cache[parent_id], tuple(children))
                for parent_id, children in groupby(nonroots, by_parent_id))
    for parent, children in families:
        parent.child_plugin_instances = children
    return sorted(filterfalse(by_parent_id, cache.values()),
                  key=attrgetter('position'))
示例#5
0
def build_plugin_tree(plugins):
    """
    Accepts an iterable of plugins and assigns tuples, sorted by position, of
    children plugins to their respective parents.
    Returns a sorted list of root plugins.
    """
    cache = dict((p.pk, p) for p in plugins)
    by_parent_id = attrgetter('parent_id')
    nonroots = sorted(filter(by_parent_id, cache.values()),
                      key=attrgetter('parent_id', 'position'))
    families = ((cache[parent_id], tuple(children))
                for parent_id, children
                in groupby(nonroots, by_parent_id))
    for parent, children in families:
        parent.child_plugin_instances = children
    return sorted(filterfalse(by_parent_id, cache.values()),
                  key=attrgetter('position'))
示例#6
0
    def prepare_export_data(self, processor, queryset):
        """Prepare data using filters from settings
        and return data with dimensions"""

        settings = processor.settings
        model = make_model_class(settings)
        msettings = model_settings(model)

        exclude = msettings.get('exclude', [])

        fields = settings.fields_with_processors()
        fields = list(filterfalse(lambda f: f.attribute in exclude, fields))

        if settings.end_row:
            rows = settings.end_row
            if settings.start_row:
                rows -= settings.start_row
                rows += 1

            queryset = queryset[:rows]

        if settings.end_col:
            cols = column_value(settings.end_col)
            if settings.start_col:
                cols -= column_value(settings.start_col)
                cols += 1

            fields = fields[:cols]

        return {
            'rows':
            queryset.count(),
            'cols':
            len(fields),
            'fields':
            fields,
            'items':
            (self.convert_value(process_attribute(item, field.attribute),
                                model,
                                field,
                                export=True) for item in queryset
             for field in fields)
        }
示例#7
0
    def prepare_export_data(self, processor, queryset):
        """Prepare data using filters from settings
        and return data with dimensions"""

        settings = processor.settings
        model = make_model_class(settings)
        msettings = model_settings(model)

        exclude = msettings.get('exclude', [])

        fields = settings.fields_with_converters()
        fields = list(filterfalse(
            lambda f: f.attribute in exclude, fields))

        if settings.end_row:
            rows = settings.end_row
            if settings.start_row:
                rows -= settings.start_row
                rows += 1

            queryset = queryset[:rows]

        mfields = model_fields(model)

        return {
            'rows': queryset.count(),
            'cols': len(fields),
            'fields': fields,
            'mfields': mfields,
            'items': (
                self.convert_value(
                    process_attribute(item, field.attribute),
                    field, export=True)
                for item in queryset
                for field in fields
            )
        }
示例#8
0
    def model_attributes(self, settings):
        """Return iterator of fields names by given mode_path"""

        model = self.model_class(settings)
        msettings = self.model_settings(model)

        exclude = msettings.get('exclude', [])
        fields = model._meta.get_all_field_names()
        fields += msettings.get('fields', [])

        fields = filterfalse(lambda f: f in exclude, fields)

        for name in fields:
            field = self.get_field_by_name(model, name)

            label = name
            custom_label = getattr(field, '_sync_custom_field', False)

            if custom_label:
                label = getattr(field, 'short_description', field.__name__)
            elif field:
                label = field.verbose_name

            yield (name, label.capitalize())
示例#9
0
 def models_list(self):
     mlist = filterfalse(
         lambda m: self.model_settings(m).get('ignore', False),
         models.get_models())
     return mlist