- Recipe model with ingredients (amount/range, unit, group, note), steps, lowercase tags, author notes, source URL and private/public visibility - Central RecipeQuerySet.visible_to() used by every read path; edit only by owner, delete by owner or admin (visible recipes only) - Text-based editing: ingredient/step parser with roundtrip and scaling - Photo upload (JPEG/PNG/WebP/HEIC), re-encoded to WebP without EXIF, thumbnails, cover image, served only through permission-checked view - Search across title, description, ingredients, tags; ingredient and tag filters; "mine" and favourites views - Admin can delete all recipes of a deactivated user - Acceptance tests: private recipes unreachable for others and admins in list, search, tags, favourites, detail, edit, delete and image URLs Co-Authored-By: Claude Opus 5.5 <[email protected]>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
import io
|
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
|
from PIL import Image
|
|
|
|
from recipes import parsing
|
|
from recipes.models import Recipe
|
|
|
|
|
|
def make_recipe(owner, title="Testrezept", visibility=Recipe.Visibility.PUBLIC, ingredients="200 g Mehl\n2 Eier",
|
|
steps="Mischen.\n\nBacken.", tags=("kuchen",)):
|
|
recipe = Recipe.objects.create(owner=owner, title=title, visibility=visibility, servings=4)
|
|
recipe.set_ingredients(parsing.parse_ingredients(ingredients))
|
|
recipe.set_steps(parsing.parse_steps(steps))
|
|
recipe.set_tags(tags)
|
|
return recipe
|
|
|
|
|
|
def image_upload(name="foto.jpg", size=(1200, 900), fmt="JPEG", color=(200, 120, 40)):
|
|
buffer = io.BytesIO()
|
|
Image.new("RGB", size, color).save(buffer, fmt)
|
|
content_type = {"JPEG": "image/jpeg", "PNG": "image/png", "WEBP": "image/webp"}[fmt]
|
|
return SimpleUploadedFile(name, buffer.getvalue(), content_type=content_type)
|
|
|
|
|
|
def form_data(**overrides):
|
|
data = {
|
|
"title": "Pfannkuchen",
|
|
"description": "Einfach und schnell.",
|
|
"servings": 4,
|
|
"servings_label": "Portionen",
|
|
"prep_minutes": 10,
|
|
"cook_minutes": 15,
|
|
"ingredients_text": "250 g Mehl\n500 ml Milch\n3 Eier\n1 Prise Salz",
|
|
"steps_text": "Alles verrühren.\n\nIn der Pfanne ausbacken.",
|
|
"tags_text": "Frühstück, Süß",
|
|
"author_notes": "Mit Apfelmus servieren.",
|
|
"source_url": "",
|
|
"visibility": "private",
|
|
}
|
|
data.update(overrides)
|
|
return data
|