first push

This commit is contained in:
2025-05-23 14:44:12 +08:00
commit abefd1b19b
817 changed files with 580289 additions and 0 deletions
+193
View File
@@ -0,0 +1,193 @@
<div class="modal-content">
<div class="modal-header bg-dark text-center">
<h5 class="modal-title white w-100" id="myModalLabel160">Add User</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="row">
<div class="col-md-4 col-12">
<div class="form-group">
<label for="first-name-column">姓名</label>
{{form.full_name}}
{% for error in form.full_name.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="last-name-column">邮箱</label>
{{form.email}}
{% for error in form.email.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">电话</label>
{{form.phone}}
{% for error in form.phone.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">部门</label>
{{form.department}}
{% for error in form.department.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">角色</label>
{{form.role}}
{% for error in form.role.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">访问级别</label>
{{form.access_level}}
{% for error in form.access_level.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">密码</label>
{{form.password1}}
{% for error in form.password1.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">重复密码</label>
{{form.password2}}
{% for error in form.password2.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-6 col-12">
<div class="form-group">
<label>地址行1</label>
{{address_form.address_line_one}}
{% for error in address_form.address_line_one.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-6 col-12">
<div class="form-group">
<label>地址行2</label>
{{address_form.address_line_two}}
{% for error in address_form.address_line_two.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>国家</label>
{{address_form.country}}
{% for error in address_form.country.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>省</label>
{{address_form.state}}
{% for error in address_form.state.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>城市</label>
{{address_form.city}}
{% for error in address_form.city.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>邮编</label>
{{address_form.pin_code}}
{% for error in address_form.pin_code.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-8 col-12">
<div class="form-group">
<label for="company-column">办公地点</label>
{{form.location}}
{% for error in form.location.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-8 col-12 d-flex justify-content-between">
<div class="form-group">
<label for="company-column">头像</label>
{{form.profile_pic}}
{% for error in form.profile_pic.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
<div class="form-group rounded ml-2" id="imagePreview"></div>
</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 == "add-user-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 () {
filePreview(this);
});
</script>
+128
View File
@@ -0,0 +1,128 @@
{% extends 'layouts/main-layout.html' %}
{% load static %}
{% 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>User 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">Users</li>
<li class="breadcrumb-item active" aria-current="page">User Details</li>
</ol>
</nav>
</div>
</div>
</div>
<div>
<a href="{% url 'users:list' %}" class="btn btn-sm btn-outline-info my-3">Back to User List</a>
</div>
<div class="page-content">
<section class="row">
<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">
{% if user.profile_pic %}
<img class="w-100 active" src="{{user.profile_pic.url}}">
{% else %}
<img class="w-100 active" src="{% static 'assets/images/faces/1.jpg' %}">
{% endif %}
</div>
<h6 class="my-3">
<i class="bi bi-person-badge"></i>
<span>Contact Information</span>
</h6>
<p><i class="bi bi-telephone-fill"></i>&nbsp; <a href="tel:{{user.phone}}">{{user.phone}}</a> </p>
<p><i class="bi bi-envelope-fill"></i>&nbsp; <a href="mailto:{{user.email}}">{{user.email}}</a> </p>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-8">
<div class="card">
<div class="card-body">
<h6 class="my-3">
<i class="bi bi-person-fill"></i>
<span>Basic Information</span>
</h6>
<table class="table table-borderless">
<tr>
<td><b>Full Name</b></td>
<td>{{user.full_name}}</td>
</tr>
<tr>
<td><b>Designation</b></td>
<td>{{user.role}}</td>
</tr>
<tr>
<td><b>Department</b></td>
<td>{{user.department}}</td>
</tr>
<tr>
<td><b>Status</b></td>
<td>
{% if user.is_active %}
Active
{% else %}
Inactive
{% endif %}
</td>
</tr>
<tr>
<td><b>Address</b></td>
<td>{{user.address}}</td>
</tr>
</table>
</div>
</div>
<div class="card">
<div class="card-body">
<h6 class="my-3">
<i class="bi bi-building"></i>
<span>Company Information</span>
</h6>
<table class="table table-borderless">
<tr>
<td><b>Company Name</b></td>
<td>{{user.location.office_name}}</td>
</tr>
<tr>
<td><b>Company Address</b></td>
<td>{{user.location.address}}</td>
</tr>
<tr>
<td><b>Contact Person Name</b></td>
<td>{{user.location.contact_person_name}}</td>
</tr>
<tr>
<td><b>Contact Person Number</b></td>
<td>{{user.location.contact_person_phone}}</td>
</tr>
<tr>
<td><b>Contact Person Email</b></td>
<td>{{user.location.contact_person_email}}</td>
</tr>
</table>
</div>
</div>
</div>
{% include 'commons/history.html' %}
</section>
</div>
{% endblock content %}
+155
View File
@@ -0,0 +1,155 @@
{% extends 'layouts/main-layout.html' %}
{% block content %}
{% load static %}
<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">Users</li>
</ol>
</nav>
</div>
</div>
</div>
<section class="section">
{% if perms.authentication.add_users %}
<div>
<button type="button" class="btn btn-sm btn-outline-info my-3"
hx-get="{% url 'users:add' %}" hx-target="#add-user-modal-content"
data-bs-toggle="modal" data-bs-target="#add-user-modal">添加用户</button>
</div>
{% endif %}
<!-- Add Modal -->
<div class="modal fade text-left" id="add-user-modal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel160" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div id="add-user-modal-content" class="modal-content" hx-target="this"></div>
</div>
</div>
<!-- update modal -->
<div class="modal fade text-left" id="update-user-modal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel160" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div id="update-user-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 'users: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 'users:export_users_csv' %}"><i class="bi bi-filetype-csv"></i> CSV Format</a>
<a class="dropdown-item" href="{% url 'users:export_users_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>
<th>状态</th>
{% if request.user.is_superuser %}
<th>操作</th>
{% endif %}
{% if perms.authentication.delete_users or perms.authentication.view_users or perms.authentication.edit_users %}
<th>操作</th>
{% endif %}
</tr>
</thead>
{% if page_object %}
<tbody id="search_result">
{% for user in page_object %}
<tr>
<td>{{page_object.start_index|add:forloop.counter0}}</td>
<td>
<div class="user-img d-flex align-items-center">
<div class="avatar avatar-lg">
{% if user.profile_pic %}
<img src="{{user.profile_pic.url}}">
{% else %}
<img src="{% static 'assets/images/faces/1.jpg' %}">
{% endif %}
</div>
</div>
</td>
<td>{{user.full_name | title}}</td>
<td>{{user.email}}</td>
<td>{{user.role}}</td>
<td>
{% if user.access_level %}
All
{% else %}
Only Assigned
{% endif %}
</td>
<td>{{user.last_login}}</td>
{% if request.user.is_superuser %}
<td>
<div class="form-check form-switch">
<input
class="form-check-input"
hx-post="{% url 'users:status' user.id %}"
hx-headers='{"X-CSRFToken":"{{ csrf_token }}"}'
type="checkbox" {% if user.is_active %} checked {% endif %}
style="cursor: pointer;"
>
</div>
</td>
{% endif %}
<td>
<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
{% if perms.authentication.view_users %}
<a href="{% url 'users:details' user.id %}" class="btn btn-success"><i class="bi bi-eye-fill"></i></a>
{% endif %}
{% if perms.authentication.edit_users %}
<button type="button" class="btn btn-info"
hx-get="{% url 'users:update' user.id %}" hx-target="#update-user-modal-content"
data-bs-toggle="modal" data-bs-target="#update-user-modal"
><i class="bi bi-pencil-square"></i></button>
{% endif %}
{% if perms.authentication.delete_users %}
<form action="{% url 'users:delete' user.id %}" method="post" onsubmit="return confirm('Are you sure you want to delete this?')">
{% csrf_token %}
<button type="submit" value="Delete" class="btn btn-sm btn-danger"><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 %}
+183
View File
@@ -0,0 +1,183 @@
{% load static %}
<div class="modal-content">
<div class="modal-header bg-dark text-center">
<h5 class="modal-title white w-100" id="myModalLabel160">Update User</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="row">
<div class="col-md-4 col-12">
<div class="form-group">
<label for="first-name-column">Name</label>
{{form.full_name}}
{% for error in form.full_name.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="last-name-column">Email</label>
{{form.email}}
{% for error in form.email.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">Phone</label>
{{form.phone}}
{% for error in form.phone.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">Department</label>
{{form.department}}
{% for error in form.department.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">Role</label>
{{form.role}}
{% for error in form.role.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label for="company-column">Access Level</label>
{{form.access_level}}
{% for error in form.access_level.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-6 col-12">
<div class="form-group">
<label>Address Line 1</label>
{{address_form.address_line_one}}
{% for error in address_form.address_line_one.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-6 col-12">
<div class="form-group">
<label>Address Line 2</label>
{{address_form.address_line_two}}
{% for error in address_form.address_line_two.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>Country</label>
{{address_form.country}}
{% for error in address_form.country.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>State</label>
{{address_form.state}}
{% for error in address_form.state.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>City</label>
{{address_form.city}}
{% for error in address_form.city.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-4 col-12">
<div class="form-group">
<label>Zip Code</label>
{{address_form.pin_code}}
{% for error in address_form.pin_code.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-8 col-12">
<div class="form-group">
<label for="company-column">Office Location</label>
{{form.location}}
{% for error in form.location.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
</div>
<div class="col-md-8 col-12 d-flex justify-content-between">
<div class="form-group">
<label for="company-column">Profile Picture</label>
{{form.profile_pic}}
{% for error in form.profile_pic.errors %}
<small class="text-danger mb-3">{{ error }}</small>
{% endfor %}
</div>
<div class="form-group rounded" id="imagePreview">
{% if user.profile_pic %}
<img src="{{user.profile_pic.url}}" class="rounded" width="100" height="80" onerror="this.parentElement.innerHTML = '';"/>
{% else %}
<img src="{% static 'assets/images/faces/1.jpg' %}" class="rounded" width="100" height="80"/>
{% endif %}
</div>
</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-user-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>
+70
View File
@@ -0,0 +1,70 @@
{% if page_object %}
{% load static %}
{% for user in page_object %}
<tr>
<td>
{% if page_object.start_index %}
{{page_object.start_index|add:forloop.counter0}}
{% else %}
{{forloop.counter}}
{% endif %}
</td>
<td>
<div class="user-img d-flex align-items-center">
<div class="avatar avatar-lg">
{% if user.profile_pic %}
<img src="{{user.profile_pic.url}}">
{% else %}
<img src="{% static 'assets/images/faces/1.jpg' %}">
{% endif %}
</div>
</div>
</td>
<td>{{user.full_name | title}}</td>
<td>{{user.email}}</td>
<td>{{user.role}}</td>
<td>
{% if user.access_level %}
All
{% else %}
Only Assigned
{% endif %}
</td>
<td>{{user.last_login}}</td>
{% if request.user.is_superuser %}
<td>
<div class="form-check form-switch">
<input
class="form-check-input"
hx-post="{% url 'users:status' user.id %}"
hx-headers='{"X-CSRFToken":"{{ csrf_token }}"}'
type="checkbox" {% if user.is_active %} checked {% endif %}
style="cursor: pointer;"
>
</div>
</td>
{% endif %}
<td>
<div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
{% if perms.authentication.view_users %}
<a href="{% url 'users:details' user.id %}" class="btn btn-success"><i class="bi bi-eye-fill"></i></a>
{% endif %}
{% if perms.authentication.edit_users %}
<button type="button" class="btn btn-info"
hx-get="{% url 'users:update' user.id %}" hx-target="#update-user-modal-content"
data-bs-toggle="modal" data-bs-target="#update-user-modal"
><i class="bi bi-pencil-square"></i></button>
{% endif %}
{% if perms.authentication.delete_users %}
<form action="{% url 'users:delete' user.id %}" method="post" onsubmit="return confirm('Are you sure you want to delete this?')">
{% csrf_token %}
<button type="submit" value="Delete" class="btn btn-sm btn-danger"><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 %}
+60
View File
@@ -0,0 +1,60 @@
{% 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>Email</th>
<th>Phone</th>
<th>Designation</th>
<th>Department</th>
<th>Address</th>
<th>Office Location</th>
</tr>
</thead>
{% if users %}
<tbody>
{% for user in users %}
<tr>
<td style="width: 50%">{{forloop.counter}}</td>
<td>
{% if user.profile_pic %}
<img src="{{user.profile_pic.path}}" width="100" height="80" />
{% else %} Not Uploaded {% endif %}
</td>
<td>{{user.full_name}}</td>
<td>{{user.email}}</td>
<td>{{user.phone}}</td>
<td>{{user.role.related_name}}</td>
<td>{{user.department.name}}</td>
<td>{{user.address}}</td>
<td>{{user.location}}</td>
</tr>
{% endfor %}
</tbody>
{% else %}
<tr>
<td colspan="9">No record available!</td>
</tr>
{% endif %}
</table>
{% endautoescape %}