|
@@ -12,14 +12,31 @@ from .models import MaillingList, MaillingListSubscription, SyncCommandError
|
|
|
import coin.members.admin
|
|
|
|
|
|
|
|
|
+class AddMaillingListSubscriptionInline(admin.StackedInline):
|
|
|
+ model = MaillingListSubscription
|
|
|
+ extra = 1
|
|
|
+ max_num = 1
|
|
|
+ fields = ('member', 'maillinglist')
|
|
|
+ verbose_name_plural = "Ajouter un abonnement à la liste mail"
|
|
|
+ verbose_name = "Ajouter un abonnement"
|
|
|
+
|
|
|
+ form = autocomplete_light.modelform_factory(MaillingListSubscription, fields='__all__')
|
|
|
+
|
|
|
+ def get_queryset(self, request):
|
|
|
+ qs = super(AddMaillingListSubscriptionInline, self).get_queryset(request)
|
|
|
+ return qs.none()
|
|
|
+
|
|
|
+ def has_delete_permission(self, request, obj=None):
|
|
|
+ return False
|
|
|
+
|
|
|
+
|
|
|
class MaillingListSubscriptionInline(admin.TabularInline):
|
|
|
model = MaillingListSubscription
|
|
|
- extra = 0
|
|
|
|
|
|
- form = autocomplete_light.modelform_factory(
|
|
|
- MaillingListSubscription,
|
|
|
- fields='__all__',
|
|
|
- )
|
|
|
+ readonly_fields = ('member', 'maillinglist',)
|
|
|
+
|
|
|
+ def has_add_permission(self, request, obj=None):
|
|
|
+ return False
|
|
|
|
|
|
|
|
|
class MaillingListAdmin(admin.ModelAdmin):
|
|
@@ -43,7 +60,7 @@ class MaillingListAdmin(admin.ModelAdmin):
|
|
|
sync_to_server.short_description = (
|
|
|
'Synchroniser les listes sélectionnées vers le serveur')
|
|
|
|
|
|
- inlines = [MaillingListSubscriptionInline,]
|
|
|
+ inlines = [AddMaillingListSubscriptionInline, MaillingListSubscriptionInline,]
|
|
|
|
|
|
def change_view(self, request, object_id, *args, **kwargs):
|
|
|
try:
|
|
@@ -66,7 +83,7 @@ admin.site.register(MaillingList, MaillingListAdmin)
|
|
|
|
|
|
|
|
|
class MemberAdmin(coin.members.admin.MemberAdmin):
|
|
|
- inlines = coin.members.admin.MemberAdmin.inlines + [MaillingListSubscriptionInline]
|
|
|
+ inlines = coin.members.admin.MemberAdmin.inlines + [AddMaillingListSubscriptionInline, MaillingListSubscriptionInline]
|
|
|
|
|
|
def change_view(self, request, *args, **kwargs):
|
|
|
try:
|