first push
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title white w-100 text-center" id="myModalLabel160">
|
||||
添加产品
|
||||
</h5>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-close"
|
||||
data-bs-dismiss="modal"
|
||||
aria-label="Close"
|
||||
></button>
|
||||
</div>
|
||||
<form
|
||||
hx-encoding="multipart/form-data"
|
||||
hx-post="{{request.path}}"
|
||||
novalidate
|
||||
>
|
||||
{% csrf_token %}
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>产品类别</label>
|
||||
{{form.product_category}}
|
||||
{% for error in form.product_category.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>产品类型</label>
|
||||
{{form.product_type}}
|
||||
{% for error in form.product_type.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>产品名称</label>
|
||||
{{form.name}}
|
||||
{% for error in form.name.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>制造商</label>
|
||||
{{form.manufacturer}}
|
||||
{% for error in form.manufacturer.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>描述</label>
|
||||
{{form.description}}
|
||||
{% for error in form.description.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between me-4">
|
||||
<div class="form-group" style="width: 50%">
|
||||
<label>产品图片</label>
|
||||
{{form.product_picture}}
|
||||
{% for error in form.product_picture.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="form-group" id="imagePreview"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-light-secondary"
|
||||
data-bs-dismiss="modal"
|
||||
>
|
||||
<i class="bx bx-x d-block d-sm-none"></i>
|
||||
<span class="d-none d-sm-block">关闭</span>
|
||||
</button>
|
||||
|
||||
<button type="submit" class="btn btn-sm btn-info ml-1"
|
||||
onclick="this.innerHTML = `<span class='spinner-grow spinner-grow-sm' role='status' aria-hidden='true'></span> Saving...`;"
|
||||
>
|
||||
<i class="bx bx-check d-block d-sm-none"></i>
|
||||
<span class="d-none d-sm-block">保存</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
htmx.on("htmx:beforeSwap", (e) => {
|
||||
if (
|
||||
e.detail.target.id == "add-product-modal-content" &&
|
||||
!e.detail.xhr.response
|
||||
) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
function filePreview(input) {
|
||||
if (input.files && input.files[0]) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
$("#imagePreview + img").remove();
|
||||
$("#imagePreview").after(
|
||||
'<img src="' +
|
||||
e.target.result +
|
||||
'" class="rounded" width="100" height="80"/>'
|
||||
);
|
||||
};
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
}
|
||||
}
|
||||
$("#inputFile").change(function () {
|
||||
$("#imagePreview img").remove();
|
||||
filePreview(this);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
@@ -0,0 +1,86 @@
|
||||
{% extends 'layouts/main-layout.html' %}
|
||||
{% block content %}
|
||||
<div class="page-heading">
|
||||
<div class="page-title">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 order-md-1 order-last">
|
||||
<h3>Product Details</h3>
|
||||
</div>
|
||||
<div class="col-12 col-md-6 order-md-2 order-first">
|
||||
<nav aria-label="breadcrumb" class="breadcrumb-header float-start float-lg-end">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/">Dashboard</a></li>
|
||||
<li class="breadcrumb-item" aria-current="page">Products</li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Product Details</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<a href="{% url 'products:list' %}" class="btn btn-sm btn-outline-info my-3">Back to Product List</a>
|
||||
</div>
|
||||
<div class="page-content">
|
||||
<section class="row">
|
||||
{% if product.product_picture %}
|
||||
<div class="col-12 col-lg-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row gallery">
|
||||
<div class="col-12 mb-2 py-2 px-2 border">
|
||||
<img class="w-100 active" src="{{product.product_picture.url}}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="col-12 {% if product.product_picture %} col-lg-8 {% endif %}">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h6 class="my-3">
|
||||
<i class="bi bi-display-fill"></i>
|
||||
<span>Product Information</span>
|
||||
</h6>
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
<td><b>Product Name</b></td>
|
||||
<td>{{product.name}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Product Type</b></td>
|
||||
<td>{{product.product_type}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Product Category</b></td>
|
||||
<td>{{product.product_category}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Manufacturer</b></td>
|
||||
<td>{{product.manufacturer}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% if product.description %}
|
||||
{% if product.description|length > 700 %} </div> {% endif %}
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h6 class="my-3">
|
||||
<i class="bi bi-card-text"></i>
|
||||
<span>Product Description</span>
|
||||
</h6>
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
<td>{{product.description|urlize}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% include 'commons/history.html' %}
|
||||
</section>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
@@ -0,0 +1,146 @@
|
||||
{% extends 'layouts/main-layout.html' %}
|
||||
{% block content %}
|
||||
<div class="page-heading">
|
||||
<div class="page-title">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 order-md-1 order-last">
|
||||
<h3>产品</h3>
|
||||
</div>
|
||||
<div class="col-12 col-md-6 order-md-2 order-first">
|
||||
<nav aria-label="breadcrumb" class="breadcrumb-header float-start float-lg-end">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/">Dashboard</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Products</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="section">
|
||||
{% if perms.authentication.add_product %}
|
||||
<div>
|
||||
<button type="button" class="btn btn-sm btn-outline-info my-3"
|
||||
hx-get="{% url 'products:add' %}" hx-target="#add-product-modal-content"
|
||||
data-bs-toggle="modal" data-bs-target="#add-product-modal"
|
||||
>添加产品</i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
<!-- add modal -->
|
||||
<div class="modal fade text-left" id="add-product-modal" tabindex="-1" role="dialog"
|
||||
aria-labelledby="myModalLabel160" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div id="add-product-modal-content" class="modal-content" hx-target="this"></div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- update modal -->
|
||||
<div class="modal fade text-left" id="update-product-modal" tabindex="-1" role="dialog"
|
||||
aria-labelledby="myModalLabel160" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div id="update-product-modal-content" class="modal-content" hx-target="this"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{% if page_object %}
|
||||
<div class="d-flex justify-content-end my-2 gap-2">
|
||||
<input name="search_text" type="search" class='dataTable-input' autocomplete="off" placeholder='Search here...'
|
||||
hx-get="{% url 'products:search' page_object.number %}" hx-trigger="keyup changed delay:500ms, search" hx-target="#search_result">
|
||||
{% if request.user.is_superuser %}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary rounded"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
><i class="bi bi-download"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="{% url 'products:export_products_csv' %}"><i class="bi bi-filetype-csv"></i> CSV Format</a>
|
||||
<a class="dropdown-item" href="{% url 'products:export_products_pdf' %}"><i class="bi bi-filetype-pdf"></i> PDF Format</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<table class="table table-hover" id="table1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>序号</th>
|
||||
<th>产品图片</th>
|
||||
<th>产品名称</th>
|
||||
<th>产品类型</th>
|
||||
<th>产品类别</th>
|
||||
<th>状态</th>
|
||||
{% if perms.authentication.delete_product or perms.authentication.view_product or perms.authentication.edit_product %}
|
||||
<th>操作</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
{% if page_object %}
|
||||
<tbody id="search_result">
|
||||
{% for products in page_object %}
|
||||
<tr>
|
||||
<td>{{page_object.start_index|add:forloop.counter0}}</td>
|
||||
<td>{% if products.product_picture %} <img src="{{products.product_picture.url}}" class="rounded" width="100" height="80" /> {% else %} Not Uploaded {% endif %}</td>
|
||||
<td>{{products.name}}</td>
|
||||
<td>
|
||||
{{products.product_type}}
|
||||
{% if products.product_type.is_deleted %}
|
||||
<i class="bi bi-exclamation-triangle text-warning" title="Product type is deleted, please update."></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{products.product_category}}
|
||||
{% if products.product_category.is_deleted %}
|
||||
<i class="bi bi-exclamation-triangle text-warning" title="Product category is deleted, please update."></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if request.user.is_superuser %}
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
class="form-check-input"
|
||||
hx-post="{% url 'products:status' products.id %}"
|
||||
hx-headers='{"X-CSRFToken":"{{ csrf_token }}"}'
|
||||
type="checkbox" {% if products.status %} checked {% endif %}
|
||||
style="cursor: pointer;"
|
||||
>
|
||||
</div>
|
||||
{% else %}
|
||||
{% if products.status %} Active {% else %} Inactive {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
|
||||
{% if perms.authentication.view_product %}
|
||||
<a href="{% url 'products:details_product' products.id %}" class="btn btn-success"><i class="bi bi-eye-fill"></i></a>
|
||||
{% endif %}
|
||||
{% if perms.authentication.edit_product %}
|
||||
<button type="button" class="btn btn-info"
|
||||
hx-get="{% url 'products:update_product' products.id %}" hx-target="#update-product-modal-content"
|
||||
data-bs-toggle="modal" data-bs-target="#update-product-modal"
|
||||
><i class="bi bi-pencil-square"></i></button>
|
||||
{% endif %}
|
||||
{% if perms.authentication.delete_product %}
|
||||
<form action="{% url 'products:delete_product' products.id %}" method="post" onsubmit="return confirm('Are you sure you want to delete this?')">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-danger btn-sm"><i class="bi bi-trash3-fill"></i></button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
{% else %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
暂无记录
|
||||
</div>
|
||||
{% endif %}
|
||||
</table>
|
||||
{% include 'commons/pagination.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock content%}
|
||||
@@ -0,0 +1,63 @@
|
||||
{% if page_object %}
|
||||
{% for products in page_object %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if page_object.start_index %}
|
||||
{{page_object.start_index|add:forloop.counter0}}
|
||||
{% else %}
|
||||
{{forloop.counter}}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{% if products.product_picture %} <img src="{{products.product_picture.url}}" class="rounded" width="100" height="80" /> {% else %} Not Uploaded {% endif %}</td>
|
||||
<td>{{products.name}}</td>
|
||||
<td>
|
||||
{{products.product_type}}
|
||||
{% if products.product_type.is_deleted %}
|
||||
<i class="bi bi-exclamation-triangle text-warning" title="Product type is deleted, please update."></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{products.product_category}}
|
||||
{% if products.product_category.is_deleted %}
|
||||
<i class="bi bi-exclamation-triangle text-warning" title="Product category is deleted, please update."></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if request.user.is_superuser %}
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
class="form-check-input"
|
||||
hx-post="{% url 'products:status' products.id %}"
|
||||
hx-headers='{"X-CSRFToken":"{{ csrf_token }}"}'
|
||||
type="checkbox" {% if products.status %} checked {% endif %}
|
||||
style="cursor: pointer;"
|
||||
>
|
||||
</div>
|
||||
{% else %}
|
||||
{% if products.status %} Active {% else %} Inactive {% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
|
||||
{% if perms.authentication.view_product %}
|
||||
<a href="{% url 'products:details_product' products.id %}" class="btn btn-success"><i class="bi bi-eye-fill"></i></a>
|
||||
{% endif %}
|
||||
{% if perms.authentication.edit_product %}
|
||||
<button type="button" class="btn btn-info"
|
||||
hx-get="{% url 'products:update_product' products.id %}" hx-target="#update-product-modal-content"
|
||||
data-bs-toggle="modal" data-bs-target="#update-product-modal"
|
||||
><i class="bi bi-pencil-square"></i></button>
|
||||
{% endif %}
|
||||
{% if perms.authentication.delete_product %}
|
||||
<form action="{% url 'products:delete_product' products.id %}" method="post" onsubmit="return confirm('Are you sure you want to delete this?')">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-danger btn-sm"><i class="bi bi-trash3-fill"></i></button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<td colspan="8" class="text-center"> No record found related to your search keyword</td>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,56 @@
|
||||
{% autoescape off %}
|
||||
<style>
|
||||
th,
|
||||
td {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
padding: 3px;
|
||||
background-color: #d6eeee;
|
||||
border-bottom: 2px solid white;
|
||||
}
|
||||
th {
|
||||
background-color: rgb(65, 65, 192);
|
||||
color: white;
|
||||
}
|
||||
@page {
|
||||
size: letter landscape;
|
||||
margin: 0.5cm;
|
||||
}
|
||||
</style>
|
||||
<table style="width: 100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sl No.</th>
|
||||
<th>Image</th>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Category</th>
|
||||
<th>Manufacturer</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% if products %}
|
||||
<tbody>
|
||||
{% for product in products %}
|
||||
<tr>
|
||||
<td style="width: 50%">{{forloop.counter}}</td>
|
||||
<td>
|
||||
{% if product.product_picture %}
|
||||
<img src="{{product.product_picture.path}}" width="100" height="80" />
|
||||
{% else %} Not Uploaded {% endif %}
|
||||
</td>
|
||||
<td>{{product.name}}</td>
|
||||
<td>{{product.product_category.name}}</td>
|
||||
<td>{{product.product_type.name}}</td>
|
||||
<td>{{product.manufacturer}}</td>
|
||||
<td>{{product.description}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="7">No record available!</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
{% endautoescape %}
|
||||
@@ -0,0 +1,111 @@
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title white w-100 text-center" id="myModalLabel160">
|
||||
Update Product
|
||||
</h5>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-close"
|
||||
data-bs-dismiss="modal"
|
||||
aria-label="Close"
|
||||
></button>
|
||||
</div>
|
||||
<form hx-encoding='multipart/form-data' hx-post='{{request.path}}' novalidate>
|
||||
{% csrf_token %}
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Product Category</label>
|
||||
{{form.product_category}}
|
||||
{% for error in form.product_category.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Product Type</label>
|
||||
{{form.product_type}}
|
||||
{% for error in form.product_type.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Product Name</label>
|
||||
{{form.name}}
|
||||
{% for error in form.name.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Manufacturer</label>
|
||||
{{form.manufacturer}}
|
||||
{% for error in form.manufacturer.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
{{form.description}}
|
||||
{% for error in form.description.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between me-4">
|
||||
<div class="form-group" style="width: 50%">
|
||||
<label>Product Image</label>
|
||||
{{form.product_picture}}
|
||||
{% for error in form.product_picture.errors %}
|
||||
<small class="text-danger mb-3">{{ error }}</small>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="imagePreview">
|
||||
{% if product.product_picture %}
|
||||
<img src="{{product.product_picture.url}}" class="rounded" width="100" height="80" onerror="this.parentElement.innerHTML = '';"/>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-light-secondary"
|
||||
data-bs-dismiss="modal"
|
||||
>
|
||||
<i class="bx bx-x d-block d-sm-none"></i>
|
||||
<span class="d-none d-sm-block">Close</span>
|
||||
</button>
|
||||
|
||||
<button type="submit" class="btn btn-sm btn-info ml-1"
|
||||
onclick="this.innerHTML = `<span class='spinner-grow spinner-grow-sm' role='status' aria-hidden='true'></span> Saving...`;"
|
||||
>
|
||||
<i class="bx bx-check d-block d-sm-none"></i>
|
||||
<span class="d-none d-sm-block">Save</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<script>
|
||||
htmx.on("htmx:beforeSwap", (e) => {
|
||||
if (e.detail.target.id == "update-product-modal-content" && !e.detail.xhr.response) {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
function filePreview(input){
|
||||
if (input.files && input.files[0]) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
$('#imagePreview + img').remove();
|
||||
$('#imagePreview').after('<img src="'+e.target.result+'" class="rounded" width="100" height="80"/>');
|
||||
};
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
}
|
||||
}
|
||||
$("#inputFile").change(function () {
|
||||
$('#imagePreview img').remove();
|
||||
filePreview(this);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
Reference in New Issue
Block a user