Commit 0e032cbe authored by SimonBoulier's avatar SimonBoulier

Form to add a mailling list subscription in the member/mailling list admin.

parent 2b59d862
......@@ -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:
......
......@@ -24,6 +24,8 @@ class MaillingListSubscription(models.Model):
verbose_name_plural = 'abonnements à des listes mail'
unique_together = ('member', 'maillinglist')
def __str__(self):
return str(self.maillinglist)
class MaillingList(models.Model):
short_name = models.CharField(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment