Commit 0c0dedf58404aef7023abee3050398787f487bfa
1 parent
0ef38d0b
Exists in
master
and in
9 other branches
Create relation only if it doesnt exist
Signed-off-by: Carlos Coelho <carlos@pencillabs.com>
Showing
2 changed files
with
19 additions
and
19 deletions
Show diff stats
src/colab-spb-plugin/src/colab_spb/migrations/0002_auto_20160229_1735.py
... | ... | @@ -3,29 +3,29 @@ from __future__ import unicode_literals |
3 | 3 | |
4 | 4 | from django.db import models, migrations |
5 | 5 | |
6 | + | |
6 | 7 | class Migration(migrations.Migration): |
7 | 8 | |
8 | 9 | def match_communities_mailinglists(apps, schema_editor): |
9 | - NoosferoCommunity = apps.get_model("colab_noosfero", | |
10 | - "NoosferoCommunity") | |
10 | + NoosferoCommunity = apps.get_model( | |
11 | + "colab_noosfero", "NoosferoCommunity" | |
12 | + ) | |
11 | 13 | MailingList = apps.get_model("super_archives", "MailingList") |
12 | - CommunityAssociations = apps.get_model("colab_spb", | |
13 | - "CommunityAssociations") | |
14 | + Associations = apps.get_model("colab_spb", "CommunityAssociations") | |
14 | 15 | |
15 | 16 | for community in NoosferoCommunity.objects.all(): |
16 | 17 | try: |
17 | - maillist = MailingList.objects.get(name__iexact=community.identifier) | |
18 | - | |
19 | - community_association = CommunityAssociations() | |
20 | - | |
21 | - community_association.community = community | |
22 | - community_association.mail_list = maillist | |
23 | - | |
24 | - community_association.save() | |
18 | + maillist = MailingList.objects.get( | |
19 | + name__iexact=community.identifier | |
20 | + ) | |
21 | + | |
22 | + association = Associations.objects.get_or_create( | |
23 | + mail_list=maillist, | |
24 | + community=community | |
25 | + ) | |
25 | 26 | except MailingList.DoesNotExist: |
26 | 27 | continue |
27 | 28 | |
28 | - | |
29 | 29 | dependencies = [ |
30 | 30 | ('colab_spb', '0001_initial'), |
31 | 31 | ] | ... | ... |
src/colab-spb-plugin/src/colab_spb/migrations/0003_auto_20160229_1804.py
... | ... | @@ -8,21 +8,21 @@ class Migration(migrations.Migration): |
8 | 8 | |
9 | 9 | def associate_communities_groups(apps, schema_editor): |
10 | 10 | GitlabGroup = models.get_model("colab_gitlab", "GitlabGroup") |
11 | - NoosferoCommunity = models.get_model("colab_noosfero", | |
12 | - "NoosferoCommunity") | |
13 | - CommunityAssociations = models.get_model("colab_spb", | |
14 | - "CommunityAssociations") | |
11 | + CommunityAssociations = models.get_model( | |
12 | + "colab_spb", "CommunityAssociations" | |
13 | + ) | |
15 | 14 | |
16 | 15 | for community_association in CommunityAssociations.objects.all(): |
17 | 16 | try: |
18 | 17 | community = community_association.community |
19 | - group = GitlabGroup.objects.get(name__iexact=community.identifier) | |
18 | + group = GitlabGroup.objects.get( | |
19 | + name__iexact=community.identifier | |
20 | + ) | |
20 | 21 | community_association.group = group |
21 | 22 | community_association.save() |
22 | 23 | except GitlabGroup.DoesNotExist: |
23 | 24 | continue |
24 | 25 | |
25 | - | |
26 | 26 | dependencies = [ |
27 | 27 | ('colab_spb', '0002_auto_20160229_1735'), |
28 | 28 | ] | ... | ... |