Esempio n. 1
0
 def index(self):
     x = get_current_view()
     y = get_url('/')
     print(y)
     print(x.get_url('standalone.index'))
     check_list = ['Fede', 'Bryan', 'John', 'Sara', 'Deborah']
     return self.render('standalone_.html', check_list=check_list)
Esempio n. 2
0
    def get_attributes(self, field):
        for item in ast.literal_eval(field.data):
            filename = item
            if field.url_relative_path:
                filename = urljoin(field.url_relative_path, filename)

            yield get_url(field.endpoint, filename=filename), item
Esempio n. 3
0
    def get_url(self, field):
        if field.thumbnail_size:
            filename = field.thumbnail_fn(field.data)
        else:
            filename = field.data

        if field.url_relative_path:
            filename = urljoin(field.url_relative_path, filename)

        return get_url(field.endpoint, filename=filename)
Esempio n. 4
0
    def get_url(self, field):
        if field.thumbnail_size:
            filename = field.thumbnail_fn(field.data)
        else:
            filename = field.data

        if field.url_relative_path:
            filename = urljoin(field.url_relative_path, filename)

        return get_url(field.endpoint, filename=filename)
Esempio n. 5
0
    def __call__(self, field, **kwargs):
        kwargs.setdefault('data-role', 'select2-ajax')

        # field의 options로 정의된 param들을 data-url에 붙여준다.
        # 추후필요에 따라 data-url자체를 재정의할 수 있는 방법도 제공해주면 좋겠다.
        url = get_url('portal.ajax_model_lookup',
                      name=field.loader.name,
                      querym=json.dumps(field.options))
        kwargs.setdefault('data-url', url)
        # kwargs.setdefault('data-url', field.loader.data_url)

        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')

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

            for value in field.data:
                data = field.loader.format(value)
                options_string.append(
                    HTMLString('<option %s>%s</option>' %
                               (html_params(value=data[0]), data[1])))
                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:
                options_string.append(
                    HTMLString('<option %s>%s</option>' %
                               (html_params(value=data[0]), data[1])))
                kwargs['value'] = data[0]
                kwargs['data-json'] = json.dumps(data)

        placeholder = gettext(
            field.loader.options.get('placeholder', 'Please select model'))
        kwargs.setdefault('data-placeholder', placeholder)

        return HTMLString('<select %s>%s</select>' % (html_params(
            name=field.name, **kwargs), '\n'.join(options_string)))
Esempio n. 6
0
    def get_url(self, field):
        from flask_admin.helpers import get_url
        from flask_admin._compat import urljoin

        if field.thumbnail_size:
            filename = field.thumbnail_fn(field.data)
        else:
            filename = field.data

        if field.url_relative_path:
            filename = urljoin(field.url_relative_path, filename)

        return get_url(field.endpoint, path=filename)
Esempio n. 7
0
    def __call__(self, field, **kwargs):
        kwargs.setdefault('id', field.id)
        placeholder = ''
        if field.data and isinstance(field.data, ImageGridFsProxy):
            args = helpers.make_thumb_args(field.data)
            placeholder = self.template % {
                'thumb': get_url('.api_file_view', **args),
                'marker': '_%s-delete' % field.name
            }

        return Markup(
            '%s<input %s>' %
            (placeholder, html_params(name=field.name, type='file', **kwargs)))
Esempio n. 8
0
    def upload(self):
        return_url = request.headers['Referer']
        file_data = request.files.get('file')
        try:
            question = CommitteeQuestion.import_from_uploaded_answer_file(
                file_data)
            if question.id:
                # it already existed
                flash("That question has already been imported.", "warn")
                return redirect(
                    get_url('.edit_view', id=question.id, url=return_url))

            db.session.add(question)
            db.session.commit()
            flash("Successfully imported from %s" % (file_data.filename, ))
            return redirect(
                get_url('.edit_view', id=question.id, url=return_url))
        except ValueError as e:
            flash(
                "Couldn't import from %s: %s" %
                (file_data.filename, e.message), 'error')
            return redirect(return_url)
Esempio n. 9
0
    def __call__(self, field, **kwargs):
        kwargs.setdefault('id', field.id)
        placeholder = ''
        if field.data and isinstance(field.data, ImageGridFsProxy):
            args = helpers.make_thumb_args(field.data)
            placeholder = self.template % {
                'thumb': get_url('.api_file_view', **args),
                'marker': '_%s-delete' % field.name
            }

        return Markup('%s<input %s>' % (placeholder,
                      html_params(name=field.name,
                                  type='file',
                                  **kwargs)))
Esempio n. 10
0
    def __call__(self, field, **kwargs):
        kwargs.setdefault("id", field.id)

        placeholder = ""
        if field.data and isinstance(field.data, ImageGridFsProxy):
            args = helpers.make_thumb_args(field.data)
            placeholder = self.template % {
                "thumb": get_url(".api_file_view", **args),
                "marker": "_%s-delete" % field.name,
            }

        return HTMLString(
            "%s<input %s>"
            % (placeholder, html_params(name=field.name, type="file", **kwargs))
        )
Esempio n. 11
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',
                                               gettext('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 HTMLString('<input %s>' %
                          html_params(name=field.name, **kwargs))
Esempio n. 12
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', gettext('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))
Esempio n. 13
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", gettext("Please select model"))
        kwargs.setdefault("data-placeholder", placeholder)

        return HTMLString("<input %s>" % html_params(name=field.name, **kwargs))