Skip to content

Commit

Permalink
1. 增加BaseAdmin模型。2. 增加了FieldOptions来提供了部分工人数据的推荐FieldOption配置。
Browse files Browse the repository at this point in the history
Signed-off-by: Sadam·Sadik <[email protected]>
  • Loading branch information
Haoke98 committed Dec 17, 2023
1 parent 05fb6cd commit 74e3a02
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Django 新的动态Admin , 具有异步请求, 异步列表页刷新和加载, U
![](https://haoke98.github.io/DjangoAsyncAdmin/static/digital_world_banner.png)
* [AI实验室](#)
![](https://haoke98.github.io/DjangoAsyncAdmin/static/silk_road_ai_banner.png)
* [过程可视化数据处理引擎](#)
![](docs/static/截屏2023-12-06 17.02.10.png)

## 功能
<table>
Expand Down Expand Up @@ -154,6 +156,14 @@ pip install /path/to/your_project/dist/DjangoAsyncAdmin-6.5.4.tar.gz
<td>版本</td><td colspan="2">说明</td>
</tr>

<tr>
<td rowspan="1">6.11.0</td>
<td colspan="2">
1. 增加BaseAdmin模型。<br>
2. 增加了FieldOptions来提供了部分工人数据的推荐FieldOption配置。
</td>
</tr>

<tr>
<td rowspan="1">6.10.0</td>
<td colspan="2">
Expand Down
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Django 新的动态Admin , 具有异步请求, 异步列表页刷新和加载, U
![](static/digital_world_banner.png)
* [AI实验室](#)
![](static/silk_road_ai_banner.png)
* [过程可视化数据处理引擎](#)
![](static/截屏2023-12-06 17.02.10.png)


## 功能
<table>
Expand Down
Binary file added docs/static/截屏2023-12-06 17.02.10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "DjangoAsyncAdmin"
version = "6.10.0"
version = "6.11.0"
authors = [
{ name = "Sadam·Sadik", email = "[email protected]" },
]
Expand Down
162 changes: 162 additions & 0 deletions simplepro/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
from django.contrib import admin
from django.utils.html import format_html
from django.utils.safestring import mark_safe

LIST_DISPLAY = ['id', 'updatedAt', 'createdAt']


class FieldOptions:
IP_ADDRESS = {
'min_width': "140px",
'align': 'left'
}
MAC_ADDRESS = {
'min_width': "180px",
'align': 'left'
}
UUID = {
'fixed': 'left',
'min_width': '80px',
'align': 'center',
"show_overflow_tooltip": True
}
REMARK = {
'min_width': '240px',
'align': 'left'
}
DATE_TIME = {
'min_width': '180px',
'align': 'left'
}
DURATION = {
'min_width': '180px',
'align': 'left'
}
USER_NAME = {
'min_width': "148px",
'align': 'left'
}
PASSWORD = {
'min_width': "200px",
'align': 'left'
}
LINK = {
'min_width': "140px",
'align': 'center'
}
PORT = {
'min_width': "102px",
'align': 'center'
}
EMAIL = {
'min_width': "180px",
'align': 'center'
}
MOBILE = {
'min_width': "140px",
'align': 'center'
}


def showUrl(url):
if url:
tag = mark_safe('''<a href="%s" target="blank" class="button" title="%s">URL</a>''' % (url, url))
else:
tag = "-"
return tag


def avatar(url):
return format_html(
'''<img src="{}" width="200px" height="100px" title="点击可浏览" onClick="show_big_img(this)"/>''',
url, )


class BaseAdmin(admin.ModelAdmin):
list_display = LIST_DISPLAY
date_hierarchy = 'updatedAt'

def get_fields(self, request, obj=None):
"""
Hook for specifying fields.
"""
if self.fields:
return self.fields
# _get_form_for_get_fields() is implemented in subclasses.
form = self._get_form_for_get_fields(request, obj)
res = [*form.base_fields, *self.get_readonly_fields(request, obj)]
x = ['remark', 'info']
for i in x:
if i in res:
res.remove(i)
res.append(i)
return res

@staticmethod
def username(value):
return f'''<div style="display:flex;">
<el-input value="{value}" :disabled="false">
<template slot="append">
<el-button style="color:white;border-radius: 0 4px 4px 0;width:40px;display: flex;justify-content: center;align-items: center;" type="primary" icon="el-icon-copy-document" onclick="copyStr('{value}')"></el-button>
</template>
</el-input>
</div>'''

@staticmethod
def password(value):
return f'''<div style="display:flex;">
<el-input value="{value}" :disabled="false" :show-password="true" type="password">
<template slot="append">
<el-button style="color:white;border-radius: 0 4px 4px 0;width:40px;display: flex;justify-content: center;align-items: center;" type="primary" icon="el-icon-copy-document" onclick="copyStr('{value}')"></el-button>
</template>
</el-input>
</div>'''

def shwoUrl(url: str):
tag = mark_safe('''
<a class="ui circular icon red button" href="%s" target="blank">
<i class="linkify icon"></i>
</a>
''' % url)
return tag

class Media:

def __init__(self):
pass

css = {
'all': ()
}
js = [
'js/jquery-3.6.0.min.js',
'js/clipboardUtil.js',
]


class PictureShowAdmin(BaseAdmin):
def __init__(self, model, admin_site):
self.list_display = super().list_display + ['_img']
super().__init__(model, admin_site)

def _img(self, obj):
_url = ""
if hasattr(obj, "originalUrl"):
_url = obj.originalUrl
if hasattr(obj, "cover"):
if hasattr(obj.cover, "originalUrl"):
_url = obj.cover.originalUrl
return format_html(
'''<img src="{}" width="200px" height="100px" title="{}" onClick="show_big_img(this)"/>''',
_url, "%s\n%s" %
(obj.__str__(), _url)

)

_img.short_description = "封面"

class Media:
js = (
'js/jquery-3.6.0.min.js',
'js/imageUtil.js'
)

0 comments on commit 74e3a02

Please sign in to comment.