mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-03 08:22:18 +02:00
Cleanup
This commit is contained in:
parent
91545f45be
commit
74978ba5ba
8 changed files with 193 additions and 115 deletions
|
@ -14,48 +14,56 @@ class WaffleFlag(AbstractUserFlag):
|
|||
|
||||
class Meta:
|
||||
"""Contains meta information about this class"""
|
||||
|
||||
verbose_name = "waffle flag"
|
||||
verbose_name_plural = "Waffle flags"
|
||||
|
||||
# Defines which waffle flags should be created at startup.
|
||||
# Add to this list if you want to add another flag that is generated at startup.
|
||||
# When you do so, you will need to add a new instance of `0091_create_waffle_flags_v{version_number}`
|
||||
# in registrar/migrations for that change to update automatically on migrate.
|
||||
DEFAULT_WAFFLE_FLAGS = [
|
||||
"profile_feature",
|
||||
"dns_hosting_feature"
|
||||
]
|
||||
@staticmethod
|
||||
def get_default_waffle_flags():
|
||||
"""
|
||||
Defines which waffle flags should be created at startup.
|
||||
Add to this list if you want to add another flag that is generated at startup.
|
||||
When you do so, you will need to add a new instance of `0091_create_waffle_flags_v{version_number}`
|
||||
in registrar/migrations for that change to update automatically on migrate.
|
||||
This has to exist here, as from the context of migrations, it cannot access constants
|
||||
"""
|
||||
default_flags = [
|
||||
# flag_name, flag_note
|
||||
("profile_feature", "Used for profiles"),
|
||||
("dns_hosting_feature", "Used for dns hosting"),
|
||||
]
|
||||
return default_flags
|
||||
|
||||
@classmethod
|
||||
def create_waffle_flags_for_migrations(cls):
|
||||
@staticmethod
|
||||
def create_waffle_flags_for_migrations(apps, default_waffle_flags):
|
||||
"""
|
||||
Creates a pre-defined list of flags for our migrations.
|
||||
"""
|
||||
logger.info("Creating default waffle flags...")
|
||||
WaffleFlag = apps.get_model("registrar", "WaffleFlag")
|
||||
# Flags can be changed through the command line or through django admin.
|
||||
# To keep the scope of this function minimal and simple, if we require additional
|
||||
# config on these flag, it should be done in a seperate function or as a command.
|
||||
for flag_name in cls.DEFAULT_WAFFLE_FLAGS:
|
||||
for flag_name, flag_note in default_waffle_flags:
|
||||
try:
|
||||
cls.objects.update_or_create(
|
||||
WaffleFlag.objects.update_or_create(
|
||||
name=flag_name,
|
||||
# Booleans like superusers or is_staff can be set here, if needed.
|
||||
defaults={
|
||||
'note': 'Auto-generated waffle flag'
|
||||
}
|
||||
defaults={"note": flag_note},
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred when attempting to add or update flag {flag_name}: {e}")
|
||||
|
||||
@classmethod
|
||||
def delete_waffle_flags_for_migrations(cls):
|
||||
|
||||
@staticmethod
|
||||
def delete_waffle_flags_for_migrations(apps, default_waffle_flags):
|
||||
"""
|
||||
Delete a pre-defined list of flags for our migrations (the reverse_code operation).
|
||||
"""
|
||||
logger.info("Deleting default waffle flags...")
|
||||
existing_flags = cls.objects.filter(name__in=cls.DEFAULT_WAFFLE_FLAGS)
|
||||
WaffleFlag = apps.get_model("registrar", "WaffleFlag")
|
||||
existing_flags = WaffleFlag.objects.filter(name__in=default_waffle_flags)
|
||||
for flag in existing_flags:
|
||||
try:
|
||||
cls.objects.get(name=flag.name).delete()
|
||||
WaffleFlag.objects.get(name=flag.name).delete()
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred when attempting to delete flag {flag.name}: {e}")
|
||||
logger.error(f"An error occurred when attempting to delete flag {flag.name}: {e}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue