diff --git a/app/controllers/daily_plan_recipes.py b/app/controllers/daily_plan_recipes.py index 8f2f801b..ca14e85a 100644 --- a/app/controllers/daily_plan_recipes.py +++ b/app/controllers/daily_plan_recipes.py @@ -36,7 +36,7 @@ def add_recipe(self, daily_plan_id): self.daily_recipe = DailyPlanManager(self.daily_plan).add_recipe(self.recipe) - return redirect(url_for("DailyPlanView:show", id=self.daily_plan.id)) + return redirect(request.referrer) @route("daily_plans/add_shopping/", methods=["POST"]) def add_shopping(self, daily_plan_id): diff --git a/app/helpers/context_processors.py b/app/helpers/context_processors.py index 0a999852..270b7d41 100644 --- a/app/helpers/context_processors.py +++ b/app/helpers/context_processors.py @@ -73,3 +73,10 @@ def inflect(word, value): raise AttributeError( f"Don't know how to inflect {word} with value {value}, teach me!" ) + + +context_processors = { + "human_format_date": human_format_date, + "formatted_amount": formatted_amount, + "inflect": inflect, +} diff --git a/app/models/__init__.py b/app/models/__init__.py index 82840d73..d1f6a152 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -64,7 +64,7 @@ "EventDay", ] -all_dict = { +models_dictionary = { "Attendee": Attendee, "Conversion": Conversion, "DailyPlan": DailyPlan, diff --git a/app/static/js/controllers/clicker_controller.js b/app/static/js/controllers/clicker_controller.js index b032194e..5f53cd7d 100644 --- a/app/static/js/controllers/clicker_controller.js +++ b/app/static/js/controllers/clicker_controller.js @@ -10,6 +10,8 @@ export default class extends Controller { } activateLink(event) { + if (event.target.dataset.bsToggle == "modal") { return; } // prevent this when clicking modal button + var clickable_parent = event.target.closest(".clickable") var first_link = clickable_parent.getElementsByTagName("a")[0]; first_link.click(); diff --git a/app/static/js/controllers/custom_events_controller.js b/app/static/js/controllers/custom_events_controller.js new file mode 100644 index 00000000..c18596d6 --- /dev/null +++ b/app/static/js/controllers/custom_events_controller.js @@ -0,0 +1,11 @@ +import { Controller } from "../../node_modules/@hotwired/stimulus" + +export default class extends Controller { + static values = { "event": String } + + dispatch() { + const event = new CustomEvent(this.eventValue) + window.dispatchEvent(event) + } + +} diff --git a/app/static/js/src/app.js b/app/static/js/src/app.js index 420a70bc..59d278b4 100644 --- a/app/static/js/src/app.js +++ b/app/static/js/src/app.js @@ -70,5 +70,8 @@ window.Stimulus.register('dropzone', DropzoneController) import ClassChangeController from "../controllers/class_change_controller.js" window.Stimulus.register('class-change', ClassChangeController) +import CustomEventsController from "../controllers/custom_events_controller.js" +window.Stimulus.register('custom-events', CustomEventsController) + // Turbo import * as Turbo from "@hotwired/turbo" diff --git a/app/templates/base/base.html.j2 b/app/templates/base/base.html.j2 index a11a19a7..3d159493 100644 --- a/app/templates/base/base.html.j2 +++ b/app/templates/base/base.html.j2 @@ -61,9 +61,6 @@ - - - {% block links %}{% endblock %} {% block style %}{% endblock %} {% block scripts %}{% endblock %} diff --git a/app/templates/daily_plans/_add_recipe_form_options.html.j2 b/app/templates/daily_plans/_add_recipe_form_options.html.j2 index 1f277a06..8f0b363a 100644 --- a/app/templates/daily_plans/_add_recipe_form_options.html.j2 +++ b/app/templates/daily_plans/_add_recipe_form_options.html.j2 @@ -4,5 +4,5 @@ {{ options(current_user.visible_recipes) }} - {{ options(public_recipes) }} - \ No newline at end of file + {{ options(Recipe.load_all_public(exclude_mine=True)) }} + diff --git a/app/templates/daily_plans/_add_recipe_modal.html.j2 b/app/templates/daily_plans/_add_recipe_modal.html.j2 new file mode 100644 index 00000000..195e666d --- /dev/null +++ b/app/templates/daily_plans/_add_recipe_modal.html.j2 @@ -0,0 +1,29 @@ + diff --git a/app/templates/daily_plans/_day_badge.html.j2 b/app/templates/daily_plans/_day_badge.html.j2 deleted file mode 100644 index 4a69d5d2..00000000 --- a/app/templates/daily_plans/_day_badge.html.j2 +++ /dev/null @@ -1,54 +0,0 @@ -{% if not day.is_active %} - {% set color = "light-grey" %} -{% elif day.weekday in ["neděle"] %} - {% set color = "secondary-highlighted" %} -{% else %} - {% set color = "secondary" %} -{% endif %} - -{% if not day.is_active %} - {% set class = "opacity-50 d-none d-md-inline-block cursor-default" %} -{% elif day.is_active %} - {% set class = "clickable" %} -{% endif %} - -
-
{{ link_to(day) }}
- - {% if day.is_active %} - -
- - - - {% endif %} - - {% if day.all_tasks %} -
- {% for task in day.all_tasks %} - {{ task }}
- {% endfor %} - {% endif %} - -
diff --git a/app/templates/daily_plans/_day_card.html.j2 b/app/templates/daily_plans/_day_card.html.j2 new file mode 100644 index 00000000..146dc8f2 --- /dev/null +++ b/app/templates/daily_plans/_day_card.html.j2 @@ -0,0 +1,64 @@ +{% if not day.is_active %} + {% set color = "light-grey" %} +{% elif day.weekday in ["neděle"] %} + {% set color = "secondary-highlighted" %} +{% else %} + {% set color = "secondary" %} +{% endif %} + +{% if not day.is_active %} + {% set class = "opacity-50 d-none d-md-inline-block cursor-default" %} +{% elif day.is_active %} + {% set class = "clickable" %} +{% endif %} + +# set daily_plan = day + +
+ +

{{ link_to(day, class="fs-5") }}

+ + {% if day.is_active %} + + + + + + {% endif %} + + {% if day.all_tasks %} +
+ {% for task in day.all_tasks %} + {{ task }}
+ {% endfor %} + {% endif %} + +
+ +{% with modal_id="add-recipe-to-"~day.id~"-modal" %} + {% include "daily_plans/_add_recipe_modal.html.j2" %} +{% endwith %} diff --git a/app/templates/daily_plans/_navigation.html.j2 b/app/templates/daily_plans/_navigation.html.j2 index 3d5510af..7ea4a9b5 100644 --- a/app/templates/daily_plans/_navigation.html.j2 +++ b/app/templates/daily_plans/_navigation.html.j2 @@ -1,4 +1,4 @@ -

{{ link_to(daily_plan.event) }}

+

{{ link_to(daily_plan.event) }}

{% if daily_plan.has_previous %} @@ -25,4 +25,4 @@ {% endif %} -
\ No newline at end of file + diff --git a/app/templates/events/_export.html.j2 b/app/templates/events/_export.html.j2 index 672e4432..bff0d603 100644 --- a/app/templates/events/_export.html.j2 +++ b/app/templates/events/_export.html.j2 @@ -1,4 +1,4 @@ -
+
exporty
diff --git a/app/templates/events/_info.html.j2 b/app/templates/events/_info.html.j2 index bff8eb37..4633f54d 100644 --- a/app/templates/events/_info.html.j2 +++ b/app/templates/events/_info.html.j2 @@ -1,8 +1,6 @@

{{ event.name }}

-
-
@@ -31,8 +29,11 @@ {{icon("person")}} pro {{ event.people_count }} lidí  ({{event.relative_portion_count | round(1) }} celých porcí)
- {% if event.is_shared %} {{ icon("shared", cursor_class="cursor-default") }} {% endif %} - {% if event.is_archived %} {{ icon("archived", cursor_class="cursor-default") }} {% endif %} + {% if event.is_shared %} + {{ icon("shared", cursor_class="cursor-default") }} + {% endif %} + + {% if event.is_archived %} {{ icon("archived", cursor_class="cursor-default", tooltip="v archivu") }} {% endif %}
@@ -45,4 +46,4 @@
-
\ No newline at end of file +
diff --git a/app/templates/events/_more_options.html.j2 b/app/templates/events/_more_options.html.j2 index d9e2ea00..784da5b1 100644 --- a/app/templates/events/_more_options.html.j2 +++ b/app/templates/events/_more_options.html.j2 @@ -2,9 +2,9 @@
{% if event.is_shared %} - {% set share_text = "zneveřejnit" + icon("unshare") %} + {% set share_text = "zneveřejnit " + icon("unshare") %} {% else %} - {% set share_text = "zveřejnit" + icon("share") %} + {% set share_text = "zveřejnit " + icon("share") %} {% endif %} {{ button_to(url_for('EventView:toggle_shared', id=event.id), @@ -14,7 +14,7 @@
{% if event.can_current_user_share %} {{ button_to(url_for('ShareEventView:show_share_with_user', event_id=event.id), - class="btn bg-color-secondary-action color-white w-100", value="sdílet dalším lidem" + icon('share')) }} + class="btn bg-color-secondary-action color-white w-100", value="sdílet dalším lidem " + icon('share')) }} {% else %} {% endif %} @@ -27,9 +27,9 @@
{% if not event.is_archived %} - {% set archive_text = "archivovat" + icon("archive") %} + {% set archive_text = "archivovat " + icon("archive") %} {% else %} - {% set archive_text = "aktivovat" + icon("unarchive") %} + {% set archive_text = "aktivovat " + icon("unarchive") %} {% endif %} {{ button_to(url_for('EventView:toggle_archived', id=event.id), @@ -38,7 +38,7 @@
{{ button_to(url_for('EventView:delete', id=event.id), - class="btn bg-color-secondary-action color-white w-100 ", value="smazat akci " ~ icon("delete"), confirmation="Opravdu chcete smazat akci?") }} + class="btn bg-color-secondary-action color-white w-100 ", value="smazat akci " ~ icon("delete"), confirmation="opravdu chceš smazat akci?") }}
-
\ No newline at end of file +
diff --git a/app/templates/events/_other_options.html.j2 b/app/templates/events/_other_options.html.j2 index 858aef15..0335ccf4 100644 --- a/app/templates/events/_other_options.html.j2 +++ b/app/templates/events/_other_options.html.j2 @@ -5,7 +5,7 @@
{{ button_to(url_for('EventView:duplicate', id=event.id), - class="btn bg-color-secondary-action color-white w-100", value="zkopírovat" + icon('duplicate')) }} + class="btn bg-color-secondary-action color-white w-100", value="zkopírovat " + icon('duplicate')) }}
@@ -16,4 +16,4 @@
-
\ No newline at end of file +
diff --git a/app/templates/events/_sharing.html.j2 b/app/templates/events/_sharing.html.j2 index c0572177..77c0d079 100644 --- a/app/templates/events/_sharing.html.j2 +++ b/app/templates/events/_sharing.html.j2 @@ -2,18 +2,17 @@ sdílení
{% for event_role in event.user_roles %} -
-
- {{ event_role.user.email }} {{ icon(event_role.role) }} -
-
- {% if event.can_current_user_share %} - {{ button_to(url_for('ShareEventView:remove_sharing', event_id=event.id, user_id=event_role.user.id), - class="btn", style="color:white; background-color: #A66A6A", value="odebrat práva" ~ icon('delete')) }} - {% endif %} +
+
+ {{ event_role.user.email }} {{ icon(event_role.role) }} +
+
+ {% if event.can_current_user_share %} + {{ button_to(url_for('ShareEventView:remove_sharing', event_id=event.id, user_id=event_role.user.id), + class="btn", style="color:white; background-color: #A66A6A", value="odebrat práva" ~ icon('delete')) }} + {% endif %} +
-
-
{% endfor %} {% if event.is_shared %} diff --git a/app/templates/events/_warnings.html.j2 b/app/templates/events/_warnings.html.j2 index a24335df..cb3db017 100644 --- a/app/templates/events/_warnings.html.j2 +++ b/app/templates/events/_warnings.html.j2 @@ -5,9 +5,7 @@ or event.no_category_ingredient_recipes or event.recipes_without_category %} -
- -
+

Upozornění

{% if event.zero_amount_ingredient_recipes %} diff --git a/app/templates/events/edit.html.j2 b/app/templates/events/edit.html.j2 index 45042f92..c6f5f841 100644 --- a/app/templates/events/edit.html.j2 +++ b/app/templates/events/edit.html.j2 @@ -17,7 +17,7 @@ {% for week in timetable.all_relevant_days_split_by_weeks %}
{% for day in week %} - {% include("daily_plans/_day_badge.html.j2") %} + {% include("daily_plans/_day_card.html.j2") %} {% endfor %}
{% endfor %} @@ -43,4 +43,4 @@ {% include "events/_other_options.html.j2" %} {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/templates/events/edit/_info.html.j2 b/app/templates/events/edit/_info.html.j2 index 6615938f..0ee620b0 100644 --- a/app/templates/events/edit/_info.html.j2 +++ b/app/templates/events/edit/_info.html.j2 @@ -1,15 +1,13 @@ {% from "macros/render_field.html.j2" import render_field, render_floating_field %} -
- {{ form.csrf_token }} -
+ + {{ form.hidden_tag() }} + +
{{ render_floating_field(form.name) }}
-
-
-
@@ -34,7 +32,6 @@
-
@@ -54,7 +51,7 @@ {% set value =value~" " %} {% endif %} - +
{% endif %}
@@ -63,13 +60,12 @@
- -
- {{ render_field(form.submit, value="uložit změny", class="w-100 bg-color-primary-action color-white mt-0 pt-3 pb-3") }} -
- + +
+ {{ render_field(form.submit, value="uložit změny", class="w-100 bg-color-primary-action color-white mt-0 pt-3 pb-3") }} +
diff --git a/app/templates/events/show.html.j2 b/app/templates/events/show.html.j2 index 45da2a40..8319ff93 100644 --- a/app/templates/events/show.html.j2 +++ b/app/templates/events/show.html.j2 @@ -11,19 +11,16 @@
-
-
{% for week in timetable.all_relevant_days_split_by_weeks %}
{% for day in week %} - {% include("daily_plans/_day_badge.html.j2") %} + {% include("daily_plans/_day_card.html.j2") %} {% endfor %}
{% endfor %}
-
{% if event.can_current_user_edit %} {% include "events/_more_options.html.j2" %} @@ -33,7 +30,7 @@ {% endif %} -{% if event.can_current_user_edit and (event.is_shared or event.shared_with)%} +{% if event.can_current_user_edit and (event.is_shared or event.shared_with) %} {% include "events/_sharing.html.j2" %} {% endif %} @@ -43,4 +40,4 @@ {% include "events/_other_options.html.j2" %} {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/kucharka.py b/kucharka.py index fa85f681..c63582cd 100644 --- a/kucharka.py +++ b/kucharka.py @@ -10,18 +10,12 @@ @application.context_processor def context_processors(): - from app.helpers.context_processors import ( - human_format_date, - formatted_amount, - inflect, - ) - from app.models import all_dict as models + from app.helpers.context_processors import context_processors + from app.models import models_dictionary as models from app.forms import IngredientForm, RecipeIngredientForm return dict( - human_format_date=human_format_date, - formatted_amount=formatted_amount, - inflect=inflect, + **context_processors, **models, IngredientForm=IngredientForm, RecipeIngredientForm=RecipeIngredientForm, diff --git a/tests/conftest.py b/tests/conftest.py index 9e5546a7..877898b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,12 +21,10 @@ def app(): @application.context_processor def utility_processor(): - from app.helpers.context_processors import human_format_date, formatted_amount + from app.helpers.context_processors import context_processors + from app.models import models_dictionary as models - return dict( - human_format_date=human_format_date, - formatted_amount=formatted_amount, - ) + return dict(**context_processors, **models) return application