Exemplo n.º 1
0
def AutocompleteRelationRenderer(filter_by='id', renderer=fields.IntegerFieldRenderer, **jq_options):
    """Use http://docs.jquery.com/UI/Autocomplete with pyramid"""

    class Renderer(renderer):

        def __init__(self, *args, **kwargs):
            super(Renderer, self).__init__(*args, **kwargs)
            self.field.render_opts['options'] = []

        def update_options(self, options, kwargs):
            kwargs['source'] = self.request.fa_url(
                    self.field.relation_type().__name__, 'autocomplete')

        def render(self, **kwargs):
            fanstatic_resources.fa_pyramid_js.need()
            filter_by = self.jq_options.get('filter_by')
            if self.raw_value:
                label = getattr(self.raw_value, filter_by, u'Not selected')
            else:
                label = u''

            html = h.radio_button(self.name, value=self.value, **kwargs)
            html += h.label(label)

            return ''.join(html)

    jq_options.update(filter_by=filter_by, show_input=False)

    return renderers.jQueryFieldRenderer('autocomplete_relation', renderer=Renderer, **jq_options)
Exemplo n.º 2
0
def PyramidAutocompleteFieldRenderer(filter_by='id', renderer=fields.IntegerFieldRenderer, **jq_options):
    """Use http://docs.jquery.com/UI/Autocomplete with pyramid"""

    class Renderer(renderer):

        def __init__(self, *args, **kwargs):
            super(Renderer, self).__init__(*args, **kwargs)
            self.field.render_opts['options'] = []

        def update_options(self, options, kwargs):
            autocomplete_model = self.field.relation_type().__name__
            route_url = self.request.route_url(self.request.route_name,
                                               traverse=(autocomplete_model,'autocomplete'))
            kwargs['source'] = route_url

        def render(self, **kwargs):
            filter_by = self.jq_options.get('filter_by')
            if self.raw_value:
                label = getattr(self.raw_value, filter_by, u'Not selected')
            else:
                label = u''

            html = h.radio_button(self.name, value=self.value, **kwargs)
            html += h.label(label)

            return ''.join(html)

    jq_options.update(filter_by=filter_by, show_input=False)

    return jQueryFieldRenderer('pyramidautocomplete', renderer=Renderer, **jq_options)
Exemplo n.º 3
0
def RelationRenderer(renderer=fields.SelectFieldRenderer, **jq_options):
    class Renderer(renderer):
        def render(self, *args, **kwargs):
            html = super(Renderer, self).render(*args, **kwargs)
            pk = fields._pk(self.field.model)
            model_name = self.field.parent.model.__class__.__name__
            request = self.request
            if pk:
                field_url = request.fa_url(model_name, 'xhr', pk, field=self.field.key)
            else:
                field_url = request.fa_url(model_name, 'xhr', field=self.field.key)
            fk_class = self.field.relation_type()
            model_name = fk_class.__name__
            new_url = request.fa_url(model_name, 'xhr', 'new')
            html += literal('<button class="new_relation_item" alt="%s" href="%s">New %s</button>' % (
                                                field_url, new_url, model_name))
            return html
    return renderers.jQueryFieldRenderer('relation', show_input=True, renderer=Renderer, **jq_options)
Exemplo n.º 4
0
def AutocompleteRelationRenderer(filter_by='id',
                                 renderer=fields.IntegerFieldRenderer,
                                 **jq_options):
    """Use http://docs.jquery.com/UI/Autocomplete with pyramid"""
    class Renderer(renderer):
        def __init__(self, *args, **kwargs):
            super(Renderer, self).__init__(*args, **kwargs)
            self.field.render_opts['options'] = []

        def update_options(self, options, kwargs):
            kwargs['source'] = self.request.fa_url(
                self.field.relation_type().__name__, 'autocomplete')

        def render(self, **kwargs):
            fanstatic_resources.autocomplete.need()
            filter_by = self.jq_options.get('filter_by')
            if self.raw_value:
                label = getattr(self.raw_value, filter_by, u'Not selected')
            else:
                label = u''

            radio = h.radio_button(self.name, value=self.value, **kwargs)
            radio += h.literal('&nbsp;')
            radio += h.content_tag('span', label)
            children = h.content_tag("span", radio, class_="add-on")
            html = h.content_tag("div", children, class_="input-prepend")
            return ''.join(html)

        def _serialized_value(self):
            try:
                return super(Renderer, self)._serialized_value()
            except FieldNotFoundError:
                return None

    jq_options.update(filter_by=filter_by, show_input=True)

    return renderers.jQueryFieldRenderer('bootstrap_autocomplete_relation',
                                         renderer=Renderer,
                                         **jq_options)
Exemplo n.º 5
0
def AutocompleteRelationRenderer(filter_by='id', renderer=fields.IntegerFieldRenderer, **jq_options):
    """Use http://docs.jquery.com/UI/Autocomplete with pyramid"""

    class Renderer(renderer):

        def __init__(self, *args, **kwargs):
            super(Renderer, self).__init__(*args, **kwargs)
            self.field.render_opts['options'] = []

        def update_options(self, options, kwargs):
            kwargs['source'] = self.request.fa_url(
                    self.field.relation_type().__name__, 'autocomplete')

        def render(self, **kwargs):
            fanstatic_resources.autocomplete.need()
            filter_by = self.jq_options.get('filter_by')
            if self.raw_value:
                label = getattr(self.raw_value, filter_by, u'Not selected')
            else:
                label = u''

            radio = h.radio_button(self.name, value=self.value, **kwargs)
            radio += h.literal('&nbsp;')
            radio += h.content_tag('span', label)
            children = h.content_tag("span", radio, class_="add-on")
            html = h.content_tag("div", children, class_="input-prepend")
            return ''.join(html)

        def _serialized_value(self):
            try:
                return super(Renderer,self)._serialized_value()
            except FieldNotFoundError:
                return None

    jq_options.update(filter_by=filter_by, show_input=True)

    return renderers.jQueryFieldRenderer('bootstrap_autocomplete_relation', renderer=Renderer, **jq_options)