Skip to content

Commit 85ba2b7

Browse files
committed
Wip design
1 parent 40a160d commit 85ba2b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4318
-3189
lines changed

bakeup/core/views.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def dispatch(self, request, *args, **kwargs):
1717

1818

1919
class CustomerRequiredMixin(AccessMixin):
20+
login_url = 'shop:login'
21+
2022
def dispatch(self, request, *args, **kwargs):
2123
if request.user.is_authenticated and hasattr(request.user, 'customer'):
2224
return super().dispatch(request, *args, **kwargs)

bakeup/shop/models.py

+14
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ def get_absolute_url(self):
5555

5656
def has_products_open_for_order(self):
5757
return self.production_day_products.filter(production_plan__isnull=True).exists()
58+
59+
def get_random_product_image(self):
60+
product = self.production_day_products.published().exclude(
61+
Q(product__image='')|
62+
Q(product__image=None)).order_by('?').first()
63+
if product:
64+
return product.product.image
5865

5966
@property
6067
def calendar_week(self):
@@ -142,13 +149,20 @@ def get_ingredient_summary_list(self):
142149
return collections.OrderedDict(sorted(ingredients.items(), key=lambda t: t[0].path))
143150

144151

152+
class ProductionDayProductQuerySet(models.QuerySet):
153+
def published(self):
154+
return self.filter(is_published=True)
155+
156+
145157
class ProductionDayProduct(CommonBaseClass):
146158
production_day = models.ForeignKey('shop.ProductionDay', on_delete=models.CASCADE, related_name='production_day_products')
147159
product = models.ForeignKey('workshop.Product', on_delete=models.PROTECT, related_name='production_days', limit_choices_to={'is_sellable': True})
148160
max_quantity = models.PositiveSmallIntegerField(blank=False, null=False)
149161
production_plan = models.ForeignKey('workshop.ProductionPlan', on_delete=models.SET_NULL, blank=True, null=True)
150162
is_published = models.BooleanField(default=False, verbose_name="Published?")
151163

164+
objects = ProductionDayProductQuerySet.as_manager()
165+
152166
class Meta:
153167
ordering = ('production_day', 'product')
154168
unique_together = ['production_day', 'product']

bakeup/shop/urls.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from bakeup.shop.views import CustomerOrderUpdateView, CustomerOrderAddView, CustomerOrderListView, ProductListView, ShopView, ProductionDayWeeklyView, CustomerOrderPositionDeleteView, CustomerOrderAddBatchView, CustomerOrderPositionUpdateView
44

5+
from bakeup.users.views import LoginView, TokenLoginView, SignupView
56
from bakeup.users.views import (
67
shop_user_profile_view,
78
shop_user_update_view,
@@ -23,6 +24,8 @@
2324
path("orders/positions/<int:pk>/update/", view=CustomerOrderPositionUpdateView.as_view(), name="customer-order-position-update"),
2425
path("orders/", view=CustomerOrderListView.as_view(), name="order-list"),
2526
path("profile/", view=shop_user_update_view, name="user-profile"),
27+
path("login/", view=LoginView.as_view(), name="login"),
28+
path("signup/", view=SignupView.as_view(), name="signup"),
2629
# path("product/add/", view=ProductAddView.as_view(), name="product-add"),
2730
# path("product/<int:pk>/", view=ProductDetailView.as_view(), name="product-detail"),
2831
# path("product/", view=ProductListView.as_view(), name="product-list"),

bakeup/shop/views.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class CustomerOrderAddBatchView(CustomerRequiredMixin, FormView):
115115

116116
def get_form_kwargs(self):
117117
kwargs = super().get_form_kwargs()
118-
kwargs['production_day_products'] = self.production_day.production_day_products.filter(is_published=True).filter(Q(production_plan__isnull=True) | Q(production_plan__state=0))
118+
kwargs['production_day_products'] = self.production_day.production_day_products.published().filter(Q(production_plan__isnull=True) | Q(production_plan__state=0))
119119
kwargs['customer'] = self.request.user.customer
120120
return kwargs
121121

@@ -200,10 +200,10 @@ def get_context_data(self, **kwargs):
200200
customer = None if self.request.user.is_anonymous else self.request.user.customer
201201
if production_day_next:
202202
context['production_day_next'] = production_day_next.production_day
203-
context['production_day_products'] = production_day_next.production_day.production_day_products.filter(is_published=True)
203+
context['production_day_products'] = production_day_next.production_day.production_day_products.published()
204204
context['current_customer_order'] = CustomerOrder.objects.filter(customer=customer, production_day=production_day_next.production_day).first()
205205
production_day_products = []
206-
for production_day_product in production_day_next.production_day.production_day_products.filter(is_published=True):
206+
for production_day_product in production_day_next.production_day.production_day_products.published():
207207
form = production_day_product.get_order_form(customer)
208208
production_day_products.append({
209209
'production_day_product': production_day_product,
@@ -212,6 +212,7 @@ def get_context_data(self, **kwargs):
212212
context['production_day_products'] = production_day_products
213213
context['show_remaining_products'] = self.request.tenant.clientsetting.show_remaining_products
214214
context['point_of_sales'] = PointOfSale.objects.all()
215+
context['production_days'] = ProductionDay.objects.upcoming()
215216
return context
216217

217218

0 commit comments

Comments
 (0)