Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Render view titles in templates

Marcin Gębala352f50442175
diff --git a/saleor/dashboard/category/views.py b/saleor/dashboard/category/views.py
index 4f0f28697d..5324a766de 100644
--- a/saleor/dashboard/category/views.py
+++ b/saleor/dashboard/category/views.py
@@ -24,7 +24,6 @@ def category_list(request, root_pk=None):
@staff_member_required
def category_create(request, root_pk=None):
category = Category()
- title = _('Add new category')
form = CategoryForm(request.POST or None, initial={'parent': root_pk})
if form.is_valid():
category = form.save()
@@ -35,7 +34,7 @@ def category_create(request, root_pk=None):
return redirect('dashboard:category-list')
elif form.errors:
messages.error(request, _('Failed to save category'))
- ctx = {'category': category, 'form': form, 'title': title}
+ ctx = {'category': category, 'form': form}
return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
@@ -43,7 +42,6 @@ def category_create(request, root_pk=None):
def category_edit(request, pk=None):
category = get_object_or_404(Category, pk=pk)
root = category.parent
- title = category.name
form = CategoryForm(request.POST or None,
instance=category,
initial={'parent': root})
@@ -56,7 +54,7 @@ def category_edit(request, pk=None):
return redirect('dashboard:category-list')
elif form.errors:
messages.error(request, _('Failed to save category'))
- ctx = {'category': category, 'form': form, 'title': title}
+ ctx = {'category': category, 'form': form}
return TemplateResponse(request, 'dashboard/category/detail.html', ctx)
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index f78ab5617e..ba90f62450 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -28,7 +28,6 @@ def product_list(request):
@staff_member_required
def product_create(request):
product = Product()
- title = _('Add new product')
form = forms.ProductForm(request.POST or None, instance=product)
if form.is_valid():
product = form.save()
@@ -38,7 +37,7 @@ def product_create(request):
elif form.errors:
messages.error(request, _('Your submitted data was not valid - '
'please correct the errors below'))
- ctx = {'product_form': form, 'product': product, 'title': title}
+ ctx = {'product_form': form, 'product': product}
return TemplateResponse(request, 'dashboard/product/product_form.html', ctx)
@@ -67,8 +66,8 @@ def product_edit(request, pk):
ctx = {'attributes': attributes, 'images': images, 'product_form': form,
'product': product, 'stock_delete_form': stock_delete_form,
- 'stock_items': stock_items, 'title': product.name,
- 'variants': variants, 'variants_delete_form': variants_delete_form}
+ 'stock_items': stock_items, 'variants': variants,
+ 'variants_delete_form': variants_delete_form}
return TemplateResponse(request, 'dashboard/product/product_form.html', ctx)
@@ -262,10 +261,8 @@ def attribute_list(request):
def attribute_edit(request, pk=None):
if pk:
attribute = get_object_or_404(ProductAttribute, pk=pk)
- title = attribute.display
else:
attribute = ProductAttribute()
- title = _('Add new attribute')
form = forms.ProductAttributeForm(request.POST or None, instance=attribute)
formset = forms.AttributeChoiceValueFormset(request.POST or None,
request.FILES or None,
@@ -279,8 +276,7 @@ def attribute_edit(request, pk=None):
elif any([form.errors, formset.errors]):
messages.error(request, _('Your submitted data was not valid - '
'please correct the errors below'))
- ctx = {'attribute': attribute, 'form': form, 'formset': formset,
- 'title': title}
+ ctx = {'attribute': attribute, 'form': form, 'formset': formset}
return TemplateResponse(request, 'dashboard/product/attributes/form.html',
ctx)
diff --git a/saleor/dashboard/templates/dashboard/category/detail.html b/saleor/dashboard/templates/dashboard/category/detail.html
index cda2ebb041..62e6fc616a 100644
--- a/saleor/dashboard/templates/dashboard/category/detail.html
+++ b/saleor/dashboard/templates/dashboard/category/detail.html
@@ -3,7 +3,7 @@
{% load i18n %}
{% load mptt_tags %}
-{% block title %}{{ title }} - {% trans 'Categories' %} - {{ block.super }}{% endblock %}
+{% block title %}{% if category.pk %}{{ category }}{% else %}{% trans 'Add new category' %}{% endif %} - {% trans 'Categories' %} - {{ block.super }}{% endblock %}
{% block custom_css %}
<style type="text/css">
@@ -16,7 +16,7 @@
{% block body_class %}body-categories{% endblock %}
-{% block page_title %}{{ title }}{% endblock %}
+{% block page_title %}{% if category.pk %}{{ category }}{% else %}{% trans 'Add new category' %}{% endif %}{% endblock %}
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--with-menu">
@@ -26,7 +26,7 @@
<li><a href="{% url 'dashboard:category-list' root_pk=node.pk %}">{{ node.name }}</a></li>
{% endfor %}
{% endif %}
- <li>{{ title }}</li>
+ <li>{% if category.pk %}{{ category }}{% else %}{% trans 'Add new category' %}{% endif %}</li>
</ul>
{% endblock %}
diff --git a/saleor/dashboard/templates/dashboard/product/attributes/form.html b/saleor/dashboard/templates/dashboard/product/attributes/form.html
index f2ca68a6a7..d0d0b6e20f 100644
--- a/saleor/dashboard/templates/dashboard/product/attributes/form.html
+++ b/saleor/dashboard/templates/dashboard/product/attributes/form.html
@@ -3,7 +3,7 @@
{% load materializecss %}
{% load static %}
-{% block title %}{{ title }} - {% trans "Attributes" %} - {{ block.super }}{% endblock %}
+{% block title %}{% if attribute.pk %}{{ attribute }}{% else %}{% trans 'Add new attribute' %}{% endif %} - {% trans "Attributes" %} - {{ block.super }}{% endblock %}
{% block body_class %}body-store body-attributes{% endblock %}
@@ -19,7 +19,7 @@
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--with-menu">
<li><a href="{% url 'dashboard:product-attributes' %}">{% trans "Attributes" %}</a></li>
- <li>{{ title }}</li>
+ <li>{% if attribute.pk %}{{ attribute }}{% else %}{% trans 'Add new attribute' %}{% endif %}</li>
</ul>
{% endblock %}
diff --git a/saleor/dashboard/templates/dashboard/product/product_form.html b/saleor/dashboard/templates/dashboard/product/product_form.html
index 23063140e7..2ce62ad677 100644
--- a/saleor/dashboard/templates/dashboard/product/product_form.html
+++ b/saleor/dashboard/templates/dashboard/product/product_form.html
@@ -5,7 +5,7 @@
{% load static %}
{% load attributes %}
-{% block title %}{{ title }} - {% trans "Products" %} - {{ block.super }}{% endblock %}
+{% block title %}{% if product.pk %}{{ product }}{% else %}{% trans 'Add new product' %}{% endif %} - {% trans "Products" %} - {{ block.super }}{% endblock %}
{% block body_class %}body-store body-products{% endblock %}
@@ -32,7 +32,7 @@
{% block breadcrumbs %}
<ul class="breadcrumbs breadcrumbs--with-menu">
<li><a href="{% url "dashboard:product-list" %}">{% trans "Products" %}</a></li>
- <li title="{{ title }}">{{ title }}</li>
+ <li>{% if product.pk %}{{ product }}{% else %}{% trans 'Add new product' %}{% endif %}</li>
</ul>
{% endblock %}