Skip to content

Commit

Permalink
Add a command to set the config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-Crow committed Mar 11, 2024
1 parent 30a023e commit a46ed44
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ dmypy.json
.vscode/

# Project-specific stuff
config.json
cron.json
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ init:
$(EXEC_CMD) poetry run pre-commit install
$(EXEC_CMD) poetry run python manage.py migrate
make collectstatic
$(EXEC_CMD) poetry run python manage.py set_config
$(EXEC_CMD) poetry run python manage.py create_sample_pages

.PHONY: runserver
Expand Down
9 changes: 9 additions & 0 deletions config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"header_brand": "Intitulé officiel",
"header_brand_html": "Intitulé<br />officiel",
"footer_brand": "Intitulé officiel",
"footer_brand_html": "Intitulé<br />officiel",
"site_title": "Titre du site",
"site_tagline": "Sous-titre du site",
"footer_description": "Description"
}
19 changes: 19 additions & 0 deletions content_manager/management/commands/set_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
from os.path import isfile

from django.core.management.base import BaseCommand

from content_manager.models import CmsDsfrConfig


class Command(BaseCommand):
def handle(self, *args, **kwargs):
if isfile("config.json"):
with open("config.json") as config_file:
config_data = json.load(config_file)

_config, created = CmsDsfrConfig.objects.get_or_create(id=1, defaults=config_data)
if created:
self.stdout.write(self.style.SUCCESS(f"Config imported for {config_data.get('site_title', '')}"))
else:
self.stdout.write(self.style.SUCCESS("Config already existing, data not imported."))

0 comments on commit a46ed44

Please sign in to comment.