Verified Commit 2d34b6fd authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Add OneToOneField from Committee to MailingList instead of contact email string

parent e6db9460
......@@ -35,8 +35,8 @@ class CommitteeAdmin(TranslatedModelAdmin):
search_fields = ('name', 'description')
filter_horizontal = ('permissions',)
fields = ('name', 'description', 'photo', 'permissions',
'since', 'until', 'contact_email', 'wiki_namespace', 'active')
fields = ('name', 'description', 'photo', 'permissions', 'since',
'until', 'contact_mailinglist', 'wiki_namespace', 'active')
def get_queryset(self, request):
qs = super().get_queryset(request)
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-05-19 20:25
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('mailinglists', '0009_auto_20170429_2149'),
('activemembers', '0019_auto_20170227_1632'),
]
operations = [
migrations.RemoveField(
model_name='committee',
name='contact_email',
),
migrations.AddField(
model_name='committee',
name='contact_mailinglist',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='mailinglists.MailingList', verbose_name='contact email address'),
),
]
......@@ -90,7 +90,12 @@ class Committee(models.Model, metaclass=ModelTranslateMeta):
active = models.BooleanField(default=False)
contact_email = models.EmailField(_('contact email address'))
contact_mailinglist = models.OneToOneField(
'mailinglists.MailingList',
verbose_name=_('contact email address'),
null=True,
blank=True,
)
wiki_namespace = models.CharField(
_('Wiki namespace'),
......
......@@ -5,6 +5,7 @@ from django.test import TestCase
from django.utils import timezone
from activemembers.models import Committee, CommitteeMembership, Board
from mailinglists.models import MailingList
from members.models import Member
......@@ -155,6 +156,36 @@ class PermissionsBackendTest(TestCase):
self.assertEqual(set(), u.get_all_permissions())
class CommitteeMailingListTest(TestCase):
fixtures = ['mailinglists.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.testcie1 = Committee.objects.get(pk=1)
cls.testcie2 = Committee.objects.get(pk=2)
cls.mailtest1 = MailingList.objects.get(pk=1)
cls.mailtest2 = MailingList.objects.get(pk=2)
def setUp(self):
self.testcie1.refresh_from_db()
self.testcie2.refresh_from_db()
self.mailtest1.refresh_from_db()
self.mailtest2.refresh_from_db()
def test_one_to_one(self):
self.testcie1.contact_mailinglist = self.mailtest1
self.testcie1.save()
self.testcie2.contact_mailinglist = self.mailtest1
with self.assertRaises(ValidationError):
self.testcie2.full_clean()
self.testcie2.contact_mailinglist = self.mailtest2
self.testcie2.full_clean()
class BoardTest(TestCase):
fixtures = ['committees.json']
......@@ -173,7 +204,6 @@ class BoardTest(TestCase):
b = Board(
name_nl="testbe",
name_en="testbo",
contact_email="test@test.com",
description_nl="descnl",
description_en="descen",
since=timezone.now().date()
......@@ -197,7 +227,6 @@ class BoardTest(TestCase):
b = Board(
name_nl="testbe",
name_en="testbo",
contact_email="test@test.com",
description_nl="descnl",
description_en="descen",
since=timezone.now().date()
......
[
{
"model": "mailinglists.mailinglist",
"pk": 1,
"fields": {
"name": "mailtest1"
}
},
{
"model": "mailinglists.mailinglist",
"pk": 2,
"fields": {
"name": "mailtest2"
}
}
]
Supports Markdown
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