-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import config waffles to django waffles 🧇
- Loading branch information
Showing
13 changed files
with
51 additions
and
325 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
bedrock/base/management/commands/import_waffle_switches.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,29 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from waffle.models import Switch | ||
|
||
from bedrock.base.models import ConfigValue | ||
from bedrock.utils.management.decorators import alert_sentry_on_exception | ||
|
||
|
||
@alert_sentry_on_exception | ||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
prefix = "SWITCH_" | ||
|
||
for config in ConfigValue.objects.all(): | ||
# Ignore funnelcakes and other yummy things. | ||
if not config.name.startswith(prefix): | ||
continue | ||
|
||
# Remove prefix. | ||
name = config.name[len(prefix) :] | ||
# Set active to boolean. | ||
active = config.value == "on" | ||
|
||
switch, created = Switch.objects.update_or_create(name=name, defaults={"active": active}) | ||
print(f"{'Created new' if created else 'Updated'} switch: {name} = {'on' if active else 'off'}") |
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
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
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.