admin.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import autocomplete_light
  4. from django.contrib import admin
  5. from django.contrib import messages
  6. from .models import MaillingList
  7. class MaillingListAdmin(admin.ModelAdmin):
  8. list_display = ('email', 'verbose_name')
  9. actions = ['sync_to_server']
  10. def sync_to_server(self, request, queryset):
  11. for _list in queryset.all():
  12. try:
  13. _list.sync_to_list_server()
  14. except Exception as e:
  15. messages.error(
  16. request,
  17. 'Impossible de synchroniser la liste {} : "{}"'.format(
  18. _list, e))
  19. else:
  20. messages.success(
  21. request,
  22. 'Liste {} synchronisée vers le serveur'.format(
  23. _list.email))
  24. sync_to_server.short_description = (
  25. 'Synchroniser les listes sélectionnées vers le serveur')
  26. form = autocomplete_light.modelform_factory(
  27. MaillingList,
  28. fields='__all__',
  29. )
  30. admin.site.register(MaillingList, MaillingListAdmin)