mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-11 05:20:16 +02:00
Correct migration syntax.
This commit is contained in:
parent
e15d79b834
commit
ab10f062f7
@ -24,7 +24,7 @@ def create_member_state(apps, schema_editor):
|
|||||||
try:
|
try:
|
||||||
# move group permissions to state
|
# move group permissions to state
|
||||||
g = Group.objects.get(name=member_state_name)
|
g = Group.objects.get(name=member_state_name)
|
||||||
s.permissions.add(g.permissions.all())
|
[s.permissions.add(p.pk) for p in g.permissions.all()]
|
||||||
g.delete()
|
g.delete()
|
||||||
except Group.DoesNotExist:
|
except Group.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
@ -32,8 +32,8 @@ def create_member_state(apps, schema_editor):
|
|||||||
# auto-populate member IDs
|
# auto-populate member IDs
|
||||||
CORP_IDS = getattr(settings, 'CORP_IDS', [])
|
CORP_IDS = getattr(settings, 'CORP_IDS', [])
|
||||||
ALLIANCE_IDS = getattr(settings, 'ALLIANCE_IDS', [])
|
ALLIANCE_IDS = getattr(settings, 'ALLIANCE_IDS', [])
|
||||||
s.member_corporations.add(EveCorporationInfo.objects.filter(corporation_id__in=CORP_IDS))
|
[s.member_corporations.add(c.pk) for c in EveCorporationInfo.objects.filter(corporation_id__in=CORP_IDS)]
|
||||||
s.member_alliances.add(EveAllianceInfo.objects.filter(alliance_id__in=ALLIANCE_IDS))
|
[s.member_alliances.add(a.pk) for a in EveAllianceInfo.objects.filter(alliance_id__in=ALLIANCE_IDS)]
|
||||||
|
|
||||||
|
|
||||||
def create_member_group(apps, schema_editor):
|
def create_member_group(apps, schema_editor):
|
||||||
@ -45,11 +45,11 @@ def create_member_group(apps, schema_editor):
|
|||||||
try:
|
try:
|
||||||
# move permissions back
|
# move permissions back
|
||||||
state = State.objects.get(name=member_state_name)
|
state = State.objects.get(name=member_state_name)
|
||||||
g.permissions.add(state.permissions.all())
|
[g.permissions.add(p.pk) for p in state.permissions.all()]
|
||||||
|
|
||||||
# move users back
|
# move users back
|
||||||
for profile in state.userprofile_set.all().select_related('user'):
|
for profile in state.userprofile_set.all().select_related('user'):
|
||||||
profile.user.groups.add(g)
|
profile.user.groups.add(g.pk)
|
||||||
except State.DoesNotExist:
|
except State.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ def create_blue_state(apps, schema_editor):
|
|||||||
try:
|
try:
|
||||||
# move group permissions to state
|
# move group permissions to state
|
||||||
g = Group.objects.get(name=blue_state_name)
|
g = Group.objects.get(name=blue_state_name)
|
||||||
s.permissions.add(g.permissions.all())
|
[s.permissions.add(p.pk) for p in g.permissions.all()]
|
||||||
g.permissions.clear()
|
g.permissions.clear()
|
||||||
except Group.DoesNotExist:
|
except Group.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
@ -73,8 +73,8 @@ def create_blue_state(apps, schema_editor):
|
|||||||
# auto-populate blue member IDs
|
# auto-populate blue member IDs
|
||||||
BLUE_CORP_IDS = getattr(settings, 'BLUE_CORP_IDS', [])
|
BLUE_CORP_IDS = getattr(settings, 'BLUE_CORP_IDS', [])
|
||||||
BLUE_ALLIANCE_IDS = getattr(settings, 'BLUE_ALLIANCE_IDS', [])
|
BLUE_ALLIANCE_IDS = getattr(settings, 'BLUE_ALLIANCE_IDS', [])
|
||||||
s.member_corporations.add(EveCorporationInfo.objects.filter(corporation_id__in=BLUE_CORP_IDS))
|
[s.member_corporations.add(c.pk) for c in EveCorporationInfo.objects.filter(corporation_id__in=BLUE_CORP_IDS)]
|
||||||
s.member_alliances.add(EveAllianceInfo.objects.filter(alliance_id__in=BLUE_ALLIANCE_IDS))
|
[s.member_alliances.add(a.pk) for a in EveAllianceInfo.objects.filter(alliance_id__in=BLUE_ALLIANCE_IDS)]
|
||||||
|
|
||||||
|
|
||||||
def create_blue_group(apps, schema_editor):
|
def create_blue_group(apps, schema_editor):
|
||||||
@ -86,11 +86,11 @@ def create_blue_group(apps, schema_editor):
|
|||||||
try:
|
try:
|
||||||
# move permissions back
|
# move permissions back
|
||||||
state = State.objects.get(name=blue_state_name)
|
state = State.objects.get(name=blue_state_name)
|
||||||
g.permissions.add(state.permissions.all())
|
[g.permissions.add(p.pk) for p in state.permissions.all()]
|
||||||
|
|
||||||
# move users back
|
# move users back
|
||||||
for profile in state.userprofile_set.all().select_related('user'):
|
for profile in state.userprofile_set.all().select_related('user'):
|
||||||
profile.user.groups.add(g)
|
profile.user.groups.add(g.pk)
|
||||||
except State.DoesNotExist:
|
except State.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -131,9 +131,9 @@ def create_profiles(apps, schema_editor):
|
|||||||
# carry states and mains forward
|
# carry states and mains forward
|
||||||
profile = UserProfile.objects.get_or_create(user=auth.user.pk)
|
profile = UserProfile.objects.get_or_create(user=auth.user.pk)
|
||||||
state = State.objects.get(name=auth.state if auth.state else 'Guest')
|
state = State.objects.get(name=auth.state if auth.state else 'Guest')
|
||||||
profile.state = state
|
profile.state = state.pk
|
||||||
char = EveCharacter.objects.get(character_id=auth.main_char_id)
|
char = EveCharacter.objects.get(character_id=auth.main_char_id)
|
||||||
profile.main_character = char
|
profile.main_character = char.pk
|
||||||
profile.save()
|
profile.save()
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,20 +5,10 @@ from __future__ import unicode_literals
|
|||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
def create_groups(apps, schema_editor):
|
|
||||||
Group = apps.get_model('auth', 'Group')
|
|
||||||
Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP)
|
|
||||||
Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP)
|
|
||||||
|
|
||||||
def reverse(apps, schema_editor):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('groupmanagement', '0002_auto_20160906_2354'),
|
('groupmanagement', '0002_auto_20160906_2354'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = []
|
||||||
migrations.RunPython(create_groups, reverse)
|
|
||||||
]
|
|
||||||
|
@ -12,23 +12,6 @@ import logging
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def add_default_member_permission(apps, schema_editor):
|
|
||||||
for app_config in apps.get_app_configs():
|
|
||||||
app_config.models_module = True
|
|
||||||
create_permissions(app_config, apps=apps, verbosity=0)
|
|
||||||
app_config.models_module = None
|
|
||||||
|
|
||||||
Group = apps.get_model("auth", "Group")
|
|
||||||
Permission = apps.get_model("auth", "Permission")
|
|
||||||
|
|
||||||
try:
|
|
||||||
perm = Permission.objects.get(codename='request_groups', name='Can request non-public groups')
|
|
||||||
group = Group.objects.get(name=getattr(settings, str('DEFAULT_AUTH_GROUP'), 'Member'))
|
|
||||||
group.permissions.add(perm)
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
logger.warning('Failed to add default request_groups permission to Member group')
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@ -40,5 +23,4 @@ class Migration(migrations.Migration):
|
|||||||
name='authgroup',
|
name='authgroup',
|
||||||
options={'permissions': (('request_groups', 'Can request non-public groups'),)},
|
options={'permissions': (('request_groups', 'Can request non-public groups'),)},
|
||||||
),
|
),
|
||||||
migrations.RunPython(add_default_member_permission),
|
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user