コード例 #1
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        self.field_name = field.name
        self.field = field

        self.lookup_kwarg = '%s__in' % field_path
        self.lookup_val = [
            _ for _ in request.GET.get(self.lookup_kwarg, '').split(',')
            if _.strip()
        ]

        super(AjaxFieldFilter, self).__init__(
            field, request, params, model, model_admin, field_path)

        self.model = model

        self.uuid = '_'+str(uuid.uuid4())

#        _d = request.GET.copy()
#        del _d[self.lookup_kwarg]
#        self.base_url = request.path + '?' + _d.urlencode
#        if _d:
#            self.base_url += '&'
#        self.base_url += self.lookup_kwarg + '='

        self.ajax_url = reverse(
            'model_field_search',
            args=(model._meta.app_label, model.__name__.lower(), self.field_name))
コード例 #2
0
    def parse(cls, token):
        '''Parses `token` into float.
        :param token: A python object denoting a token to be pared
        '''
        try:
            return cls.float(token)
        except ValidationError:
            if not isinstance(token, str):
                raise

        # parse semicolon as in matlab: 1:3 = [1,2,3],  1:2:3 = [1,3]
        spl = [_.strip() for _ in token.split(':')]
        if len(spl) < 2 or len(spl) > 3:
            if ':' in token:
                raise ValidationError("Expected format '<start>:<end>' or "
                                      "'<start>:<step>:<end>', found: '%s'" %
                                      token)
            raise ValidationError("Unparsable string '%s'" % token)

        start, step, stop = \
            cls.float(spl[0]), 1 if len(spl) == 2 else \
            cls.float(spl[1]), cls.float(spl[-1])
        decimals = cls.get_decimals(*spl)

        arange = np.arange(start, stop, step, dtype=float)
        if decimals is not None:
            if round(arange[-1].item() + step, decimals) == \
                    round(stop, decimals):
                arange = np.append(arange, stop)

            arange = np.round(arange, decimals=decimals)
            if decimals == 0:
                arange = arange.astype(int)
        return arange.tolist()
コード例 #3
0
    def __init__(self, field, request, params, model, model_admin, field_path):
        self.field_name = field.name
        self.field = field

        self.lookup_kwarg = '%s__in' % field_path
        self.lookup_val = [
            _ for _ in request.GET.get(self.lookup_kwarg, '').split(',')
            if _.strip()
        ]

        super(AjaxFieldFilter, self).__init__(field, request, params, model,
                                              model_admin, field_path)

        self.model = model

        self.uuid = '_' + str(uuid.uuid4())

        #        _d = request.GET.copy()
        #        del _d[self.lookup_kwarg]
        #        self.base_url = request.path + '?' + _d.urlencode
        #        if _d:
        #            self.base_url += '&'
        #        self.base_url += self.lookup_kwarg + '='

        self.ajax_url = reverse('model_field_search',
                                args=(model._meta.app_label,
                                      model.__name__.lower(), self.field_name))
コード例 #4
0
ファイル: assopy_tags.py プロジェクト: yakky/assopy
def field_widget(field, attrs):
    attrs = dict(
        map(lambda _: _.strip(), x.split('=')) for x in attrs.split(','))
    field.field.widget.attrs.update(attrs)
    return field
コード例 #5
0
def field_widget(field, attrs):
    attrs = dict(map(lambda _: _.strip(), x.split('=')) for x in attrs.split(','))
    field.field.widget.attrs.update(attrs)
    return field