diff --git a/config/settings/base.py b/config/settings/base.py index afce2dd..67dc186 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -40,6 +40,7 @@ PROJECT_APPS = [ "theme", "tpv", "users", + "web", ] INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + PROJECT_APPS diff --git a/config/urls.py b/config/urls.py index b3e6e57..f388713 100644 --- a/config/urls.py +++ b/config/urls.py @@ -5,7 +5,7 @@ from django.contrib import admin from django.urls import include, path urlpatterns = [ - path("", include("shop.urls")), + path("", include("web.urls", namespace='web')), path("admin/", admin.site.urls), path("api/v1/", include("config.api.v1.urls")), path("watchman/", include("watchman.urls")), diff --git a/shop/tests/web/test_components.py b/shop/tests/web/test_components.py index e53f15f..f862ddf 100644 --- a/shop/tests/web/test_components.py +++ b/shop/tests/web/test_components.py @@ -9,5 +9,5 @@ class TestWebComponents(TestCase, CreateProductsMixin): self.product = self.create_product() def test_list_products_component(self): - response = self.client.get(reverse("shop:list_products")) + response = self.client.get(reverse("web:list_products")) assert response.status_code == 200 diff --git a/shop/tests/web/test_index.py b/shop/tests/web/test_index.py index 2be9f88..6103ae6 100644 --- a/shop/tests/web/test_index.py +++ b/shop/tests/web/test_index.py @@ -9,13 +9,13 @@ class TestIndex(TestCase, CreateProductsMixin): self.product = self.create_product() def test_index_view(self): - response = self.client.get(reverse("shop:index")) + response = self.client.get(reverse("web:index")) assert response.status_code == 200 def test_product_detail_view(self): response = self.client.get( reverse( - "shop:product_detail", + "web:product_detail", kwargs={"pk": self.product.pk, "slug": self.product.slug}, ) ) diff --git a/shop/urls.py b/shop/urls.py index f6be08b..d73d9c9 100644 --- a/shop/urls.py +++ b/shop/urls.py @@ -1,12 +1,6 @@ from django.urls import path -from shop.views import index, list_products, product_detail - app_name = "shop" -urlpatterns = [ - path("", index, name="index"), - path("products///", product_detail, name="product_detail"), - path("shop/components/products/", list_products, name="list_products"), -] +urlpatterns = [] diff --git a/shop/views.py b/shop/views.py index def8369..344461b 100644 --- a/shop/views.py +++ b/shop/views.py @@ -7,7 +7,7 @@ from shop.models import Product class IndexView(TemplateView): - template_name = "shop/index.html" + template_name = "web/index.html" def get_context_data(self, **kwargs): return { @@ -16,7 +16,7 @@ class IndexView(TemplateView): class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin): - template_name = "shop/list_products.html" + template_name = "web/list_products.html" queryset = Product.objects.all() filter_class = ProductFilter @@ -30,7 +30,7 @@ class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin): class ProductDetail(TemplateView): - template_name = "shop/product_detail.html" + template_name = "web/product_detail.html" def get_context_data(self, pk, slug, **kwargs): product = get_object_or_404(Product, pk=pk) diff --git a/users/tests/test_login.py b/users/tests/test_login.py index 0257754..16b6715 100644 --- a/users/tests/test_login.py +++ b/users/tests/test_login.py @@ -27,7 +27,7 @@ class TestLogin(APITestCase): ) assert response.status_code == status.HTTP_302_FOUND - assert response.url == reverse("shop:index") + assert response.url == reverse("web:index") def test_login_get(self): response = self.client.get(reverse("users:login")) @@ -43,11 +43,11 @@ class TestLogin(APITestCase): ) assert response.status_code == status.HTTP_302_FOUND - assert response.url == reverse("shop:index") + assert response.url == reverse("web:index") response = self.client.get(reverse("users:login")) assert response.status_code == status.HTTP_302_FOUND - assert response.url == reverse("shop:index") + assert response.url == reverse("web:index") def test_login_failed(self): response = self.client.post( @@ -70,13 +70,13 @@ class TestLogin(APITestCase): ) assert response.status_code == status.HTTP_302_FOUND - assert response.url == reverse("shop:index") + assert response.url == reverse("web:index") response = self.client.post(reverse("users:logout")) assert response.status_code == status.HTTP_302_FOUND - assert response.url == reverse("shop:index") + assert response.url == reverse("web:index") def test_logout_already_logged_out(self): response = self.client.post(reverse("users:logout")) assert response.status_code == status.HTTP_302_FOUND - assert response.url == reverse("shop:index") + assert response.url == reverse("web:index") diff --git a/users/views.py b/users/views.py index 9317ab5..bec84b1 100644 --- a/users/views.py +++ b/users/views.py @@ -15,7 +15,7 @@ class RedirectionMixin: class LoginView(View, RedirectionMixin): template_name = "users/login.html" - redirect_to = "shop:index" + redirect_to = "web:index" login_form_class = LoginForm def get_login_form(self, request): @@ -40,7 +40,7 @@ class LoginView(View, RedirectionMixin): class LogoutView(View, RedirectionMixin): - redirect_to = "shop:index" + redirect_to = "web:index" def get(self, request, *args, **kwargs): logout_user(request) diff --git a/web/__init__.py b/web/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web/admin.py b/web/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/web/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/web/apps.py b/web/apps.py new file mode 100644 index 0000000..c11daac --- /dev/null +++ b/web/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class WebConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "web" diff --git a/web/migrations/__init__.py b/web/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web/models.py b/web/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/web/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/shop/templates/components/cart/cart_dropdown.html b/web/templates/components/cart/cart_dropdown.html similarity index 100% rename from shop/templates/components/cart/cart_dropdown.html rename to web/templates/components/cart/cart_dropdown.html diff --git a/shop/templates/components/generic/navbar.html b/web/templates/components/generic/navbar.html similarity index 86% rename from shop/templates/components/generic/navbar.html rename to web/templates/components/generic/navbar.html index e00ebc0..ef8784c 100644 --- a/shop/templates/components/generic/navbar.html +++ b/web/templates/components/generic/navbar.html @@ -7,7 +7,7 @@ diff --git a/shop/templates/components/product_card.html b/web/templates/components/product_card.html similarity index 96% rename from shop/templates/components/product_card.html rename to web/templates/components/product_card.html index 93e6d02..c3a78be 100644 --- a/shop/templates/components/product_card.html +++ b/web/templates/components/product_card.html @@ -3,7 +3,7 @@
- + {{ product.name }}
- {{ product.name }}
diff --git a/shop/templates/components/products/list_filters.html b/web/templates/components/products/list_filters.html similarity index 97% rename from shop/templates/components/products/list_filters.html rename to web/templates/components/products/list_filters.html index 100b100..d23e333 100644 --- a/shop/templates/components/products/list_filters.html +++ b/web/templates/components/products/list_filters.html @@ -5,7 +5,7 @@
//", product_detail, name="product_detail"), + path("shop/components/products/", list_products, name="list_products"), +] diff --git a/web/views.py b/web/views.py new file mode 100644 index 0000000..344461b --- /dev/null +++ b/web/views.py @@ -0,0 +1,48 @@ +from django.shortcuts import get_object_or_404 +from django.views.generic import TemplateView + +from shop.filters import ProductFilter +from shop.mixins import FilteredQuerysetMixin, PaginatedQuerysetMixin +from shop.models import Product + + +class IndexView(TemplateView): + template_name = "web/index.html" + + def get_context_data(self, **kwargs): + return { + "title": "Shoppy", + } + + +class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin): + template_name = "web/list_products.html" + queryset = Product.objects.all() + filter_class = ProductFilter + + def get_context_data(self, **kwargs): + qs = self.get_queryset() + products = self.get_paginated_queryset(qs) + + return { + "products": products, + } + + +class ProductDetail(TemplateView): + template_name = "web/product_detail.html" + + def get_context_data(self, pk, slug, **kwargs): + product = get_object_or_404(Product, pk=pk) + + return { + "product": product, + "title": product.name, + "description": product.description, + "image": product.images.first(), + } + + +index = IndexView.as_view() +list_products = ListProducts.as_view() +product_detail = ProductDetail.as_view()