Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add simple product views and templates
Michal Ociepka64c48796fd10
diff --git a/product/templates/product/details.html b/product/templates/product/details.htmlnew file mode 100644index 0000000000..f6a60ccf2d--- /dev/null+++ b/product/templates/product/details.html@@ -0,0 +1,5 @@+{% extends "base.html" %}++{% block content %}+asd+{% endblock content %}diff --git a/product/templates/product/index.html b/product/templates/product/index.htmlnew file mode 100644index 0000000000..4930e46fb0--- /dev/null+++ b/product/templates/product/index.html@@ -0,0 +1,9 @@+{% extends "base.html" %}++{% block content %}+<ul>+ {% for product in products %}+ <li><a href="{{ product.get_absolute_url }}">{{ product }}</a></li>+ {% endfor %}+</ul>+{% endblock content %}diff --git a/product/urls.py b/product/urls.pynew file mode 100644index 0000000000..28e7bf6acd--- /dev/null+++ b/product/urls.py@@ -0,0 +1,9 @@+from django.conf.urls import patterns, url+++urlpatterns = patterns('product.views',+ url(r'^$', 'index', name='index'),+ url(r'^(?P<slug>[a-z-]+?)-(?P<product_id>[0-9]+)/$', 'details',+ name='details'),+)+diff --git a/product/views.py b/product/views.pyindex 60f00ef0ef..40694b98aa 100755--- a/product/views.py+++ b/product/views.py@@ -1 +1,25 @@-# Create your views here.+from .models import Product+from django.http import HttpResponsePermanentRedirect, Http404+from django.template.response import TemplateResponse+++def index(request):+ products = Product.objects.all()++ return TemplateResponse(request, 'product/index.html', {+ 'products': products+ })+++def details(request, slug, product_id):+ try:+ product = Product.objects.get(id=product_id)+ except Product.DoesNotExist:+ return Http404()++ if product.get_slug() != slug:+ return HttpResponsePermanentRedirect(product.get_absolute_url())++ return TemplateResponse(request, 'product/details.html', {+ 'product': product+ })diff --git a/saleor/templates/base.html b/saleor/templates/base.htmlindex 4c974cf529..4eca2cb3b7 100644--- a/saleor/templates/base.html+++ b/saleor/templates/base.html@@ -40,10 +40,7 @@<a href="/">Home</a></li><li>- <a href="#">About</a>- </li>- <li>- <a href="#">Contact</a>+ <a href="{% url "product:index" %}">Products</a></li></ul></div>diff --git a/saleor/urls.py b/saleor/urls.pyindex 22d020e929..81d78250e8 100644--- a/saleor/urls.py+++ b/saleor/urls.py@@ -1,16 +1,11 @@-from django.conf.urls import patterns, url+from django.conf.urls import patterns, url, include+from django.contrib import admin-# Uncomment the next two lines to enable the admin:-# from django.contrib import admin-# admin.autodiscover()++admin.autodiscover()urlpatterns = patterns('',+ url(r'^admin/', include(admin.site.urls)),url(r'^$', 'saleor.views.home', name='home'),- # url(r'^saleor/', include('saleor.foo.urls')),-- # Uncomment the admin/doc line below to enable admin documentation:- # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),-- # Uncomment the next line to enable the admin:- # url(r'^admin/', include(admin.site.urls)),+ url(r'^products/', include('product.urls', namespace='product')))diff --git a/setup.py b/setup.pyindex 46ba652f44..aebc500f85 100755--- a/setup.py+++ b/setup.py@@ -7,6 +7,7 @@ REQUIREMENTS = ['Django == 1.5c1','South >= 0.7.6','satchless',+ 'unidecode',]setup(name='saleor',