Added the user details in the Mia core application.

This commit is contained in:
依瑪貓 2020-08-09 20:47:53 +08:00
parent 229ce011b5
commit c500f15945
4 changed files with 296 additions and 15 deletions

View File

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: mia 1.0\n" "Project-Id-Version: mia 1.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-09 20:20+0800\n" "POT-Creation-Date: 2020-08-09 20:41+0800\n"
"PO-Revision-Date: 2020-08-09 20:21+0800\n" "PO-Revision-Date: 2020-08-09 20:45+0800\n"
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n" "Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
"Language-Team: Traditional Chinese <imacat@mail.imacat.idv.tw>\n" "Language-Team: Traditional Chinese <imacat@mail.imacat.idv.tw>\n"
"Language: Traditional Chinese\n" "Language: Traditional Chinese\n"
@ -100,6 +100,7 @@ msgstr "日期:"
#: mia_core/templates/mia_core/include/period-chooser.html:107 #: mia_core/templates/mia_core/include/period-chooser.html:107
#: mia_core/templates/mia_core/include/period-chooser.html:125 #: mia_core/templates/mia_core/include/period-chooser.html:125
#: mia_core/templates/mia_core/user_detail.html:58
msgid "Confirm" msgid "Confirm"
msgstr "確定" msgstr "確定"
@ -115,40 +116,143 @@ msgstr "從:"
msgid "To:" msgid "To:"
msgstr "到:" msgstr "到:"
#: mia_core/templates/mia_core/user_list.html:28 #: mia_core/templates/mia_core/user_detail.html:35
msgid "The account is not in use."
msgstr "帳號未使用。"
#: mia_core/templates/mia_core/user_detail.html:49
msgid "User Deletion Confirmation"
msgstr "帳號刪除確認"
#: mia_core/templates/mia_core/user_detail.html:54
msgid "Do you really want to delete this user?"
msgstr "您真的要刪掉這個帳號嗎?"
#: mia_core/templates/mia_core/user_detail.html:59
msgid "Cancel"
msgstr "取消"
#: mia_core/templates/mia_core/user_detail.html:69
msgid "Back"
msgstr "回上頁"
#: mia_core/templates/mia_core/user_detail.html:73
msgid "Setting"
msgstr "設定"
#: mia_core/templates/mia_core/user_detail.html:76
msgid "You cannot delete your own account."
msgstr "不能刪除自己的帳號。"
#: mia_core/templates/mia_core/user_detail.html:78
#: mia_core/templates/mia_core/user_detail.html:83
#: mia_core/templates/mia_core/user_detail.html:88
#: mia_core/templates/mia_core/user_detail.html:93
msgid "Delete"
msgstr "刪除"
#: mia_core/templates/mia_core/user_detail.html:81
msgid "You cannot delete this account because it is in use."
msgstr "帳號使用中,不可刪除。"
#: mia_core/templates/mia_core/user_detail.html:86
msgid "This account is already deleted."
msgstr "帳號已刪除。"
#: mia_core/templates/mia_core/user_detail.html:99
msgid "Login ID.:"
msgstr "帳號"
#: mia_core/templates/mia_core/user_detail.html:104
msgid "Name:"
msgstr "姓名"
#: mia_core/templates/mia_core/user_detail.html:110
msgid "This account is disabled."
msgstr "帳號停用。"
#: mia_core/templates/mia_core/user_detail.html:116
msgid "This account is deleted."
msgstr "帳號已刪。"
#: mia_core/templates/mia_core/user_detail.html:122
msgid "This user has not logged in yet."
msgstr "使用者還沒登入過。"
#: mia_core/templates/mia_core/user_detail.html:126
msgid "# of visits:"
msgstr "登入次數:"
#: mia_core/templates/mia_core/user_detail.html:131
msgid "Last visit at:"
msgstr "上次登入時間:"
#: mia_core/templates/mia_core/user_detail.html:136
msgid "IP:"
msgstr "IP:"
#: mia_core/templates/mia_core/user_detail.html:141
msgid "Host:"
msgstr "主機名稱:"
#: mia_core/templates/mia_core/user_detail.html:146
msgid "Country:"
msgstr "國家:"
#: mia_core/templates/mia_core/user_detail.html:147
msgid "(Not Available)"
msgstr "(不可考)"
#: mia_core/templates/mia_core/user_detail.html:152
msgid "Created at:"
msgstr "建檔時間:"
#: mia_core/templates/mia_core/user_detail.html:157
msgid "Created by:"
msgstr "建檔人:"
#: mia_core/templates/mia_core/user_detail.html:162
msgid "Updated at:"
msgstr "更新時間:"
#: mia_core/templates/mia_core/user_detail.html:167
msgid "Updated by:"
msgstr "更新人:"
#: mia_core/templates/mia_core/user_list.html:27
msgid "Account Management" msgid "Account Management"
msgstr "帳號管理" msgstr "帳號管理"
#: mia_core/templates/mia_core/user_list.html:36 #: mia_core/templates/mia_core/user_list.html:35
msgid "New" msgid "New"
msgstr "新增" msgstr "新增"
#: mia_core/templates/mia_core/user_list.html:44 #: mia_core/templates/mia_core/user_list.html:43
msgid "Login ID" msgid "Login ID"
msgstr "帳號" msgstr "帳號"
#: mia_core/templates/mia_core/user_list.html:45 #: mia_core/templates/mia_core/user_list.html:44
msgid "Name" msgid "Name"
msgstr "姓名" msgstr "姓名"
#: mia_core/templates/mia_core/user_list.html:46 #: mia_core/templates/mia_core/user_list.html:45
#: mia_core/templates/mia_core/user_list.html:68 #: mia_core/templates/mia_core/user_list.html:67
msgid "View" msgid "View"
msgstr "查閱" msgstr "查閱"
#: mia_core/templates/mia_core/user_list.html:56 #: mia_core/templates/mia_core/user_list.html:55
msgid "Disabled" msgid "Disabled"
msgstr "停用" msgstr "停用"
#: mia_core/templates/mia_core/user_list.html:59 #: mia_core/templates/mia_core/user_list.html:58
msgid "Deleted" msgid "Deleted"
msgstr "已刪" msgstr "已刪"
#: mia_core/templates/mia_core/user_list.html:62 #: mia_core/templates/mia_core/user_list.html:61
msgid "Not In Use" msgid "Not In Use"
msgstr "未使用" msgstr "未使用"
#: mia_core/templates/mia_core/user_list.html:76 #: mia_core/templates/mia_core/user_list.html:75
msgid "There is currently no data." msgid "There is currently no data."
msgstr "目前沒有資料。" msgstr "目前沒有資料。"

View File

@ -0,0 +1,171 @@
{% extends "base.html" %}
{% comment %}
The Mia Core Application
user_detail.html: The template for the user details
Copyright (c) 2020 imacat.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: imacat@mail.imacat.idv.tw (imacat)
First written: 2020/8/9
{% endcomment %}
{% load i18n %}
{% load mia_core %}
{% block settings %}
{% setvar "title" user.name %}
{% endblock %}
{% block content %}
{% if not user.is_in_use %}
<div class="alert alert-info alert-dismissible fade show">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ _("The account is not in use.")|force_escape }}
</div>
{% endif %}
<!-- the delete confirmation dialog -->
<form action="{% url "mia_core:users.delete" user %}" method="POST">
{% csrf_token %}
<!-- The Modal -->
<div class="modal" id="del-modal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">{{ _("User Deletion Confirmation")|force_escape }}</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">{{ _("Do you really want to delete this user?")|force_escape }}</div>
<!-- Modal footer -->
<div class="modal-footer">
<button class="btn btn-danger" type="submit" name="del-confirm">{{ _("Confirm")|force_escape }}</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ _("Cancel")|force_escape }}</button>
</div>
</div>
</div>
</div>
</form>
<div class="btn-group btn-actions">
<a class="btn btn-primary" role="button" href="{% url "mia_core:users" %}">
<i class="fas fa-chevron-circle-left"></i>
{{ _("Back")|force_escape }}
</a>
<a class="btn btn-primary" role="button" href="{% url "mia_core:users.edit" user %}">
<i class="fas fa-user-cog"></i>
{{ _("Setting")|force_escape }}
</a>
{% if user.login_id == request.user.login_id %}
<button class="btn btn-secondary" type="button" disabled="disabled" title="{{ _("You cannot delete your own account.")|force_escape }}">
<i class="fas fa-trash"></i>
{{ _("Delete")|force_escape }}
</button>
{% elif user.is_in_use %}
<button class="btn btn-secondary" type="button" disabled="disabled" title="{{ _("You cannot delete this account because it is in use.")|force_escape }}">
<i class="fas fa-trash"></i>
{{ _("Delete")|force_escape }}
</button>
{% elif user.is_deleted %}
<button class="btn btn-secondary" type="button" disabled="disabled" title="{{ _("This account is already deleted.")|force_escape }}>">
<i class="fas fa-trash"></i>
{{ _("Delete")|force_escape }}
</button>
{% else %}
<button class="btn btn-danger" type="button" data-toggle="modal" data-target="#del-modal">
<i class="fas fa-trash"></i>
{{ _("Delete")|force_escape }}
</button>
{% endif %}
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Login ID.:")|force_escape }}</div>
<div class="col-sm-10">{{ user.login_id }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Name:")|force_escape }}</div>
<div class="col-sm-10">{{ user.name }}</div>
</div>
{% if user.is_disabled %}
<div class="row form-group">
<div class="col-sm-12">{{ _("This account is disabled.")|force_escape }}</div>
</div>
{% endif %}
{% if user.is_deleted %}
<div class="row form-group">
<div class="col-sm-12">{{ _("This account is deleted.")|force_escape }}</div>
</div>
{% endif %}
{% if not user.visits %}
<div class="row form-group">
<div class="col-sm-12">{{ _("This user has not logged in yet.")|force_escape }}</div>
</div>
{% else %}
<div class="row form-group">
<div class="col-sm-2">{{ _("# of visits:")|force_escape }}</div>
<div class="col-sm-10">{{ user.visits }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Last visit at:")|force_escape }}</div>
<div class="col-sm-10">{{ user.visited_at }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("IP:")|force_escape }}</div>
<div class="col-sm-10">{{ user.visited_ip }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Host:")|force_escape }}</div>
<div class="col-sm-10">{{ user.visited_host }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Country:")|force_escape }}</div>
<div class="col-sm-10">{{ user.visited_country.name|default:_("(Not Available)")|force_escape }}</div>
</div>
{% endif %}
<div class="row form-group">
<div class="col-sm-2">{{ _("Created at:")|force_escape }}</div>
<div class="col-sm-10">{{ account.created_at }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Created by:")|force_escape }}</div>
<div class="col-sm-10">{{ account.created_by }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Updated at:")|force_escape }}</div>
<div class="col-sm-10">{{ account.updated_at }}</div>
</div>
<div class="row form-group">
<div class="col-sm-2">{{ _("Updated by:")|force_escape }}</div>
<div class="col-sm-10">{{ account.updated_by }}</div>
</div>
{% endblock %}

View File

@ -31,8 +31,7 @@ urlpatterns = [
path("users/create", views.todo, name="users.create"), path("users/create", views.todo, name="users.create"),
# TODO: To be done. # TODO: To be done.
path("users/store", views.todo, name="users.store"), path("users/store", views.todo, name="users.store"),
# TODO: To be done. path("users/<user:user>", views.UserView.as_view(), name="users.detail"),
path("users/<user:user>", views.todo, name="users.detail"),
# TODO: To be done. # TODO: To be done.
path("users/<user:user>/edit", views.todo, name="users.edit"), path("users/<user:user>/edit", views.todo, name="users.edit"),
# TODO: To be done. # TODO: To be done.

View File

@ -24,7 +24,8 @@ from django.contrib.messages.views import SuccessMessageMixin
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views.decorators.http import require_POST from django.views.decorators.http import require_POST
from django.views.generic import DeleteView as CoreDeleteView, ListView from django.views.generic import DeleteView as CoreDeleteView, ListView, \
DetailView
from mia_core.models import User from mia_core.models import User
@ -60,6 +61,12 @@ class UserListView(ListView):
queryset = User.objects.order_by("login_id") queryset = User.objects.order_by("login_id")
class UserView(DetailView):
"""The view of a user."""
def get_object(self, queryset=None):
return self.request.resolver_match.kwargs["user"]
# TODO: To be removed. # TODO: To be removed.
def todo(request, **kwargs): def todo(request, **kwargs):
"""A dummy placeholder view for the URL settings that are not """A dummy placeholder view for the URL settings that are not