Skip to content
Snippets Groups Projects
Verified Commit 8303606d authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

SImplify and fix preference name migration

parent c4d82a12
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ from django.db import migrations ...@@ -2,7 +2,6 @@ from django.db import migrations
from aleksis.apps.ldap.util.ldap_sync import setting_name_from_field from aleksis.apps.ldap.util.ldap_sync import setting_name_from_field
from aleksis.core.models import Person from aleksis.core.models import Person
from django.contrib.sites.models import Site
_preference_suffixes = ["", "_re", "_replace"] _preference_suffixes = ["", "_re", "_replace"]
...@@ -15,26 +14,13 @@ def _setting_name_old(model, field): ...@@ -15,26 +14,13 @@ def _setting_name_old(model, field):
def _migrate_preferences(apps, schema_editor): def _migrate_preferences(apps, schema_editor):
SitePreferenceModel = apps.get_model("core", "SitePreferenceModel") SitePreferenceModel = apps.get_model("core", "SitePreferenceModel")
try:
current_site = Site.objects.get_current()
except Site.DoesNotExist:
# Failing to find a site is not fatal, jsut not migrate
return
for field in Person.syncable_fields(): for field in Person.syncable_fields():
old_setting_name = _setting_name_old(Person, field) old_setting_name = _setting_name_old(Person, field)
setting_name = setting_name_from_field(Person, field) setting_name = setting_name_from_field(Person, field)
for suffix in _preference_suffixes: for suffix in _preference_suffixes:
old_pref_name = old_setting_name + suffix old_pref_name = old_setting_name + suffix
new_pref_name = setting_name + suffix new_pref_name = setting_name + suffix
qs = SitePreferenceModel.objects.filter(instance=current_site, section="ldap", name=old_pref_name) SitePreferenceModel.objects.filter(section="ldap", name=old_pref_name).update(name=new_pref_name)
if qs.exists():
SitePreferenceModel.objects.update_or_create(
instance=current_site,
section="ldap",
name=new_pref_name,
defaults={"raw_value": qs[0].raw_value},
)
class Migration(migrations.Migration): class Migration(migrations.Migration):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment