Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-LDAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mike Gabriel
AlekSIS-App-LDAP
Commits
8303606d
Verified
Commit
8303606d
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
SImplify and fix preference name migration
parent
c4d82a12
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/ldap/migrations/0001_preferences.py
+1
-15
1 addition, 15 deletions
aleksis/apps/ldap/migrations/0001_preferences.py
with
1 addition
and
15 deletions
aleksis/apps/ldap/migrations/0001_preferences.py
+
1
−
15
View file @
8303606d
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment