sandwitches 2.4.0__tar.gz → 2.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. {sandwitches-2.4.0 → sandwitches-2.4.1}/PKG-INFO +1 -1
  2. {sandwitches-2.4.0 → sandwitches-2.4.1}/pyproject.toml +1 -1
  3. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/admin.py +10 -2
  4. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/forms.py +65 -5
  5. sandwitches-2.4.1/src/sandwitches/migrations/0015_order_completed_alter_order_status_and_more.py +56 -0
  6. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/models.py +8 -1
  7. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/partials/order_rows.html +1 -1
  8. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/recipe_form.html +113 -18
  9. sandwitches-2.4.1/src/sandwitches/templates/community.html +238 -0
  10. sandwitches-2.4.1/src/sandwitches/templates/order_detail.html +68 -0
  11. sandwitches-2.4.1/src/sandwitches/templates/profile.html +185 -0
  12. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/urls.py +1 -0
  13. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/views.py +46 -1
  14. sandwitches-2.4.0/src/sandwitches/templates/community.html +0 -141
  15. sandwitches-2.4.0/src/sandwitches/templates/profile.html +0 -95
  16. {sandwitches-2.4.0 → sandwitches-2.4.1}/README.md +0 -0
  17. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/__init__.py +0 -0
  18. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/api.py +0 -0
  19. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/asgi.py +0 -0
  20. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/feeds.py +0 -0
  21. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/locale/nl/LC_MESSAGES/django.mo +0 -0
  22. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/locale/nl/LC_MESSAGES/django.po +0 -0
  23. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/management/__init__.py +0 -0
  24. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/management/commands/__init__.py +0 -0
  25. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/management/commands/reset_daily_orders.py +0 -0
  26. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0001_initial.py +0 -0
  27. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0002_historicalrecipe_servings_recipe_servings.py +0 -0
  28. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0003_setting.py +0 -0
  29. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0004_alter_setting_ai_api_key_and_more.py +0 -0
  30. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0005_rating_comment.py +0 -0
  31. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0006_historicalrecipe_is_highlighted_and_more.py +0 -0
  32. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0007_historicalrecipe_price_recipe_price_order.py +0 -0
  33. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0008_historicalrecipe_daily_orders_count_and_more.py +0 -0
  34. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0009_historicalrecipe_is_approved_recipe_is_approved.py +0 -0
  35. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0010_rename_is_approved_historicalrecipe_is_community_made_and_more.py +0 -0
  36. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0011_alter_historicalrecipe_is_community_made_and_more.py +0 -0
  37. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0012_rename_is_community_made_historicalrecipe_is_approved_and_more.py +0 -0
  38. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0013_cartitem.py +0 -0
  39. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/0014_ensure_groups_exist.py +0 -0
  40. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/migrations/__init__.py +0 -0
  41. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/settings.py +0 -0
  42. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/storage.py +0 -0
  43. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/tasks.py +0 -0
  44. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/admin_base.html +0 -0
  45. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/confirm_delete.html +0 -0
  46. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/dashboard.html +0 -0
  47. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/order_list.html +0 -0
  48. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/partials/dashboard_charts.html +0 -0
  49. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/rating_list.html +0 -0
  50. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/recipe_approval_list.html +0 -0
  51. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/recipe_list.html +0 -0
  52. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/tag_form.html +0 -0
  53. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/tag_list.html +0 -0
  54. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/task_detail.html +0 -0
  55. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/task_list.html +0 -0
  56. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/user_form.html +0 -0
  57. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/admin/user_list.html +0 -0
  58. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/base.html +0 -0
  59. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/base_beer.html +0 -0
  60. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/cart.html +0 -0
  61. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/carousel_scripts.html +0 -0
  62. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/favorites_search_form.html +0 -0
  63. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/footer.html +0 -0
  64. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/ingredients_scripts.html +0 -0
  65. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/ingredients_section.html +0 -0
  66. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/instructions_section.html +0 -0
  67. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/language_dialog.html +0 -0
  68. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/navbar.html +0 -0
  69. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/rating_section.html +0 -0
  70. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/recipe_header.html +0 -0
  71. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/search_form.html +0 -0
  72. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/search_scripts.html +0 -0
  73. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/side_menu.html +0 -0
  74. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/components/user_menu.html +0 -0
  75. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/detail.html +0 -0
  76. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/favorites.html +0 -0
  77. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/index.html +0 -0
  78. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/login.html +0 -0
  79. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/partials/recipe_list.html +0 -0
  80. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/setup.html +0 -0
  81. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templates/signup.html +0 -0
  82. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templatetags/__init__.py +0 -0
  83. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templatetags/custom_filters.py +0 -0
  84. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/templatetags/markdown_extras.py +0 -0
  85. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/utils.py +0 -0
  86. {sandwitches-2.4.0 → sandwitches-2.4.1}/src/sandwitches/wsgi.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sandwitches
3
- Version: 2.4.0
3
+ Version: 2.4.1
4
4
  Summary: Add your description here
5
5
  Author: Martyn van Dijke
6
6
  Author-email: Martyn van Dijke <martijnvdijke600@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sandwitches"
3
- version = "2.4.0"
3
+ version = "2.4.1"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -84,7 +84,15 @@ class RatingAdmin(ImportExportModelAdmin):
84
84
  @admin.register(Order)
85
85
  class OrderAdmin(ImportExportModelAdmin):
86
86
  resource_classes = [OrderResource]
87
- list_display = ("id", "user", "recipe", "status", "total_price", "created_at")
88
- list_filter = ("status", "created_at")
87
+ list_display = (
88
+ "id",
89
+ "user",
90
+ "recipe",
91
+ "status",
92
+ "completed",
93
+ "total_price",
94
+ "created_at",
95
+ )
96
+ list_filter = ("status", "completed", "created_at")
89
97
  search_fields = ("user__username", "recipe__title")
90
98
  readonly_fields = ("total_price", "created_at", "updated_at")
@@ -86,6 +86,8 @@ class UserSignupForm(UserCreationForm, BaseUserFormMixin):
86
86
 
87
87
 
88
88
  class UserProfileForm(forms.ModelForm):
89
+ image_data = forms.CharField(widget=forms.HiddenInput(), required=False)
90
+
89
91
  class Meta:
90
92
  model = User
91
93
  fields = (
@@ -96,8 +98,25 @@ class UserProfileForm(forms.ModelForm):
96
98
  "bio",
97
99
  )
98
100
 
101
+ def save(self, commit=True):
102
+ user = super().save(commit=False)
103
+ image_data = self.cleaned_data.get("image_data")
104
+ if image_data and image_data.startswith("data:image"):
105
+ import base64
106
+ from django.core.files.base import ContentFile
107
+
108
+ format, imgstr = image_data.split(";base64,")
109
+ ext = format.split("/")[-1]
110
+ data = ContentFile(base64.b64decode(imgstr), name=f"avatar.{ext}")
111
+ user.avatar = data
112
+ if commit:
113
+ user.save()
114
+ return user
115
+
99
116
 
100
117
  class UserEditForm(forms.ModelForm):
118
+ image_data = forms.CharField(widget=forms.HiddenInput(), required=False)
119
+
101
120
  class Meta:
102
121
  model = User
103
122
  fields = (
@@ -112,6 +131,21 @@ class UserEditForm(forms.ModelForm):
112
131
  "bio",
113
132
  )
114
133
 
134
+ def save(self, commit=True):
135
+ user = super().save(commit=False)
136
+ image_data = self.cleaned_data.get("image_data")
137
+ if image_data and image_data.startswith("data:image"):
138
+ import base64
139
+ from django.core.files.base import ContentFile
140
+
141
+ format, imgstr = image_data.split(";base64,")
142
+ ext = format.split("/")[-1]
143
+ data = ContentFile(base64.b64decode(imgstr), name=f"avatar.{ext}")
144
+ user.avatar = data
145
+ if commit:
146
+ user.save()
147
+ return user
148
+
115
149
 
116
150
  class TagForm(forms.ModelForm):
117
151
  class Meta:
@@ -126,6 +160,7 @@ class RecipeForm(forms.ModelForm):
126
160
  widget=forms.TextInput(attrs={"placeholder": _("e.g. spicy, vegan, quick")}),
127
161
  )
128
162
  rotation = forms.IntegerField(widget=forms.HiddenInput(), initial=0, required=False)
163
+ image_data = forms.CharField(widget=forms.HiddenInput(), required=False)
129
164
 
130
165
  class Meta:
131
166
  model = Recipe
@@ -153,11 +188,22 @@ class RecipeForm(forms.ModelForm):
153
188
  )
154
189
 
155
190
  def save(self, commit=True):
156
- recipe = super().save(commit=commit)
191
+ recipe = super().save(commit=False)
192
+
193
+ # Handle base64 image data from cropper
194
+ image_data = self.cleaned_data.get("image_data")
195
+ if image_data and image_data.startswith("data:image"):
196
+ import base64
197
+ from django.core.files.base import ContentFile
157
198
 
158
- # Handle rotation if an image exists and rotation is requested
199
+ format, imgstr = image_data.split(";base64,")
200
+ ext = format.split("/")[-1]
201
+ data = ContentFile(base64.b64decode(imgstr), name=f"recipe_image.{ext}")
202
+ recipe.image = data
203
+
204
+ # Handle rotation if an image exists and rotation is requested (fallback for simple rotation)
159
205
  rotation = self.cleaned_data.get("rotation", 0)
160
- if rotation != 0 and recipe.image:
206
+ if rotation != 0 and recipe.image and not image_data:
161
207
  try:
162
208
  from PIL import Image as PILImage
163
209
 
@@ -169,9 +215,9 @@ class RecipeForm(forms.ModelForm):
169
215
  print(f"Error rotating image: {e}")
170
216
 
171
217
  if commit:
218
+ recipe.save()
172
219
  recipe.set_tags_from_string(self.cleaned_data.get("tags_string", ""))
173
220
  else:
174
- # We'll need to handle this in the view if commit=False
175
221
  self.save_m2m = lambda: recipe.set_tags_from_string(
176
222
  self.cleaned_data.get("tags_string", "")
177
223
  )
@@ -184,6 +230,7 @@ class UserRecipeSubmissionForm(forms.ModelForm):
184
230
  label=_("Tags (comma separated)"),
185
231
  widget=forms.TextInput(attrs={"placeholder": _("e.g. spicy, vegan, quick")}),
186
232
  )
233
+ image_data = forms.CharField(widget=forms.HiddenInput(), required=False)
187
234
 
188
235
  class Meta:
189
236
  model = Recipe
@@ -201,8 +248,21 @@ class UserRecipeSubmissionForm(forms.ModelForm):
201
248
  }
202
249
 
203
250
  def save(self, commit=True):
204
- recipe = super().save(commit=commit)
251
+ recipe = super().save(commit=False)
252
+
253
+ # Handle base64 image data from cropper
254
+ image_data = self.cleaned_data.get("image_data")
255
+ if image_data and image_data.startswith("data:image"):
256
+ import base64
257
+ from django.core.files.base import ContentFile
258
+
259
+ format, imgstr = image_data.split(";base64,")
260
+ ext = format.split("/")[-1]
261
+ data = ContentFile(base64.b64decode(imgstr), name=f"recipe_image.{ext}")
262
+ recipe.image = data
263
+
205
264
  if commit:
265
+ recipe.save()
206
266
  recipe.set_tags_from_string(self.cleaned_data.get("tags_string", ""))
207
267
  else:
208
268
  self.save_m2m = lambda: recipe.set_tags_from_string(
@@ -0,0 +1,56 @@
1
+ # Generated by Django 6.0.1 on 2026-01-27 08:33
2
+
3
+ import django.core.validators
4
+ from django.db import migrations, models
5
+
6
+
7
+ class Migration(migrations.Migration):
8
+ dependencies = [
9
+ ("sandwitches", "0014_ensure_groups_exist"),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AddField(
14
+ model_name="order",
15
+ name="completed",
16
+ field=models.BooleanField(default=False),
17
+ ),
18
+ migrations.AlterField(
19
+ model_name="order",
20
+ name="status",
21
+ field=models.CharField(
22
+ choices=[
23
+ ("PENDING", "Pending"),
24
+ ("PREPARING", "Preparing"),
25
+ ("MADE", "Made"),
26
+ ("SHIPPED", "Shipped"),
27
+ ("COMPLETED", "Completed"),
28
+ ("CANCELLED", "Cancelled"),
29
+ ],
30
+ default="PENDING",
31
+ max_length=20,
32
+ ),
33
+ ),
34
+ migrations.AlterField(
35
+ model_name="setting",
36
+ name="email",
37
+ field=models.EmailField(
38
+ blank=True,
39
+ max_length=254,
40
+ null=True,
41
+ validators=[django.core.validators.EmailValidator()],
42
+ ),
43
+ ),
44
+ migrations.AlterField(
45
+ model_name="user",
46
+ name="email",
47
+ field=models.EmailField(
48
+ max_length=254, validators=[django.core.validators.EmailValidator()]
49
+ ),
50
+ ),
51
+ migrations.AlterField(
52
+ model_name="user",
53
+ name="username",
54
+ field=models.CharField(max_length=150, unique=True),
55
+ ),
56
+ ]
@@ -11,6 +11,7 @@ import logging
11
11
  from django.urls import reverse
12
12
  from solo.models import SingletonModel
13
13
  from django.core.exceptions import ValidationError
14
+ from django.core.validators import EmailValidator
14
15
 
15
16
  from imagekit.models import ImageSpecField
16
17
  from imagekit.processors import ResizeToFill
@@ -21,7 +22,7 @@ hashed_storage = HashedFilenameStorage()
21
22
  class Setting(SingletonModel):
22
23
  site_name = models.CharField(max_length=255, default="Sandwitches")
23
24
  site_description = models.TextField(blank=True, null=True)
24
- email = models.EmailField(blank=True, null=True)
25
+ email = models.EmailField(blank=True, null=True, validators=[EmailValidator()])
25
26
  ai_connection_point = models.URLField(blank=True, null=True)
26
27
  ai_model = models.CharField(max_length=255, blank=True, null=True)
27
28
  ai_api_key = models.CharField(max_length=255, blank=True, null=True)
@@ -34,6 +35,8 @@ class Setting(SingletonModel):
34
35
 
35
36
 
36
37
  class User(AbstractUser):
38
+ username = models.CharField(max_length=150, unique=True)
39
+ email = models.EmailField(validators=[EmailValidator()])
37
40
  avatar = models.ImageField(upload_to="avatars", blank=True, null=True)
38
41
  avatar_thumbnail = ImageSpecField(
39
42
  source="avatar",
@@ -230,6 +233,9 @@ class Rating(models.Model):
230
233
  class Order(models.Model):
231
234
  STATUS_CHOICES = (
232
235
  ("PENDING", "Pending"),
236
+ ("PREPARING", "Preparing"),
237
+ ("MADE", "Made"),
238
+ ("SHIPPED", "Shipped"),
233
239
  ("COMPLETED", "Completed"),
234
240
  ("CANCELLED", "Cancelled"),
235
241
  )
@@ -239,6 +245,7 @@ class Order(models.Model):
239
245
  )
240
246
  recipe = models.ForeignKey(Recipe, related_name="orders", on_delete=models.CASCADE)
241
247
  status = models.CharField(max_length=20, choices=STATUS_CHOICES, default="PENDING")
248
+ completed = models.BooleanField(default=False)
242
249
  total_price = models.DecimalField(max_digits=6, decimal_places=2)
243
250
  created_at = models.DateTimeField(auto_now_add=True)
244
251
  updated_at = models.DateTimeField(auto_now=True)
@@ -15,7 +15,7 @@
15
15
  <td>{{ order.recipe.title }}</td>
16
16
  <td>{{ order.total_price }} €</td>
17
17
  <td>
18
- <span class="chip {% if order.status == 'PENDING' %}surface-variant{% elif order.status == 'COMPLETED' %}primary{% else %}error{% endif %}">
18
+ <span class="chip {% if order.status == 'PENDING' %}surface-variant{% elif order.status == 'COMPLETED' %}primary{% elif order.status == 'CANCELLED' %}error{% else %}secondary{% endif %}">
19
19
  {{ order.get_status_display }}
20
20
  </span>
21
21
  </td>
@@ -31,6 +31,14 @@
31
31
  .form-section {
32
32
  margin-bottom: 2rem;
33
33
  }
34
+ /* Cropper styles */
35
+ .cropper-container {
36
+ max-height: 70vh;
37
+ }
38
+ #cropper-image {
39
+ display: block;
40
+ max-width: 100%;
41
+ }
34
42
  </style>
35
43
  {% endblock %}
36
44
 
@@ -38,6 +46,7 @@
38
46
  <form method="post" enctype="multipart/form-data" id="recipe-form">
39
47
  {% csrf_token %}
40
48
  {{ form.rotation }}
49
+ {{ form.image_data }}
41
50
  <div class="grid">
42
51
  <!-- Top Section: Title, Tags, and Image -->
43
52
  <div class="s12 m8">
@@ -107,25 +116,21 @@
107
116
 
108
117
  <div class="relative mb-1" style="overflow: hidden; min-height: 200px; display: flex; align-items: center; justify-content: center;">
109
118
  {% if recipe.image %}
110
- <img src="{{ recipe.image_medium.url }}?v={% now "U" %}" class="responsive round" id="image-preview" style="max-height: 300px; width: 100%; object-fit: contain; transition: transform 0.3s ease;">
119
+ <img src="{{ recipe.image_medium.url }}?v={% now "U" %}" class="responsive round" id="image-preview" style="max-height: 300px; width: 100%; object-fit: contain;">
111
120
  {% else %}
121
+ <img src="" class="responsive round" id="image-preview" style="max-height: 300px; width: 100%; object-fit: contain; display: none;">
112
122
  <div class="medium-height middle-align center-align gray1 round" id="image-placeholder" style="width: 100%;">
113
123
  <i class="extra">image</i>
114
124
  </div>
115
125
  {% endif %}
116
126
  </div>
117
127
 
118
- {% if recipe.image %}
119
- <div class="row no-space border round mb-1">
120
- <button type="button" class="button transparent max" onclick="rotatePreview(-90)" title="{% trans 'Rotate 90° CCW' %}">
121
- <i>rotate_left</i>
122
- </button>
123
- <div class="divider vertical"></div>
124
- <button type="button" class="button transparent max" onclick="rotatePreview(90)" title="{% trans 'Rotate 90° CW' %}">
125
- <i>rotate_right</i>
128
+ <div id="image-tools" class="row no-space border round mb-1" style="{% if not recipe.image %}display: none;{% endif %}">
129
+ <button type="button" class="button transparent max" onclick="openCropper()" title="{% trans 'Edit Image' %}">
130
+ <i>crop_rotate</i>
131
+ <span>{% trans "Edit" %}</span>
126
132
  </button>
127
133
  </div>
128
- {% endif %}
129
134
 
130
135
  <div class="field file border round">
131
136
  <input type="text" readonly>
@@ -174,21 +179,111 @@
174
179
  </button>
175
180
  </nav>
176
181
  </form>
182
+
183
+ <dialog id="cropper-dialog" class="large">
184
+ <div class="padding">
185
+ <h5 class="bold mb-1">{% trans "Edit Image" %}</h5>
186
+ <div class="cropper-container mb-1">
187
+ <img id="cropper-image" src="">
188
+ </div>
189
+ <div class="row scroll no-space border round mb-1">
190
+ <button type="button" class="button transparent max" onclick="cropper.rotate(-90)" title="{% trans 'Rotate Left' %}">
191
+ <i>rotate_left</i>
192
+ </button>
193
+ <button type="button" class="button transparent max" onclick="cropper.rotate(90)" title="{% trans 'Rotate Right' %}">
194
+ <i>rotate_right</i>
195
+ </button>
196
+ <div class="divider vertical"></div>
197
+ <button type="button" class="button transparent max" onclick="cropper.scaleX(-cropper.getData().scaleX || -1)" title="{% trans 'Flip Horizontal' %}">
198
+ <i>flip</i>
199
+ </button>
200
+ <button type="button" class="button transparent max" onclick="cropper.scaleY(-cropper.getData().scaleY || -1)" title="{% trans 'Flip Vertical' %}">
201
+ <i>flip</i>
202
+ </button>
203
+ <div class="divider vertical"></div>
204
+ <button type="button" class="button transparent max" onclick="cropper.setAspectRatio(1)" title="{% trans '1:1' %}">1:1</button>
205
+ <button type="button" class="button transparent max" onclick="cropper.setAspectRatio(4/3)" title="{% trans '4:3' %}">4:3</button>
206
+ <button type="button" class="button transparent max" onclick="cropper.setAspectRatio(16/9)" title="{% trans '16:9' %}">16:9</button>
207
+ <button type="button" class="button transparent max" onclick="cropper.setAspectRatio(NaN)" title="{% trans 'Free' %}">
208
+ <i>crop_free</i>
209
+ </button>
210
+ </div>
211
+ <nav class="right-align">
212
+ <button type="button" class="button transparent" onclick="ui('#cropper-dialog')">{% trans "Cancel" %}</button>
213
+ <button type="button" class="button primary" onclick="applyCrop()">{% trans "Apply" %}</button>
214
+ </nav>
215
+ </div>
216
+ </dialog>
177
217
  {% endblock %}
178
218
 
179
219
  {% block admin_scripts %}
180
220
  <script>
181
- let currentRotation = 0;
182
-
183
- function rotatePreview(angle) {
184
- currentRotation = (currentRotation + angle) % 360;
185
- const img = document.getElementById('image-preview');
186
- if (img) {
187
- img.style.transform = `rotate(${currentRotation}deg)`;
188
- document.getElementsByName('rotation')[0].value = currentRotation;
221
+ let cropper;
222
+ const imagePreview = document.getElementById('image-preview');
223
+ const imagePlaceholder = document.getElementById('image-placeholder');
224
+ const imageTools = document.getElementById('image-tools');
225
+ const imageInput = document.getElementById('id_image');
226
+ const imageDataInput = document.getElementById('id_image_data');
227
+ const cropperImage = document.getElementById('cropper-image');
228
+
229
+ function openCropper() {
230
+ if (!imagePreview.src || imagePreview.src === window.location.href) return;
231
+ cropperImage.src = imagePreview.src;
232
+ ui('#cropper-dialog');
233
+
234
+ if (cropper) {
235
+ cropper.destroy();
189
236
  }
237
+
238
+ setTimeout(() => {
239
+ cropper = new Cropper(cropperImage, {
240
+ viewMode: 1,
241
+ autoCropArea: 1,
242
+ responsive: true,
243
+ restore: false,
244
+ checkCrossOrigin: true,
245
+ guides: true,
246
+ center: true,
247
+ highlight: false,
248
+ cropBoxMovable: true,
249
+ cropBoxResizable: true,
250
+ toggleDragModeOnDblclick: false,
251
+ });
252
+ }, 100);
190
253
  }
191
254
 
255
+ function applyCrop() {
256
+ const canvas = cropper.getCroppedCanvas({
257
+ maxWidth: 2000,
258
+ maxHeight: 2000,
259
+ });
260
+
261
+ const croppedData = canvas.toDataURL('image/jpeg', 0.9);
262
+ imagePreview.src = croppedData;
263
+ imagePreview.style.display = 'block';
264
+ if (imagePlaceholder) imagePlaceholder.style.display = 'none';
265
+ imageTools.style.display = 'flex';
266
+ imageDataInput.value = croppedData;
267
+
268
+ ui('#cropper-dialog');
269
+ }
270
+
271
+ imageInput.addEventListener('change', function(e) {
272
+ const files = e.target.files;
273
+ if (files && files.length > 0) {
274
+ const reader = new FileReader();
275
+ reader.onload = function(event) {
276
+ imagePreview.src = event.target.result;
277
+ imagePreview.style.display = 'block';
278
+ if (imagePlaceholder) imagePlaceholder.style.display = 'none';
279
+ imageTools.style.display = 'flex';
280
+ // Automatically open cropper for new images
281
+ openCropper();
282
+ };
283
+ reader.readAsDataURL(files[0]);
284
+ }
285
+ });
286
+
192
287
  document.addEventListener('DOMContentLoaded', function() {
193
288
  const fields = ['id_description', 'id_ingredients', 'id_instructions'];
194
289
  fields.forEach(id => {