Skip to content

Commit feed6d2

Browse files
authored
Merge pull request #466 from bruecksen/405-add-previous-next-buttons-to-production-day-chooser-calender-widget
Add prev, next production day buttons to shop calender widget
2 parents caace0f + b2f133a commit feed6d2

File tree

11 files changed

+70
-17
lines changed

11 files changed

+70
-17
lines changed

bakeup/pages/blocks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ def get_context(self, value, parent_context=None):
317317
)
318318
else:
319319
production_days = ProductionDay.objects.published().upcoming().available()
320-
if parent_context and "production_day_next" in parent_context:
320+
if parent_context and "production_day" in parent_context:
321321
production_days = production_days.exclude(
322-
id=parent_context["production_day_next"].pk
322+
id=parent_context["production_day"].pk
323323
)
324324
if value.get("production_day_limit"):
325325
production_days = production_days[: value.get("production_day_limit")]

bakeup/pages/models.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ShopPage(Page):
8888

8989
def get_context(self, request, *args, **kwargs):
9090
context = super().get_context(request, *args, **kwargs)
91-
self.production_day = ProductionDay.get_next_production_day(request.user)
91+
self.production_day = ProductionDay.get_production_day(request.user)
9292
customer = None if request.user.is_anonymous else request.user.customer
9393
context["production_days"] = ProductionDay.objects.upcoming().available_to_user(
9494
request.user
@@ -102,7 +102,13 @@ def get_context(self, request, *args, **kwargs):
102102
context["production_days"] = context["production_days"].exclude(
103103
id=self.production_day.pk
104104
)
105-
context["production_day_next"] = self.production_day
105+
context["production_day"] = self.production_day
106+
context["production_day_next"] = (
107+
self.production_day.get_next_production_day(request.user)
108+
)
109+
context["production_day_prev"] = (
110+
self.production_day.get_prev_production_day(request.user)
111+
)
106112
current_customer_order = CustomerOrder.objects.filter(
107113
customer=customer, production_day=self.production_day
108114
).first()

bakeup/shop/models.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def update_order_positions_product(self, production_plan_product):
310310
positions.update(product=production_plan_product)
311311

312312
@classmethod
313-
def get_next_production_day(cls, user):
313+
def get_production_day(cls, user):
314314
today = datetime.now().date()
315315
production_day_next = ProductionDayProduct.objects.filter(
316316
is_published=True, production_day__day_of_sale__gte=today
@@ -323,6 +323,30 @@ def get_next_production_day(cls, user):
323323
return production_day_next.production_day
324324
return None
325325

326+
def get_next_production_day(self, user):
327+
production_day_next = ProductionDayProduct.objects.filter(
328+
is_published=True, production_day__day_of_sale__gt=self.day_of_sale
329+
)
330+
production_day_next = production_day_next.available_to_user(user)
331+
production_day_next = production_day_next.order_by(
332+
"production_day__day_of_sale"
333+
).first()
334+
if production_day_next:
335+
return production_day_next.production_day
336+
return None
337+
338+
def get_prev_production_day(self, user):
339+
production_day_next = ProductionDayProduct.objects.filter(
340+
is_published=True, production_day__day_of_sale__lt=self.day_of_sale
341+
)
342+
production_day_next = production_day_next.available_to_user(user)
343+
production_day_next = production_day_next.order_by(
344+
"-production_day__day_of_sale"
345+
).first()
346+
if production_day_next:
347+
return production_day_next.production_day
348+
return None
349+
326350

327351
class ProductionDayProductQuerySet(models.QuerySet):
328352
def available_to_user(self, user):

bakeup/shop/views.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def setup(self, request, *args, **kwargs):
281281
pk=kwargs.get("production_day")
282282
)
283283
else:
284-
self.production_day = ProductionDay.get_next_production_day(request.user)
284+
self.production_day = ProductionDay.get_production_day(request.user)
285285

286286
return super().setup(request, *args, **kwargs)
287287

@@ -296,7 +296,13 @@ def get_context_data(self, **kwargs):
296296
self.production_day, customer
297297
)
298298
)
299-
context["production_day_next"] = self.production_day
299+
context["production_day"] = self.production_day
300+
context["production_day_next"] = (
301+
self.production_day.get_next_production_day(self.request.user)
302+
)
303+
context["production_day_prev"] = (
304+
self.production_day.get_prev_production_day(self.request.user)
305+
)
300306
production_day_products = self.production_day.production_day_products.published().available_to_user(
301307
self.request.user
302308
)

bakeup/static/css/project.css

+9
Original file line numberDiff line numberDiff line change
@@ -13226,6 +13226,15 @@ nav .nav-link:hover, nav .nav-link:focus {
1322613226
padding: 0.25rem 0.5rem;
1322713227
}
1322813228

13229+
.input-group-calendar {
13230+
width: 250px;
13231+
}
13232+
@media (max-width: 768px) {
13233+
.input-group-calendar {
13234+
width: 100%;
13235+
}
13236+
}
13237+
1322913238
textarea {
1323013239
margin-bottom: 8px;
1323113240
margin-bottom: 0.5rem;

bakeup/static/css/project.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bakeup/static/sass/project.scss

+6
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ nav {
566566
font-size: .875rem;
567567
padding: 0.25rem 0.5rem;
568568
}
569+
.input-group-calendar {
570+
width: 250px;
571+
@media (max-width: 768px) {
572+
width: 100%;
573+
}
574+
}
569575

570576
textarea {
571577
margin-bottom: .5rem;

bakeup/templates/pages/shop_page.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
{% block page_content %}
3434
{% if page.show_production_day %}
35-
{% if not production_day_next %}
35+
{% if not production_day %}
3636
<div class="row mb-10">
3737
<div class="col">
3838
<div class="card p-4">
@@ -41,7 +41,7 @@
4141
</div>
4242
</div>
4343
{% else %}
44-
{% include "shop/includes/production_day_order.html" with production_day=production_day_next production_day_products=production_day_products %}
44+
{% include "shop/includes/production_day_order.html" with production_day=production_day production_day_products=production_day_products %}
4545
{% endif %}
4646
{% endif %}
4747
{% for block in self.content %}

bakeup/templates/shop/includes/production_day_order.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
<div class="row align-items-start">
1313
<div class="col-12 col-lg-8">
1414
<div class="row">
15-
<div class="col-6 col-md-auto">
15+
<div class="col-auto align-self-center">
1616
<label for="select-production-day-date" class="fs-3 fw-bold anchor">Backtag: </label>
1717
</div>
18-
<div class="col-6 col-md-auto">
18+
<div class="col">
1919
{% csrf_token %}
20-
<div class="input-group">
20+
<div class="input-group input-group-calendar">
21+
<a class="btn bg-white fs-4 border-0 fw-bold{% if not production_day_prev %} disabled{% endif %}" type="button" href="{% if production_day_prev %}{% url 'shop:shop-production-day' production_day=production_day_prev.pk %}{% endif %}"><i class="fas fa-chevron-left"></i></a>
2122
<input id="select-production-day-date" inputmode="none" class="form-control fs-4 fw-bold border-0" data-date="{{ production_day.day_of_sale|date:'d.m.Y' }}'" name="production_day_date">
22-
<span class="input-group-text fs-3 fw-bold border-0 l-h1 bg-white"><i class="fa-solid fa-calendar-days"></i></span>
23+
<span class="input-group-text fs-3 fw-bold border-0 l-h1 bg-white ps-1"><i class="fa-solid fa-calendar-days"></i></span>
24+
<a class="btn bg-white fs-4 fw-bold border-0{% if not production_day_next %} disabled{% endif %}" type="button" href="{% if production_day_next %}{% url 'shop:shop-production-day' production_day=production_day_next.pk %}{% endif %}"><i class="fas fa-chevron-right"></i></a>
2325
</div>
2426
</div>
2527
</div>

bakeup/templates/shop/production_day.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{% block page_content %}
88

9-
{% include "shop/includes/production_day_order.html" with production_day=production_day_next production_day_products=production_day_products %}
9+
{% include "shop/includes/production_day_order.html" with production_day=production_day production_day_products=production_day_products %}
1010
<div class="row">
1111
<div class="col">
1212
<div class="horizontal-ruler">

bakeup/templates/shop/shop.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h2 class="text-shadow">- Nachbarschaftliche Backstube in Berlin - Grünau -</h2
2323
{% endblock jumbotron %}
2424

2525
{% block page_content %}
26-
{% if not production_day_next %}
26+
{% if not production_day %}
2727
<div class="row">
2828
<div class="col">
2929
<div class="alert alert-warning" role="alert">
@@ -33,7 +33,7 @@ <h4 class="alert-heading">Der Shop ist momentan geschlossen!</h4>
3333
</div>
3434
</div>
3535
{% else %}
36-
{% include "shop/includes/production_day_order.html" with production_day=production_day_next production_day_products=production_day_products %}
36+
{% include "shop/includes/production_day_order.html" with production_day=production_day production_day_products=production_day_products %}
3737
{% endif %}
3838
<div class="row">
3939
<div class="col">

0 commit comments

Comments
 (0)