From c76fd119cf55eca1f018a30258a69fb826a15cba Mon Sep 17 00:00:00 2001 From: Kyle Dammann Date: Fri, 30 Oct 2026 23:05:05 +0100 Subject: [PATCH] Make new recipes public by default New recipes (manual, AI draft and all imports) now start as public; private can still be chosen per recipe. Existing recipes are unchanged. Co-Authored-By: Claude Opus 5.5 --- .../0003_visibility_default_public.py | 18 ++++++++++++++++++ recipes/models.py | 2 +- tests/test_recipes.py | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 recipes/migrations/0003_visibility_default_public.py diff --git a/recipes/migrations/0003_visibility_default_public.py b/recipes/migrations/0003_visibility_default_public.py new file mode 100644 index 0000000..210f79c --- /dev/null +++ b/recipes/migrations/0003_visibility_default_public.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.18 on 2026-10-30 22:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('recipes', '0002_comment'), + ] + + operations = [ + migrations.AlterField( + model_name='recipe', + name='visibility', + field=models.CharField(choices=[('private', 'Privat (nur für mich)'), ('public', 'Öffentlich (alle Nutzer)')], default='public', max_length=10, verbose_name='Sichtbarkeit'), + ), + ] diff --git a/recipes/models.py b/recipes/models.py index eea4ab6..14350e1 100644 --- a/recipes/models.py +++ b/recipes/models.py @@ -82,7 +82,7 @@ class Recipe(models.Model): cook_minutes = models.PositiveSmallIntegerField("Koch-/Backzeit (Min.)", null=True, blank=True) source_url = models.URLField("Quelle (URL)", max_length=1000, blank=True) author_notes = models.TextField("Notizen", blank=True) - visibility = models.CharField("Sichtbarkeit", max_length=10, choices=Visibility.choices, default=Visibility.PRIVATE) + visibility = models.CharField("Sichtbarkeit", max_length=10, choices=Visibility.choices, default=Visibility.PUBLIC) tags = models.ManyToManyField(Tag, blank=True, related_name="recipes") created_at = models.DateTimeField("Erstellt", auto_now_add=True) updated_at = models.DateTimeField("Geändert", auto_now=True) diff --git a/tests/test_recipes.py b/tests/test_recipes.py index 568f916..fd4a944 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -188,3 +188,19 @@ def test_user_cannot_bulk_delete(user_client, other_user): make_recipe(other_user) assert user_client.post(reverse("accounts:admin_user_delete_recipes", args=[other_user.pk])).status_code == 403 assert Recipe.objects.exists() + + +def test_new_recipe_form_defaults_to_public(user_client): + form = user_client.get(reverse("recipes:create")).context["form"] + assert form["visibility"].value() == "public" + + +def test_imported_draft_defaults_to_public(user_client, settings): + settings.OPENAI_API_KEY = "" + response = user_client.post(reverse("recipes:import_text"), {"text": "200 g Mehl, 2 Eier, verrühren und backen"}) + assert response.context["form"]["visibility"].value() == "public" + + +def test_private_can_still_be_chosen(user_client): + user_client.post(reverse("recipes:create"), form_data(visibility="private")) + assert Recipe.objects.get().visibility == "private"