Exemplo n.º 1
0
 def _value(self):
     if isinstance(self.data, (list, tuple)):
         return u','.join(as_unicode(v) for v in self.data)
     elif self.data:
         return as_unicode(self.data)
     else:
         return u''
Exemplo n.º 2
0
    def add_sub_category(self, name, parent_name):

        name_text = as_unicode(name)
        parent_name_text = as_unicode(parent_name)
        category = self.get_category_menu_item(name_text)
        parent = self.get_category_menu_item(parent_name_text)
        if category is None and parent is not None:
            category = SubMenuCategory(name)
            self._menu_categories[name_text] = category
            parent.add_child(category)
Exemplo n.º 3
0
    def add_sub_category(self, name, parent_name):

        name_text = as_unicode(name)
        parent_name_text = as_unicode(parent_name) # Function defined _compat.py
        category = self.get_category_menu_item(name_text)#  Function defined below
        parent = self.get_category_menu_item(parent_name_text)
        if category is None and parent is not None: # Checks if is a Parent or Child Category
            category = SubMenuCategory(name)
            self._menu_categories[name_text] = category
            parent.add_child(category)
Exemplo n.º 4
0
    def non_lazy(self):
        filters = []

        for item in self.filters:
            copy = dict(item)
            copy['operation'] = as_unicode(copy['operation'])
            options = copy['options']
            if options:
                copy['options'] =[(k, text_type(v)) for k,v in options]
            filters.append(copy)
        return as_unicode(self.label), filters
Exemplo n.º 5
0
    def _get_list_filter_args(self):

        if self._filters:
            filter = []

            for arg in request.args:
                if not arg.strartswith('flt'):
                    continue

                if '_' not in arg:
                    continue

                pos, key = arg[3:].split('_', 1)

                if key in self._filter_args:
                    idx, flt = self._filter_args[key]

                    value = request.args[arg]

                    if flt.validate(value):
                        data = (pos, (idx, as_unicode(flt.name), value))
                        filters.append(data)
                    else:
                        flash(self.get_invalid_value_msg(value, flt), 'error')
            return [v[1] for v in sorted(filters, key=lambda n: n[0])]
        return None
Exemplo n.º 6
0
 def _value(self):
     if self.raw_data:
         return self.raw_data[0]
     elif self.data:
         # prevent utf8 characters from being converted to ascii
         return as_unicode(json.dumps(self.data, ensure_ascii=False))
     else:
         return ''
Exemplo n.º 7
0
    def handle_view_exception(self, exc):

        if isinstance(exc, ValidationError):
            flash(as_unicode(exc), 'error')
            return True
        if current_app.config.get('ADMIN_RAISE_ON_VIEW_EXCEPTION'):
            raise
        if self._debug:
            raise

        return False
Exemplo n.º 8
0
    def add_menu_item(self, menu_item, target_category=None):

        if target_category:
            cat_text = as_unicode(target_category)
            category = self._menu_categories.get(cat_text)
            # Create a new Menu category (if doesn't alredy exist)
            if category is None:
                category = MenuCategory(target_category)
                category.class_name = self.category_icon_classes.get(cat_text)
                self._menu_categories[cat_text] = category
                self._menu.append(category)
            category.add_child(menu_item)
        else:
            self._menu.append(menu_item)
Exemplo n.º 9
0
    def get_filter_arg(self, index, flt):

        if self.named_filter_urls:
            operation = flt.operation()

            try:
                operation = operation._args[0]
            except AttributeError:
                pass
            name = ('%s %s' % (flt.name, as_unicode(operation))).lower()
            name = filter_char_re.sub('', name)
            name = filter_compact_re.sub('_', name)
            return name
        else:
            return str(index)
Exemplo n.º 10
0
    def __call__(self, field, **kwargs):
        kwargs.setdefault('data-role', 'select2-ajax')
        kwargs.setdefault('data-url',
                          get_url('.ajax_lookup', name=field.loader.name))

        allow_blank = getattr(field, 'allow_blank', False)
        if allow_blank and not self.multiple:
            kwargs['data-allow-blank'] = u'1'
        kwargs.setdefault('id', field.id)
        kwargs.setdefault('type', 'hidden')

        if self.multiple:
            result = []
            ids = []

            for value in field.data:
                data = field.loader.format(value)
                result.append(data)
                ids.append(as_unicode(data[0]))
            separator = getattr(field, 'separator', ',')
            kwargs['value'] = separator.join(ids)
            kwargs['data-json'] = json.dumps(result)
            kwargs['data-multiple'] = u'1'
        else:
            data = field.loader.format(field.data)

            if data:
                kwargs['value'] = data[0]
                kwargs['data-json'] = json.dumps(data)
        placeholder = field.loader.options.get('placeholder',
                                               'Please select Model')
        kwargs.setdefault('data-placeholder', placeholder)
        minimum_input_length = int(
            field.loader.options.get('minimum_input_length', 1))
        kwargs.setdefault('data-minimum-input-length', minimum_input_length)

        return Markup('<input %S>' % html_params(name=field.name, )**kwargs)
Exemplo n.º 11
0
    def _refresh_filters_cache(self):

        self._filters = self.get_filters()

        if self._filters:
            self._filter_groups = OrderedDict()
            self._filter_args = {}

            for i, flt in enumerate(self._filters):
                key = as_unicode(flt.name)
                if key not in self._filter_groups:
                    self._filter_group[key] = FilterGroup(flt.name)
                self._filter_groups[key].append({
                    'index': 1,
                    'arg': self.get_filter_arg(i, flt),
                    'operation': flt.operation(),
                    'options': flt.get_options(self) or None,
                    'type': flt.data_type
                })

                self._filter_args[self.get_filter_arg(i, flt)] = (i, flt)
        else:
            self._filter_groups = None
            self._filter_args = None
Exemplo n.º 12
0
def iterencode(iter):

    return ','.join(
        as_unicode(v).replace(CHAR_ESCAPE, CHAR_ESCAPE + CHAR_ESCAPE).replace(
            CHAR_SEPARATOR, CHAR_ESCAPE + CHAR_SEPARATOR) for v in iter)
Exemplo n.º 13
0
def escape(value):
    return (as_unicode(value).replace(CHAR_ESCAPE,
                                      CHAR_ESCAPE + CHAR_ESCAPE).replace(
                                          CHAR_SEPARATOR,
                                          CHAR_ESCAPE + CHAR_SEPARATOR))