Example #1
0
    def render(self, name, value, attrs=None, renderer=None):
        """
        Renders this field widget as HTML
        :param name: Field input name
        :param value: Field input value
        :param attrs: Field input attributes
        :return: An HTML string representing this widget
        """

        if value is None:
            value = ""

        img_thumb = "Det er ikke valgt noe bilde."

        attrs = self.build_attrs(self.attrs, attrs)
        final_attrs = self.build_attrs(attrs, {
            "type": self.input_type,
            "name": name
        })
        if value != "":
            # Only add the value attribute if the value is non-empty
            final_attrs["value"] = force_str(self.format_value(value))
            img = ResponsiveImage.objects.get(pk=value)
            img_thumb = format_html(
                '<img src="{}" alt title="{}"/>',
                settings.MEDIA_URL + str(img.thumbnail),
                str(img.name),
                encoding="utf-8",
            )

        upload_url = reverse_lazy("gallery_dashboard:upload")

        return format_html(WIDGET_STRING, flatatt(final_attrs), img_thumb,
                           upload_url)
Example #2
0
    def render(self, name, value, attrs=None):
        """
        Renders this widget
        :param name: Name attribute of the input type
        :param value: Value, if any
        :param attrs: Dictionary of additional attributes and their values
        :return: HTML
        """

        if value is None:
            value = ''

        attrs = self.build_attrs(self.attrs, attrs)
        final_attrs = self.build_attrs(attrs, {
            'type': self.input_type,
            'name': name
        })
        if value != '':
            final_attrs['value'] = format_html(
                'value="{}"', force_text(self._format_value(value)))
        else:
            final_attrs['value'] = ''

        # Kept for backwards compatibility with existing forms.
        final_attrs['placeholder'] = 'Vennligst velg en dato ...'
        if attrs.get('placeholder', False):
            # Update the placeholder text if supplied.
            final_attrs['placeholder'] = force_text(attrs.get('placeholder'))

        return format_html(DATEPICKER_WIDGET_STRING,
                           id=force_text(final_attrs['id']),
                           name=force_text(final_attrs['name']),
                           placeholder=force_text(final_attrs['placeholder']),
                           value=final_attrs['value'])
Example #3
0
    def render(self, name, value, attrs=None, renderer=None):
        """
        Renders this widget
        :param name: Name attribute of the input type
        :param value: Value, if any
        :param attrs: Dictionary of additional attributes and their values
        :return: HTML
        """

        if value is None:
            value = ""

        attrs = self.build_attrs(self.attrs, attrs)
        final_attrs = self.build_attrs(attrs, {"type": self.input_type, "name": name})
        if value != "":
            final_attrs["value"] = format_html(
                'value="{}"', force_str(self.format_value(value))
            )
        else:
            final_attrs["value"] = ""

        # Kept for backwards compatibility with existing forms.
        final_attrs["placeholder"] = "Vennligst velg en dato ..."
        if attrs.get("placeholder", False):
            # Update the placeholder text if supplied.
            final_attrs["placeholder"] = force_str(attrs.get("placeholder"))

        return format_html(
            DATEPICKER_WIDGET_STRING,
            id=force_str(final_attrs["id"]),
            name=force_str(final_attrs["name"]),
            placeholder=force_str(final_attrs["placeholder"]),
            value=final_attrs["value"],
        )
Example #4
0
    def render(name, value=None, attrs=None, renderer=None):
        if not isinstance(value, (list, tuple)):
            value = [value]
        values = value
        widget_renderer = partial(
            render_func,
            renderer=renderer) if renderer else partial(render_func)
        # The tag is a marker for our javascript to reshuffle the elements. This is because some widgets have complex rendering with multiple fields
        pieces = [
            '<{tag} {multi_attr}>{widget}</{tag}>'.format(
                tag='div',
                multi_attr=config.WOOEY_MULTI_WIDGET_ATTR,
                widget=widget_renderer(name, value, attrs)) for value in values
        ]

        # we add a final piece that is our button to click for adding. It's useful to have it here instead of the template so we don't
        # have to reverse-engineer who goes with what

        # build the attribute dict
        data_attrs = flatatt(
            appender_data_dict if appender_data_dict is not None else {})
        pieces.append(
            format_html(
                '<a href="#{anchor}"{data}><span class="glyphicon glyphicon-plus"></span></a>',
                anchor=config.WOOEY_MULTI_WIDGET_ANCHOR,
                data=data_attrs))
        return mark_safe('\n'.join(pieces))
Example #5
0
 def as_divs(self):
     if not self:
         return ''
     return format_html(
         '<div class="{}">{}</div>', self.error_class,
         format_html_join('', '<div class="error">* {}</div>',
                          ((e, ) for e in self)))
Example #6
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = ''
     attrs = attrs or {}
     attrs.setdefault('mode', self.mode)
     attrs.setdefault('font-size', 15)
     final_attrs = self.build_attrs(attrs, name=name)
     final_attrs.pop('rows', None)
     return format_html('<ace-editor{}>\r\n{}</ace-editor>',
                        flatatt(final_attrs), force_text(value))
Example #7
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = ''
     attrs = attrs or {}
     attrs.setdefault('mode', self.mode)
     attrs.setdefault('font-size', 15)
     final_attrs = self.build_attrs(attrs, name=name)
     final_attrs.pop('rows', None)
     return format_html('<ace-editor{}>\r\n{}</ace-editor>',
                        flatatt(final_attrs),
                        force_text(value))
Example #8
0
 def errors_as_p(self):
     if not self:
         return ''
     return format_html(''.join(
         [f'<p style="color: red">{e}</p>' for e in self]))
Example #9
0
 def render(self, name, value, attrs=None):
     return format_html('<div class="g-recaptcha" data-sitekey="{}"></div>'.format(settings.RECAPTCHA_SITE_KEY))
Example #10
0
 def render(self, name, value, attrs=None):
     return format_html(
         '<div class="g-recaptcha" data-sitekey="{}"></div>'.format(
             settings.RECAPTCHA_SITE_KEY))