|
2 | 2 | from django.forms import FileInput
|
3 | 3 |
|
4 | 4 |
|
5 |
| -class SimpleImageWidget(FileInput): |
| 5 | +class PreviewImageWidget(FileInput): |
6 | 6 | """
|
7 |
| - Autor: Milton Lenis |
8 |
| - Fecha: Abril 2 2017 |
9 |
| - Widget para archivos de tipo imágen para mejorar un poco la apariencia visual de manera sencilla. |
| 7 | + Widget for displaying a image-preview in file fields. |
10 | 8 | """
|
| 9 | + |
11 | 10 | def __init__(self, *args, **kwargs):
|
12 | 11 | """
|
13 |
| - Autor: Milton Lenis |
14 |
| - Fecha: Abril 2 2017 |
15 |
| - Método constructor para agregar el atributo 'simple_image_widget' al campo y poder activarlo desde javascript |
16 |
| - :param args: Argumentos de la función |
17 |
| - :param kwargs: Keyword arguments de la función |
| 12 | + Adds a 'preview_image_widget' attr for the input |
18 | 13 | """
|
19 | 14 | kwargs['attrs'] = {
|
20 |
| - 'simple_image_widget': 1 |
| 15 | + 'preview_image_widget': 1 |
21 | 16 | }
|
22 |
| - super(SimpleImageWidget, self).__init__(*args, **kwargs) |
| 17 | + super(PreviewImageWidget, self).__init__(*args, **kwargs) |
23 | 18 |
|
24 | 19 | def render(self, name, value, attrs=None):
|
25 | 20 | """
|
26 |
| - Autor: Milton Lenis |
27 |
| - Fecha: Abril 2 2017 |
28 |
| - Se sobrecarga el método render para agregar la imágen a la vista previa al editar en caso de que tenga un valor |
29 |
| - almacenado |
30 |
| - :param name: |
31 |
| - :param value: |
32 |
| - :param attrs: |
33 |
| - :return: |
| 21 | + Adds the previous value of the file to an attr, if there is any, for preview. |
34 | 22 | """
|
35 | 23 | if value:
|
36 | 24 | preview = {"data-preview": settings.MEDIA_URL + str(value)}
|
37 |
| - if attrs: |
38 |
| - attrs.update(preview) |
39 |
| - else: |
40 |
| - attrs = preview |
41 |
| - return super(SimpleImageWidget, self).render(name, value, attrs=attrs) |
| 25 | + if not attrs: |
| 26 | + attrs = {} |
| 27 | + attrs.update(preview) |
| 28 | + return super(PreviewImageWidget, self).render(name, value, attrs=attrs) |
42 | 29 |
|
43 | 30 | class Media:
|
44 | 31 | css = {
|
45 |
| - 'all': ('plugins/simple_image_widget/simple_image_widget.css',) |
| 32 | + 'all': ('plugins/preview_image_widget/preview_image_widget.css',) |
46 | 33 | }
|
47 |
| - js = ('plugins/simple_image_widget/simple_image_widget.js',) |
| 34 | + js = ('plugins/preview_image_widget/preview_image_widget.js',) |
0 commit comments