Here are the examples of the python api django.utils.six.moves.filter taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

9 Examples 7

Example 1

Project: django-cms
Source File:
View license
    def get_translatable_content(self):
        Returns {field_name: field_contents} for translatable fields, where
        field_contents > ''
        fields = (f for f in self._meta.fields
                  if isinstance(f, (models.CharField, models.TextField)) and
                     f.editable and not f.choices and
            not in self.translatable_content_excluded_fields)
        return dict(filter(itemgetter(1),
                           ((, getattr(self, for f in fields)))

Example 2

Project: django-cms
Source File:
View license
def iterload(modname, verbose=False, failfast=False):
    Loads all modules with name 'modname' from all installed apps and returns
    and iterator of those modules.

    If verbose is True, debug information will be printed to stdout.

    If failfast is True, import errors will not be surpressed.
    return filter(None, (get_module(app, modname, verbose, failfast)
                         for app in installed_apps()))

Example 3

Project: django-cms
Source File:
View license
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) 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()),

Example 4

Project: django-oscar
Source File:
View license
    def _update_search_text(self):
        search_fields = filter(
            bool, [self.first_name, self.last_name,
                   self.line1, self.line2, self.line3, self.line4,
                   self.state, self.postcode,])
        self.search_text = ' '.join(search_fields)

Example 5

Project: django-oscar
Source File:
View license
    def join_fields(self, fields, separator=u", "):
        Join a sequence of fields using the specified separator
        field_values = []
        for field in fields:
            # Title is special case
            if field == 'title':
                value = self.get_title_display()
                value = getattr(self, field)
        return separator.join(filter(bool, field_values))

Example 6

Project: django-oscar
Source File:
View license
    def value_from_datadict(self, data, files, name):
        value = data.get(name, None)
        if value is None:
            return []
            return list(filter(bool, value.split(',')))

Example 7

Project: django-cms
Source File:
View license
def create_default_plugins(request, placeholders, template, lang):
    Create all default plugins for the given ``placeholders`` if they have
    a "default_plugins" configuration value in settings.
    return all plugins, children, grandchildren (etc.) created
    from cms.api import add_plugin

    def _create_default_plugins(placeholder, confs, parent=None):
        Auxillary function that builds all of a placeholder's default plugins
        at the current level and drives the recursion down the tree.
        Returns the plugins at the current level along with all descendants.
        plugins, descendants = [], []
        addable_confs = (conf for conf in confs
                         if has_plugin_permission(request.user,
                                                  conf['plugin_type'], 'add'))
        for conf in addable_confs:
            plugin = add_plugin(placeholder, conf['plugin_type'], lang,
                                target=parent, **conf['values'])
            if 'children' in conf:
                args = placeholder, conf['children'], plugin
                descendants += _create_default_plugins(*args)
            plugin.notify_on_autoadd(request, conf)
        if parent:
            parent.notify_on_autoadd_children(request, conf, plugins)
        return plugins + descendants

    unfiltered_confs = ((ph, get_placeholder_conf('default_plugins',
                                                  ph.slot, template))
                        for ph in placeholders)
    # Empty confs must be filtered before filtering on add permission
    mutable_confs = ((ph, default_plugin_confs)
                     for ph, default_plugin_confs
                     in filter(itemgetter(1), unfiltered_confs)
                     if ph.has_change_permission(request.user))
    return sum(starmap(_create_default_plugins, mutable_confs), [])

Example 8

Project: django-oscar
Source File:
View license
    def format_value(self, value):
        if value:
            return ','.join(map(six.text_type, filter(bool, value)))
            return ''

Example 9

Project: patchwork
Source File:
View license
def user_name(user):
    if user.first_name or user.last_name:
        names = list(filter(bool, [user.first_name, user.last_name]))
        return u' '.join(names)
    return user.username