Browse Source

Exibindo um thumbnail da foto que o servidor colocar no cadastro.

diagnosticos
Gilson Filho 13 years ago
parent
commit
6b31b9a931
  1. 9
      sigi/apps/servidores/admin.py
  2. 15
      sigi/apps/utils/admin_widgets.py

9
sigi/apps/servidores/admin.py

@ -2,6 +2,8 @@
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.forms import UserCreationForm
from django.contrib.contenttypes import generic from django.contrib.contenttypes import generic
from sigi.apps.utils.admin_widgets import AdminImageWidget
from sigi.apps.servidores.models import Servidor, Funcao, Licenca, Ferias from sigi.apps.servidores.models import Servidor, Funcao, Licenca, Ferias
from sigi.apps.contatos.models import Endereco, Telefone from sigi.apps.contatos.models import Endereco, Telefone
@ -77,6 +79,13 @@ class ServidorAdmin(admin.ModelAdmin):
#}), #}),
) )
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'foto':
request = kwargs.pop("request", None)
kwargs['widget'] = AdminImageWidget
return db_field.formfield(**kwargs)
return super(ServidorAdmin,self).formfield_for_dbfield(db_field, **kwargs)
admin.site.register(Servidor, ServidorAdmin) admin.site.register(Servidor, ServidorAdmin)
admin.site.register(Funcao, FuncaoAdmin) admin.site.register(Funcao, FuncaoAdmin)
admin.site.register(Ferias, FeriasAdmin) admin.site.register(Ferias, FeriasAdmin)

15
sigi/apps/utils/admin_widgets.py

@ -0,0 +1,15 @@
from django.contrib.admin.widgets import AdminFileWidget
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
class AdminImageWidget(AdminFileWidget):
def render(self, name, value, attrs=None):
output = []
if value and getattr(value, "url", None):
image_url = value.url
file_name=str(value)
output.append(
u' <a href="%s" target="_blank"><img src="%s" width="200" alt="%s"/></a> <br/> %s' % \
(image_url, image_url, file_name, _('Change:')))
output.append(super(AdminFileWidget, self).render(name, value, attrs))
return mark_safe(u''.join(output))
Loading…
Cancel
Save