-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #625 from johannaengland/notificationprofile/copy-…
…filter-str-to-filter Copy content of filter_string to filter
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/argus/notificationprofile/migrations/0012_copy_filter_string_to_filter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
|
||
from django.db import migrations | ||
|
||
|
||
def copy_filter_string_to_filter(apps, schema_editor): | ||
Filter = apps.get_model("argus_notificationprofile", "Filter") | ||
for f in Filter.objects.all(): | ||
changed = False | ||
filter_json = json.loads(f.filter_string) | ||
for key in filter_json.keys(): | ||
if filter_json[key] and (f.filter.get(key, None) != filter_json[key]): | ||
f.filter[key] = filter_json[key] | ||
changed = True | ||
if changed: | ||
f.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("argus_notificationprofile", "0011_media_installed_alter_media_slug_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(copy_filter_string_to_filter, migrations.RunPython.noop), | ||
] |