예제 #1
0
    def test_render_escapes_html(self):
        class StrangeFieldFile(object):
            url = "something?chapter=1&sect=2&copy=3&lang=en"

            def __unicode__(self):
                return u'''something<div onclick="alert('oops')">.jpg'''

        widget = AdminFileWidget()
        field = StrangeFieldFile()
        output = widget.render('myfile', field)
        self.assertFalse(field.url in output)
        self.assertTrue(u'href="something?chapter=1&amp;sect=2&amp;copy=3&amp;lang=en"' in output)
        self.assertFalse(unicode(field) in output)
        self.assertTrue(u'something&lt;div onclick=&quot;alert(&#39;oops&#39;)&quot;&gt;.jpg' in output)
예제 #2
0
파일: tests.py 프로젝트: ssaltzman/POET
    def test_render(self):
        band = models.Band.objects.create(name='Linkin Park')
        album = band.album_set.create(
            name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
        )

        w = AdminFileWidget()
        self.assertEqual(
            conditional_escape(w.render('test', album.cover_art)),
            '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <span class="clearable-file-input"><input type="checkbox" name="test-clear" id="test-clear_id" /> <label for="test-clear_id">Clear</label></span><br />Change: <input type="file" name="test" /></p>' % { 'STORAGE_URL': default_storage.url('') },
        )

        self.assertEqual(
            conditional_escape(w.render('test', SimpleUploadedFile('test', 'content'))),
            '<input type="file" name="test" />',
        )
예제 #3
0
    def test_render(self):
        band = models.Band.objects.create(name='Linkin Park')
        album = band.album_set.create(
            name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
        )

        w = AdminFileWidget()
        self.assertEqual(
            conditional_escape(w.render('test', album.cover_art)),
            '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <span class="clearable-file-input"><input type="checkbox" name="test-clear" id="test-clear_id" /> <label for="test-clear_id">Clear</label></span><br />Change: <input type="file" name="test" /></p>' % { 'STORAGE_URL': default_storage.url('') },
        )

        self.assertEqual(
            conditional_escape(w.render('test', SimpleUploadedFile('test', 'content'))),
            '<input type="file" name="test" />',
        )
예제 #4
0
    def __init__(self, attrs=None):

        widgets = (
            Select(),
            AdminFileWidget(),
        )
        super(FileSelectOrUploadWidget, self).__init__(widgets, attrs)
예제 #5
0
    def _construct_form(self, i, **kwargs):
        form = super(SponsorBenefitsInlineFormSet,
                     self)._construct_form(i, **kwargs)

        # only include the relevant data fields for this benefit type
        fields = form.instance.data_fields()
        form.fields = dict(
            (k, v) for (k, v) in form.fields.items() if k in fields + ["id"])

        for field in fields:
            # don't need a label, the form template will label it
            # with the benefit name
            form.fields[field].label = ""

            # provide word limit as help_text
            if (form.instance.benefit.type == "text"
                    and form.instance.max_words):
                form.fields[field].help_text = (_("maximum %s words") %
                                                form.instance.max_words)

            # use admin file widget that shows currently uploaded file
            if field == "upload":
                form.fields[field].widget = AdminFileWidget()

        return form
예제 #6
0
파일: forms.py 프로젝트: jasonamyers/pytn
 class Meta:
     model = Sticker
     fields = ["title", "description", "upload"]
     widgets = {
         "description": MarkItUpWidget(),
         "upload": AdminFileWidget(),
     }
예제 #7
0
    def test_render(self):
        band = models.Band.objects.create(name='Linkin Park')
        album = band.album_set.create(
            name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
        )

        w = AdminFileWidget()
        self.assertEqual(
            conditional_escape(w.render('test', album.cover_art)),
            'Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <br />Change: <input type="file" name="test" />' % {'STORAGE_URL': default_storage.url('')},
        )

        self.assertEqual(
            conditional_escape(w.render('test', SimpleUploadedFile('test', 'content'))),
            '<input type="file" name="test" />',
        )
예제 #8
0
    def test_render(self):
        band = models.Band.objects.create(name='Linkin Park')
        album = band.album_set.create(
            name='Hybrid Theory', cover_art=r'albums\hybrid_theory.jpg'
        )

        w = AdminFileWidget()
        self.assertEqual(
            conditional_escape(w.render('test', album.cover_art)),
            'Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <br />Change: <input type="file" name="test" />' % {'STORAGE_URL': default_storage.url('')},
        )

        self.assertEqual(
            conditional_escape(w.render('test', SimpleUploadedFile('test', 'content'))),
            '<input type="file" name="test" />',
        )
예제 #9
0
 def render(self, name, value, attrs, width, height):
     result = ''
     if value and hasattr(value, 'url') and not value.url.startswith(
             os.path.join(settings.MEDIA_URL, 'standard%3A')):
         result = ('<a href="{URL}" target="_blank">'
                   '<img src="{URL}" width="{WIDTH}" height="{HEIGHT}">'
                   '</a>'.format(URL=value.url, WIDTH=width, HEIGHT=height))
     # Call super class and return results
     result += AdminFileWidget.render(self, name, value, attrs)
     return mark_safe(result)
예제 #10
0
 class Meta:
     model = NamedReaction
     fields = [
         'Name', 'Functional_Group', 'Product', 'URL', 'Reactants',
         'ByProducts', 'Heat', 'AcidBase', 'Catalyst', 'Solvent', 'Image'
     ]
     widgets = {
         'Reactants': FilteredSelectMultiple('Reactants', False),
         'ByProducts': FilteredSelectMultiple('By Products', False),
         'Image': AdminFileWidget(),
     }
예제 #11
0
 def render(self, name, value, attrs=None, renderer=None):
     output = []
     try:
         Image.open(value)
     except AttributeError:
         html = ''
     except FileNotFoundError:
         return Textarea(attrs={'cols': 80, 'rows': 1}).render(name, value)
     except UnidentifiedImageError:
         html = u'<a href="{0}{1}" target="_blank">{1}</a>'
     else:
         html = u'<a href="{0}{1}" target="_blank"><img src="{0}{1}" alt="{1}" height="150"  style="object-fit: cover;"/></a>'  # noqa: E501
     output.append(html.format(settings.MEDIA_URL, value))
     output.append(AdminFileWidget().render(name, value, attrs, renderer))
     return mark_safe(u''.join(output))
예제 #12
0
    def __init__(self, *args, **kwargs):
        super(InformeSemestralPublicoForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.form_class = 'form-horizontal'

        self.helper.label_class = 'col-sm-2'
        self.helper.field_class = 'col-sm-9'

        self.helper.form_tag = False

        self.fields['fotos'].widget = AdminFileWidget()

        self.helper.layout = Layout(
            Fieldset(
                'Datos del Proyecto',
                Field('nombre_proyecto',
                      css_class='input-sm',
                      placeholder='nombre del proyecto'),
                Field('persona',
                      css_class='input-sm',
                      placeholder='persona encargada del proyecto'),
                Field('email', css_class='input-sm'),
                Field('telefono', css_class='input-sm'),
                Field('depto', css_class='input-sm'),
                Field('municipio', css_class='input-sm'),
                Field('direccion',
                      css_class="input-xlarge",
                      rows="2",
                      placeholder='dirección del proyecto'),
                Field('region', css_class='input-sm'),
            ),
            Fieldset(
                'Datos del Informe',
                Field('miembros_actuales',
                      css_class='input-sm',
                      placeholder='miembros actuales'),
                Field('nuevos_miembros',
                      css_class='input-sm',
                      placeholder='miembros nuevos'),
                Field('conversiones', css_class='input-sm'),
                Field('bautismos_nuevos', css_class='input-sm'),
                Field('no_bautismos', css_class='input-xlarge', rows="2"),
                Field('asistencia_general',
                      css_class="input-sm",
                      placeholder='asistencia general'),
            ),
            MultiField(
                '<b>Plantación*</b>',
                Div(
                    HTML(
                        u'<p class="help-block">Cuantos proyectos misioneros o iglesias hijas fueron plantadas desde el momento de la dedicación, si no hubo, de click en  <i class="fa fa-times"></i></p>'
                    ),
                    PrependedText('plantacion_nombre_1',
                                  "<i class='fa fa-times ninguno-btn'></i>",
                                  css_class="input-sm plantacion-field",
                                  placeholder="nombre"),
                    Field('plantacion_lugar_1',
                          css_class='input-sm',
                          placeholder="lugar"),
                    Field('plantacion_fecha_1',
                          css_class='input-sm',
                          placeholder="mes/año"),
                    css_class='col-sm-11 informe-semestral-plantacion clearfix',
                ),
                Div(
                    PrependedText('plantacion_nombre_2',
                                  "<i class='fa fa-times ninguno-btn' ></i>",
                                  css_class="input-sm",
                                  placeholder="nombre"),
                    Field('plantacion_lugar_2',
                          css_class='input-sm',
                          placeholder="lugar"),
                    Field('plantacion_fecha_2',
                          css_class='input-sm',
                          placeholder="mes/año"),
                    css_class='col-sm-11 informe-semestral-plantacion clearfix',
                ),
                Div(
                    PrependedText('plantacion_nombre_3',
                                  "<i class='fa fa-times ninguno-btn' ></i>",
                                  css_class="input-sm",
                                  placeholder="nombre"),
                    Field('plantacion_lugar_3',
                          css_class='input-sm',
                          placeholder="lugar"),
                    Field('plantacion_fecha_3',
                          css_class='input-sm',
                          placeholder="mes/año"),
                    css_class='col-sm-11 informe-semestral-plantacion clearfix',
                )),
            Field('grupos_vida',
                  css_class='input-sm',
                  placeholder='grupos de vida'),
            Field('asistencia_grupos', css_class='input-sm'),
            Field('ofrendas', css_class='input-sm'),
            Field('peticiones_oracion', css_class="input-xlarge", rows="3"),
            Field('testimonios', css_class="input-xlarge", rows="3"),
            Field('ministerio_ninos', css_class="input-xlarge", rows="3"),
            Field('uso_local', css_class="input-xlarge", rows="3"),
            'fotos',
        )
예제 #13
0
    class Meta:
        from application_lists import TECH_OPTIONS
        model = Application
        exclude = ['user', 'deleted', 'score', 'reimbursement',
                   'submitted']  # use all fields except for these
        labels = {
            'school': 'School or University',
            "grad_date": 'Expected graduation date',
            'birthday': 'Date of birth',
            'is_high_school': 'Are you in high school?',
            'github': '',
            'devpost': '',
            'personal_website': '',
            'cortex': '',
            'passionate':
            'What\'s something that you made that you\'re proud of? It doesn\'t have to be a hack. (150 words max)',
            'coolest_thing':
            'What would you build if you had access to all the resources you needed? (150 words max)',
            'other_info': 'Anything else you want to tell us?',
            'num_hackathons':
            'How many hackathons have you attended? (Put 0 if this is your first!)',
            'can_pay': 'How much of the travel costs can you pay?',
            'mentoring': 'Are you interested in mentoring other hackers?',
            'needs_reimbursement':
            'Will you be needing travel reimbursement to attend MHacks?',
            'from_city': 'Which city will you be traveling from?',
            'from_state': 'Which state will you be traveling from?'
        }

        widgets = {
            "grad_date":
            forms.TextInput(attrs={
                'placeholder': 'DD/MM/YYYY',
                'class': 'form-control input-md'
            }),
            'cortex':
            ArrayFieldSelectMultiple(
                attrs={'class': 'checkbox-inline checkbox-style'},
                choices=TECH_OPTIONS),
            'birthday':
            forms.TextInput(attrs={
                'placeholder': 'DD/MM/YYYY',
                'class': 'form-control input-md'
            }),
            'school':
            forms.TextInput(
                attrs={
                    'placeholder': 'University of ...',
                    'class': 'form-control input-md'
                }),
            'major':
            forms.Select(attrs={'class': 'select_style'}),
            'gender':
            forms.Select(attrs={'class': 'select_style'}),
            'race':
            forms.Select(attrs={'class': 'select_style'}),
            'github':
            forms.TextInput(attrs={
                'placeholder': 'Github',
                'class': 'form-control input-md'
            }),
            'devpost':
            forms.TextInput(attrs={
                'placeholder': 'Devpost',
                'class': 'form-control input-md'
            }),
            'personal_website':
            forms.TextInput(
                attrs={
                    'placeholder': 'Personal Website',
                    'class': 'form-control input-md'
                }),
            'other_info':
            forms.Textarea(attrs={'class': 'textfield form-control'}),
            'coolest_thing':
            forms.Textarea(attrs={'class': 'textfield form-control'}),
            'passionate':
            forms.Textarea(attrs={'class': 'textfield form-control'}),
            'resume':
            AdminFileWidget(attrs={'class': 'input-md form-control'})
        }