Esempio n. 1
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'])
Esempio n. 2
0
    def render(self, name, value, attrs=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_text(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)
Esempio n. 3
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))
Esempio n. 4
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))