Skip to content

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

Add document style to webpack, refactor code

dominik-zeglen3049b7e28288
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 36b9804781..a10503d106 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -12,7 +12,7 @@ from django.utils.translation import pgettext_lazy
from django_prices.templatetags.prices_i18n import gross
from payments import PaymentStatus
from prices import Price
-from weasyprint import HTML
+from weasyprint import HTML, CSS
from ...core.utils import get_paginator_items
from ...order import OrderStatus
@@ -385,7 +385,8 @@ def order_invoice(request, order_pk, group_pk):
rendered_template = get_template(
'dashboard/order/pdf/invoice.html').render(ctx)
- pdf_file = HTML(string=rendered_template).write_pdf()
+ stylesheet = CSS('saleor/static/assets/document.css')
+ pdf_file = HTML(string=rendered_template).write_pdf(stylesheets=[stylesheet])
response = HttpResponse(pdf_file, content_type='application/pdf')
name = "invoice-%s" % order.id
response['Content-Disposition'] = 'filename=%s' % name
@@ -404,7 +405,8 @@ def order_packing_slip(request, order_pk, group_pk):
ctx['logo'] = f.read().replace('white', '#333')
rendered_template = get_template(
'dashboard/order/pdf/packing_slip.html').render(ctx)
- pdf_file = HTML(string=rendered_template).write_pdf()
+ stylesheet = CSS('saleor/static/assets/document.css')
+ pdf_file = HTML(string=rendered_template).write_pdf(stylesheets=[stylesheet])
response = HttpResponse(pdf_file, content_type='application/pdf')
name = "packing-slip-%s" % order.id
response['Content-Disposition'] = 'filename=%s' % name
diff --git a/saleor/static/dashboard/scss/document.scss b/saleor/static/dashboard/scss/document.scss
new file mode 100644
index 0000000000..3e7363644d
--- /dev/null
+++ b/saleor/static/dashboard/scss/document.scss
@@ -0,0 +1,437 @@
+html {
+ font-family: sans-serif;
+ -ms-text-size-adjust: 100%;
+ -webkit-text-size-adjust: 100%;
+}
+
+body {
+ margin: 0;
+}
+
+details, header {
+ display: block;
+}
+
+[hidden] {
+ display: none;
+}
+
+h1 {
+ font-size: 2em;
+ margin: 0.67em 0;
+}
+
+img {
+ border: 0;
+}
+
+svg:not(:root) {
+ overflow: hidden;
+}
+
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+
+td, th {
+ padding: 0;
+}
+
+html {
+ -webkit-box-sizing: border-box;
+ box-sizing: border-box;
+}
+
+*, :after, :before {
+ -webkit-box-sizing: inherit;
+ box-sizing: inherit;
+}
+
+img.responsive-img {
+ max-width: 100%;
+ height: auto;
+}
+
+table, td, th {
+ border: none;
+}
+
+table {
+ width: 100%;
+ display: table;
+ &.bordered > {
+ tbody > tr, thead > tr {
+ border-bottom: 1px solid #d0d0d0;
+ }
+ }
+ &.highlight > tbody > tr {
+ -webkit-transition: background-color .25s ease;
+ transition: background-color 0.25s ease;
+ &:hover {
+ background-color: #f2f2f2;
+ }
+ }
+}
+
+thead {
+ border-bottom: 1px solid #d0d0d0;
+}
+
+td, th {
+ padding: 15px 5px;
+ display: table-cell;
+ text-align: left;
+ vertical-align: middle;
+ border-radius: 2px;
+}
+
+.left-align {
+ text-align: left;
+}
+
+.right-align {
+ text-align: right;
+}
+
+.left {
+ float: left !important;
+}
+
+.right {
+ float: right !important;
+}
+
+.currency, h6 {
+ color: #9e9e9e !important;
+}
+
+@font-face {
+ font-family: Roboto;
+ src: local(Roboto Thin), url(/static/assets/Roboto-Thin.woff2) format("woff2"), url(/static/assets/Roboto-Thin.woff) format("woff");
+ font-weight: 100;
+}
+
+@font-face {
+ font-family: Roboto;
+ src: local(Roboto Light), url(/static/assets/Roboto-Light.woff2) format("woff2"), url(/static/assets/Roboto-Light.woff) format("woff");
+ font-weight: 300;
+}
+
+@font-face {
+ font-family: Roboto;
+ src: local(Roboto Regular), url(/static/assets/Roboto-Regular.woff2) format("woff2"), url(/static/assets/Roboto-Regular.woff) format("woff");
+ font-weight: 400;
+}
+
+@font-face {
+ font-family: Roboto;
+ src: local(Roboto Medium), url(/static/assets/Roboto-Medium.woff2) format("woff2"), url(/static/assets/Roboto-Medium.woff) format("woff");
+ font-weight: 500;
+}
+
+@font-face {
+ font-family: Roboto;
+ src: local(Roboto Bold), url(/static/assets/Roboto-Bold.woff2) format("woff2"), url(/static/assets/Roboto-Bold.woff) format("woff");
+ font-weight: 700;
+}
+
+html {
+ line-height: 1.5;
+ font-family: Roboto, sans-serif;
+ font-weight: 400;
+ color: rgba(0, 0, 0, 0.87);
+}
+
+h1, h2, h3, h4, h5, h6 {
+ font-weight: 400;
+ line-height: 1.1;
+}
+
+h1 {
+ font-size: 3rem;
+ margin: 1.5rem 0 1.2rem;
+ line-height: 110%;
+}
+
+h2 {
+ line-height: 110%;
+ font-size: 2rem;
+ margin: 1rem 0 0.8rem;
+}
+
+h3 {
+ font-size: 1.5rem;
+ margin: 0.75rem 0 0.6rem;
+ line-height: 110%;
+}
+
+h4 {
+ line-height: 110%;
+ font-size: 1.3rem;
+ margin: 0.65rem 0 0.52rem;
+}
+
+h5 {
+ margin: 0.6rem 0 0.48rem;
+ line-height: 110%;
+}
+
+h6 {
+ line-height: 110%;
+ font-size: 1rem;
+ margin: 0.5rem 0 0.4rem;
+}
+
+::-webkit-input-placeholder, :-ms-input-placeholder, ::-ms-input-placeholder, ::placeholder {
+ color: #fff;
+}
+
+[type=radio] {
+ &:checked, &:not(:checked) {
+ position: absolute;
+ opacity: 0;
+ pointer-events: none;
+ }
+ &:checked + label, &:not(:checked) + label {
+ position: relative;
+ padding-left: 35px;
+ cursor: pointer;
+ display: inline-block;
+ height: 25px;
+ line-height: 25px;
+ font-size: 1rem;
+ -webkit-transition: .28s ease;
+ transition: .28s ease;
+ -webkit-user-select: none;
+ -moz-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+ }
+ &:checked + label {
+ &:after, &:before {
+ border-radius: 50%;
+ }
+ }
+ &:not(:checked) + label {
+ &:after, &:before {
+ border-radius: 50%;
+ }
+ &:after, &:before {
+ border: 2px solid #5a5a5a;
+ }
+ &:after {
+ -webkit-transform: scale(0);
+ transform: scale(0);
+ }
+ }
+ &:checked + label {
+ &:before {
+ border: 2px solid transparent;
+ }
+ &:after {
+ border: 2px solid #26a69a;
+ background-color: #26a69a;
+ -webkit-transform: scale(1.02);
+ transform: scale(1.02);
+ }
+ }
+ &:disabled {
+ &:checked + label:before {
+ background-color: transparent;
+ border-color: rgba(0, 0, 0, 0.42);
+ }
+ &:not(:checked) {
+ + label:before {
+ background-color: transparent;
+ border-color: rgba(0, 0, 0, 0.42);
+ }
+ + label:before {
+ border-color: rgba(0, 0, 0, 0.42);
+ }
+ }
+ + label {
+ color: rgba(0, 0, 0, 0.42);
+ }
+ &:checked + label:after {
+ background-color: rgba(0, 0, 0, 0.42);
+ border-color: #949494;
+ }
+ }
+}
+
+[type=checkbox] {
+ &:checked {
+ position: absolute;
+ opacity: 0;
+ pointer-events: none;
+ }
+ &:not(:checked) {
+ position: absolute;
+ opacity: 0;
+ pointer-events: none;
+ &:disabled + label:before {
+ border: none;
+ background-color: rgba(0, 0, 0, 0.42);
+ }
+ }
+ &:checked {
+ + label:before {
+ top: -4px;
+ left: -5px;
+ width: 12px;
+ height: 22px;
+ border-top: 2px solid transparent;
+ border-left: 2px solid transparent;
+ border-right: 2px solid #26a69a;
+ border-bottom: 2px solid #26a69a;
+ -webkit-transform: rotate(40deg);
+ transform: rotate(40deg);
+ -webkit-backface-visibility: hidden;
+ backface-visibility: hidden;
+ -webkit-transform-origin: 100% 100%;
+ transform-origin: 100% 100%;
+ }
+ &:disabled + label:before {
+ border-right: 2px solid rgba(0, 0, 0, 0.42);
+ border-bottom: 2px solid rgba(0, 0, 0, 0.42);
+ }
+ }
+ &:indeterminate {
+ + label:before {
+ top: -11px;
+ left: -12px;
+ width: 10px;
+ height: 22px;
+ border-top: none;
+ border-left: none;
+ border-right: 2px solid #26a69a;
+ border-bottom: none;
+ -webkit-transform: rotate(90deg);
+ transform: rotate(90deg);
+ -webkit-backface-visibility: hidden;
+ backface-visibility: hidden;
+ -webkit-transform-origin: 100% 100%;
+ transform-origin: 100% 100%;
+ }
+ &:disabled + label:before {
+ border-right: 2px solid rgba(0, 0, 0, 0.42);
+ background-color: transparent;
+ }
+ }
+}
+
+h5 {
+ font-weight: 400;
+ font-size: 1.2rem;
+ text-transform: uppercase;
+ padding-top: 10px;
+}
+
+h6 {
+ font-size: 13px;
+}
+
+.formatted-address {
+ white-space: pre-wrap;
+}
+
+.currency {
+ font-size: 12px;
+ font-weight: 400;
+}
+
+.data-table-header {
+ -webkit-box-align: center;
+ -ms-flex-align: center;
+ align-items: center;
+ display: -webkit-box;
+ display: -ms-flexbox;
+ display: flex;
+ height: 64px;
+}
+
+.data-table {
+ td, th {
+ height: 48px;
+ overflow: hidden;
+ padding: 0 24px;
+ text-overflow: ellipsis;
+ vertical-align: middle;
+ white-space: nowrap;
+ }
+ td:first-child, th:first-child {
+ padding-left: 24px;
+ }
+ td:last-child {
+ padding-right: 24px;
+ }
+ th {
+ &:last-child {
+ padding-right: 24px;
+ }
+ color: #757575;
+ font-weight: 400;
+ font-size: 12px;
+ height: 56px;
+ }
+ tfoot {
+ font-weight: 700;
+ }
+ .wide {
+ width: 99%;
+ }
+}
+
+@media print {
+ html {
+ background-color: #fff;
+ }
+ .data-table th {
+ color: rgba(0, 0, 0, 0.87);
+ }
+}
+
+html, body {
+ font-size: 12px;
+}
+
+.order-table {
+ margin-bottom: 30px;
+}
+
+.data-table {
+ max-width: 100%;
+ width: 100%;
+ tr {
+ border-bottom: 1px #d0d0d0 solid;
+ &:last-child {
+ border-bottom: none;
+ }
+ }
+ td {
+ height: 30px;
+ padding: 10px;
+ }
+}
+
+header {
+ margin-bottom: 5rem;
+}
+
+#invoice-footer {
+ position: fixed;
+ bottom: 0;
+ width: 100%;
+ text-align: center;
+}
+
+@page {
+ @bottom-center {
+ content: "Saleor eCommerce, Mirumee Software";
+ }
+
+ @bottom-right {
+ content: "Page " counter(page) "/" counter(pages);
+ }
+}
diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.html
index 815919bdf5..c35b36f04a 100644
--- a/templates/dashboard/order/pdf/invoice.html
+++ b/templates/dashboard/order/pdf/invoice.html
@@ -2,10 +2,14 @@
{% load prices_i18n %}
{% load discount_amount_for from prices %}
{% load utils %}
+{% load static %}
-{% include 'dashboard/order/pdf/style.html' %}
-
-<header>
+<html>
+<head>
+ <title>Invoice, order ID: {{ order.id }}</title>
+</head>
+<body>
+ <header>
<div style="float:left">
<img src="{{ logo|svg_url|safe }}">
</div>
@@ -158,4 +162,6 @@
{% endif %}
</tbody>
</table>
+</body>
+</html>
diff --git a/templates/dashboard/order/pdf/packing_slip.html b/templates/dashboard/order/pdf/packing_slip.html
index 56ee2162b5..06f3813253 100644
--- a/templates/dashboard/order/pdf/packing_slip.html
+++ b/templates/dashboard/order/pdf/packing_slip.html
@@ -3,8 +3,11 @@
{% load discount_amount_for from prices %}
{% load utils %}
-{% include 'dashboard/order/pdf/style.html' %}
-
+<html>
+<head>
+ <title>Packing slip</title>
+</head>
+<body>
<header>
<div style="float:left">
<img src="{{ logo|svg_url|safe }}">
@@ -77,5 +80,5 @@
</tbody>
</table>
{% endif %}
-
-
+</body>
+</html>
diff --git a/templates/dashboard/order/pdf/style.html b/templates/dashboard/order/pdf/style.html
deleted file mode 100644
index 7623c6fff7..0000000000
--- a/templates/dashboard/order/pdf/style.html
+++ /dev/null
@@ -1,49 +0,0 @@
-<style>
- .currency,h6{color:#9e9e9e!important}html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}details,header{display:block}[hidden]{display:none}h1{font-size:2em;margin:.67em 0}img{border:0}svg:not(:root){overflow:hidden}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}html{-webkit-box-sizing:border-box;box-sizing:border-box}*,:after,:before{-webkit-box-sizing:inherit;box-sizing:inherit}img.responsive-img{max-width:100%;height:auto}table,td,th{border:none}table{width:100%;display:table}table.bordered>tbody>tr,table.bordered>thead>tr{border-bottom:1px solid #d0d0d0}table.highlight>tbody>tr{-webkit-transition:background-color .25s ease;transition:background-color .25s ease}table.highlight>tbody>tr:hover{background-color:#f2f2f2}thead{border-bottom:1px solid #d0d0d0}td,th{padding:15px 5px;display:table-cell;text-align:left;vertical-align:middle;border-radius:2px}.left-align{text-align:left}.right-align{text-align:right}.left{float:left!important}.right{float:right!important}@font-face{font-family:Roboto;src:local(Roboto Thin),url(/static/assets/Roboto-Thin.woff2) format("woff2"),url(/static/assets/Roboto-Thin.woff) format("woff");font-weight:100}@font-face{font-family:Roboto;src:local(Roboto Light),url(/static/assets/Roboto-Light.woff2) format("woff2"),url(/static/assets/Roboto-Light.woff) format("woff");font-weight:300}@font-face{font-family:Roboto;src:local(Roboto Regular),url(/static/assets/Roboto-Regular.woff2) format("woff2"),url(/static/assets/Roboto-Regular.woff) format("woff");font-weight:400}@font-face{font-family:Roboto;src:local(Roboto Medium),url(/static/assets/Roboto-Medium.woff2) format("woff2"),url(/static/assets/Roboto-Medium.woff) format("woff");font-weight:500}@font-face{font-family:Roboto;src:local(Roboto Bold),url(/static/assets/Roboto-Bold.woff2) format("woff2"),url(/static/assets/Roboto-Bold.woff) format("woff");font-weight:700}html{line-height:1.5;font-family:Roboto,sans-serif;font-weight:400;color:rgba(0,0,0,.87)}h1,h2,h3,h4,h5,h6{font-weight:400;line-height:1.1}h1{font-size:3rem;margin:1.5rem 0 1.2rem}h1,h2{line-height:110%}h2{font-size:2rem;margin:1rem 0 .8rem}h3{font-size:1.5rem;margin:.75rem 0 .6rem}h3,h4{line-height:110%}h4{font-size:1.3rem;margin:.65rem 0 .52rem}h5{margin:.6rem 0 .48rem}h5,h6{line-height:110%}h6{font-size:1rem;margin:.5rem 0 .4rem}::-webkit-input-placeholder{color:#fff}:-ms-input-placeholder,::-ms-input-placeholder{color:#fff}::placeholder{color:#fff}[type=radio]:checked,[type=radio]:not(:checked){position:absolute;opacity:0;pointer-events:none}[type=radio]:checked+label,[type=radio]:not(:checked)+label{position:relative;padding-left:35px;cursor:pointer;display:inline-block;height:25px;line-height:25px;font-size:1rem;-webkit-transition:.28s ease;transition:.28s ease;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}[type=radio]:checked+label:after,[type=radio]:checked+label:before,[type=radio]:not(:checked)+label:after,[type=radio]:not(:checked)+label:before{border-radius:50%}[type=radio]:not(:checked)+label:after,[type=radio]:not(:checked)+label:before{border:2px solid #5a5a5a}[type=radio]:not(:checked)+label:after{-webkit-transform:scale(0);transform:scale(0)}[type=radio]:checked+label:before{border:2px solid transparent}[type=radio]:checked+label:after{border:2px solid #26a69a}[type=radio]:checked+label:after{background-color:#26a69a}[type=radio]:checked+label:after{-webkit-transform:scale(1.02);transform:scale(1.02)}[type=radio]:disabled:checked+label:before,[type=radio]:disabled:not(:checked)+label:before{background-color:transparent;border-color:rgba(0,0,0,.42)}[type=radio]:disabled+label{color:rgba(0,0,0,.42)}[type=radio]:disabled:not(:checked)+label:before{border-color:rgba(0,0,0,.42)}[type=radio]:disabled:checked+label:after{background-color:rgba(0,0,0,.42);border-color:#949494}[type=checkbox]:checked,[type=checkbox]:not(:checked){position:absolute;opacity:0;pointer-events:none}[type=checkbox]:not(:checked):disabled+label:before{border:none;background-color:rgba(0,0,0,.42)}[type=checkbox]:checked+label:before{top:-4px;left:-5px;width:12px;height:22px;border-top:2px solid transparent;border-left:2px solid transparent;border-right:2px solid #26a69a;border-bottom:2px solid #26a69a;-webkit-transform:rotate(40deg);transform:rotate(40deg);-webkit-backface-visibility:hidden;backface-visibility:hidden;-webkit-transform-origin:100% 100%;transform-origin:100% 100%}[type=checkbox]:checked:disabled+label:before{border-right:2px solid rgba(0,0,0,.42);border-bottom:2px solid rgba(0,0,0,.42)}[type=checkbox]:indeterminate+label:before{top:-11px;left:-12px;width:10px;height:22px;border-top:none;border-left:none;border-right:2px solid #26a69a;border-bottom:none;-webkit-transform:rotate(90deg);transform:rotate(90deg);-webkit-backface-visibility:hidden;backface-visibility:hidden;-webkit-transform-origin:100% 100%;transform-origin:100% 100%}[type=checkbox]:indeterminate:disabled+label:before{border-right:2px solid rgba(0,0,0,.42);background-color:transparent}h5{font-weight:400;font-size:1.2rem;text-transform:uppercase;padding-top:10px}h6{font-size:13px}.formatted-address{white-space:pre-wrap}.currency{font-size:12px;font-weight:400}.data-table-header{-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-ms-flexbox;display:flex;height:64px}.data-table td,.data-table th{height:48px;overflow:hidden;padding:0 24px;text-overflow:ellipsis;vertical-align:middle;white-space:nowrap}.data-table td:first-child,.data-table th:first-child{padding-left:24px}.data-table td:last-child,.data-table th:last-child{padding-right:24px}.data-table th{color:#757575;font-weight:400;font-size:12px;height:56px}.data-table tfoot{font-weight:700}.data-table .wide{width:99%}@media print{html{background-color:#fff}.data-table th{color:rgba(0,0,0,.87)}}
-
- html, body {
- font-size: 12px;
- }
-
- .order-table {
- margin-bottom: 30px;
- }
-
- .data-table {
- max-width: 100%;
- width: 100%;
- }
-
- .data-table tr {
- border-bottom: 1px #d0d0d0 solid;
- }
-
- .data-table tr:last-child {
- border-bottom: none;
- }
-
- .data-table td {
- height: 30px;
- padding: 10px;
- }
-
- header {
- margin-bottom: 5rem;
- }
-
- #invoice-footer {
- position: fixed;
- bottom: 0;
- width: 100%;
- text-align: center;
- }
-
- @page {
- @bottom-center {
- content: "Saleor eCommerce, Mirumee Software";
- }
- @bottom-right {
- content: "Page " counter(page) "/" counter(pages);
- }
- }
-</style>
diff --git a/webpack.config.js b/webpack.config.js
index 8335c0dae6..3c8e268596 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -62,6 +62,7 @@ var config = {
entry: {
dashboard: './saleor/static/dashboard/js/dashboard.js',
storefront: './saleor/static/js/storefront.js',
+ document: './saleor/static/dashboard/scss/document.scss',
vendor: [
'babel-es6-polyfill',
'bootstrap',