Compare commits

...

7 commits

11 changed files with 68 additions and 15 deletions

View file

@ -7,6 +7,9 @@ on:
permissions:
contents: read
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
jobs:
tests:
name: Python tests

View file

@ -8,6 +8,9 @@ on:
permissions:
contents: read
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
jobs:
update:
name: Update dependencies

View file

@ -196,11 +196,19 @@ USE_TZ = True
STATIC_URL = "static/"
STATIC_ROOT = env("STATIC_ROOT")
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
MEDIA_URL = "media/"
MEDIA_ROOT = BASE_DIR.parent / "media"
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
AUTH_USER_MODEL = "common.User"
LOGIN_URL = "admin:login"

View file

@ -9,7 +9,14 @@ def _collectstatic():
@pytest.fixture()
def live_server(settings, live_server):
settings.STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
settings.STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedStaticFilesStorage",
},
}
return live_server

View file

@ -19,9 +19,6 @@ class BasketForm(forms.ModelForm):
fields = ["payment_method"]
widgets = {"payment_method": forms.RadioSelect}
class Media:
js = ["purchase/js/basket_form.js"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()

View file

@ -23,3 +23,28 @@ window.dispatchChanged = function (element) {
const event = new Event("change", { bubbles: true });
element.dispatchEvent(event);
};
window.onUpdateQuantity = function (event) {
const { target } = event;
const parent = target.closest(".card");
const classes = ["bg-success", "text-white"];
if (target.value > 0) {
parent.classList.add(...classes);
} else {
parent.classList.remove(...classes);
}
};
window.setupEventsListener = function () {
const cards = document.querySelectorAll(".card input");
cards.forEach((item) => {
item.addEventListener("change", window.onUpdateQuantity);
item.addEventListener("keyup", window.onUpdateQuantity);
});
};
document.addEventListener("newUnpriced", function () {
window.setupEventsListener();
});
window.setupEventsListener();

View file

@ -64,4 +64,5 @@
{% block extrascript %}
<script src="{% static 'vendor/htmx-1.8.6/htmx.min.js' %}" defer></script>
{% django_htmx_script %}
<script defer type="application/javascript" src="{% static "purchase/js/basket_form.js" %}"></script>
{% endblock %}

View file

@ -10,7 +10,7 @@
<div class="card-body">
<h5 class="card-title">{% blocktranslate with basket_id=basket.id %}Basket #{{ basket_id }}{% endblocktranslate %}</h5>
<p class="card-text">
{% blocktranslate count counter=basket.items.count %}1 item{% plural %}{{ counter }} items{% endblocktranslate %}<br>
{% blocktranslate count counter=basket.articles_count %}1 item{% plural %}{{ counter }} items{% endblocktranslate %}<br>
{{ basket.price|currency }}<br>
{{ basket.payment_method|default:"-" }}<br>
{% now "Y-m-d" as todays_date %}

View file

@ -1,6 +1,6 @@
{% load crispy_forms_field %}
<div class="col">
<div class="card h-100 bg-success text-white" data-product-id="{{ product.pk }}">
<div class="card h-100 {% if value %}bg-success text-white{% endif %}" data-product-id="{{ product.pk }}">
{% if product.image %}
<img src="{{ product.image.url }}" class="card-img">
{% else %}

View file

@ -269,13 +269,21 @@ def test_baskets_list(live_server: LiveServer, selenium: WebDriver):
]
with freezegun.freeze_time("2022-09-24 19:01:00+0200"):
basket_with_payment_method = BasketWithItemsFactory()
basket_with_payment_method = Basket.objects.priced().get(
pk=basket_with_payment_method.pk,
basket_with_payment_method = (
Basket.objects.priced()
.with_articles_count()
.get(
pk=basket_with_payment_method.pk,
)
)
with freezegun.freeze_time("2022-09-24 19:02:00+0200"):
another_basket = BasketWithItemsFactory()
another_basket = Basket.objects.priced().get(
pk=another_basket.pk,
another_basket = (
Basket.objects.priced()
.with_articles_count()
.get(
pk=another_basket.pk,
)
)
# Login
@ -287,7 +295,7 @@ def test_baskets_list(live_server: LiveServer, selenium: WebDriver):
first_basket = displayed_baskets[0]
text = first_basket.text.replace("\n", " ")
assert f"{another_basket.pk} " in text
expected_articles_count = another_basket.items.count()
expected_articles_count = another_basket.articles_count
assert f" {expected_articles_count} article" in text
expected_price = another_basket.price / 100
assert f" {expected_price:.2f}" in text
@ -299,7 +307,7 @@ def test_baskets_list(live_server: LiveServer, selenium: WebDriver):
second_basket = displayed_baskets[1]
text = second_basket.text.replace("\n", " ")
assert f"{basket_with_payment_method.pk} " in text
expected_articles_count = basket_with_payment_method.items.count()
expected_articles_count = basket_with_payment_method.articles_count
assert f" {expected_articles_count} article" in text
expected_price = basket_with_payment_method.price / 100
assert f" {expected_price:.2f}" in text

View file

@ -90,17 +90,18 @@ def additional_unpriced_product(request: WSGIRequest) -> HttpResponse:
value = request.GET.get("value", 0)
product = get_object_or_404(Product.objects.with_no_fixed_price(), pk=product_id)
context = {"product": product, "value": value}
return render(
res = render(
request,
"purchase/snippets/basket_unpriced_item.html",
context,
)
return trigger_client_event(res, "newUnpriced", after="settle")
@permission_required("purchase.view_basket")
@condition(etag_func=reports_etag, last_modified_func=reports_last_modified)
def list_baskets(request: WSGIRequest) -> HttpResponse:
context = {"baskets": Basket.objects.priced().order_by("-id")}
context = {"baskets": Basket.objects.with_articles_count().priced().order_by("-id")}
return render(request, "purchase/basket_list.html", context)