Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yuenblue
PythonDemo
提交
79306732
P
PythonDemo
项目概览
yuenblue
/
PythonDemo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PythonDemo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
79306732
编写于
2月 26, 2024
作者:
Y
yuenblue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
aaa
上级
4f61bdcc
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
100 addition
and
50 deletion
+100
-50
democms/adm/forms/article.py
democms/adm/forms/article.py
+15
-5
democms/adm/forms/category.py
democms/adm/forms/category.py
+11
-10
democms/adm/templates/adm/article-index.html
democms/adm/templates/adm/article-index.html
+4
-16
democms/adm/tests/testarticle.py
democms/adm/tests/testarticle.py
+33
-2
democms/adm/urls.py
democms/adm/urls.py
+1
-1
democms/adm/views/article.py
democms/adm/views/article.py
+7
-4
democms/app/settings.py
democms/app/settings.py
+8
-10
democms/common/forms/__init__.py
democms/common/forms/__init__.py
+13
-0
democms/common/models/article.py
democms/common/models/article.py
+4
-2
democms/common/models/category.py
democms/common/models/category.py
+4
-0
未找到文件。
democms/adm/forms/article.py
浏览文件 @
79306732
from
django
import
forms
from
common.models
import
ArticleSummary
,
ArticleContent
from
django.core.paginator
import
Paginator
from
common.forms
import
ToppingSelect
from
common.models
import
Category
from
..caches
import
cache_category
class
ArticleIndexForm
(
forms
.
Form
):
"""CategoryIndexForm definition."""
catid
=
forms
.
IntegerField
()
status
=
forms
.
IntegerField
()
keywords
=
forms
.
CharField
(
max_length
=
25
)
page
=
forms
.
IntegerField
()
catid
=
forms
.
ModelChoiceField
(
queryset
=
None
,
label
=
"所属栏目"
,
help_text
=
"请选择栏目"
,
widget
=
ToppingSelect
(
attrs
=
{
'class'
:
'form-select'
}),
empty_label
=
"所有栏目"
)
status
=
forms
.
ChoiceField
(
choices
=
ArticleSummary
.
Status
.
choices
,
widget
=
forms
.
Select
(
attrs
=
{
'class'
:
'form-select'
}))
keywords
=
forms
.
CharField
(
max_length
=
25
,
help_text
=
'aaaa'
,
widget
=
forms
.
TextInput
(
attrs
=
{
'class'
:
'form-control'
,
'placeholder'
:
'请输入搜索关键字'
}))
# page = forms.IntegerField()
def
search
(
self
)
->
Paginator
:
paginator
=
Paginator
([
'john'
,
'paul'
,
'george'
,
'ringo'
,
'aaaa'
,
'bbbb'
,
'cccc'
],
3
)
pass
return
paginator
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'catid'
].
queryset
=
cache_category
.
categories
[
'category_order'
][
Category
.
Usage
.
Article
][
"data"
]
class
ArticleSummaryForm
(
forms
.
ModelForm
):
class
Meta
:
...
...
democms/adm/forms/category.py
浏览文件 @
79306732
...
...
@@ -2,17 +2,18 @@ from django import forms
from
common.models
import
Category
from
..caches
import
cache_category
from
django.utils.html
import
format_html
class
ToppingSelect
(
forms
.
Select
):
def
create_option
(
self
,
name
,
value
,
label
,
selected
,
index
,
subindex
=
None
,
attrs
=
None
):
# option = super().create_option(name, value, label, selected, index, subindex, attrs)
# if value:
# option['attrs']['data-price'] = value.instance.order_select
if
value
:
aa
=
"      "
from
common.forms
import
ToppingSelect
# class ToppingSelect(forms.Select):
# def create_option(self, name, value, label, selected, index, subindex=None, attrs=None):
# # option = super().create_option(name, value, label, selected, index, subindex, attrs)
# # if value:
# # option['attrs']['data-price'] = value.instance.order_select
# if value:
# aa="      "
label
=
format_html
(
"%s┊┈┈%s  "
%
(
aa
*
(
value
.
instance
.
layer_select
-
1
),
value
.
instance
.
name
))
option
=
super
().
create_option
(
name
,
value
,
label
,
selected
,
index
,
subindex
,
attrs
)
return
option
#
label = format_html("%s┊┈┈%s  "%(aa*(value.instance.layer_select-1),value.instance.name))
#
option = super().create_option(name, value, label, selected, index, subindex, attrs)
#
return option
class
CategoryIndexForm
(
forms
.
Form
):
"""CategoryIndexForm definition."""
...
...
democms/adm/templates/adm/article-index.html
浏览文件 @
79306732
...
...
@@ -8,27 +8,15 @@
{% block content_filter %}
<form
action=
"{% url 'adm:article-index' %}"
method=
"get"
class=
"row align-items-center "
>
<div
class=
"col-md-auto"
style=
"min-width: 12rem"
>
<select
class=
"form-select"
id=
"floatingselect"
aria-label=
"Default select example"
>
<option
selected
>
所有栏目
</option>
<option
value=
"1"
>
新闻
</option>
<option
value=
"2"
>
组图
</option>
<option
value=
"3"
>
视频
</option>
</select>
{{form.catid}}
</div>
<div
class=
"col-md-auto"
style=
"min-width: 12rem"
>
<select
class=
"form-select"
id=
"floatingselect2"
aria-label=
"Default select example"
>
<option
selected
>
所有状态
</option>
<option
value=
"1"
>
待审核
</option>
<option
value=
"2"
>
审核成功
</option>
<option
value=
"3"
>
审核失败
</option>
<option
value=
"3"
>
编辑中
</option>
<option
value=
"3"
>
被丢弃
</option>
</select>
{{form.status}}
</div>
<div
class=
"col"
>
<div
class=
"input-group"
>
<input
type=
"text"
class=
"form-control"
placeholder=
"请输入关键字"
aria-label=
"待搜索关键字"
aria-describedby=
"待搜索关键字"
>
<button
class=
"btn btn-outline-secondary"
type=
"
button
"
id=
"button-addon2"
>
搜索
</button>
{{form.keywords}}
<button
class=
"btn btn-outline-secondary"
type=
"
submit
"
id=
"button-addon2"
>
搜索
</button>
</div>
</div>
</form>
...
...
democms/adm/tests/testarticle.py
浏览文件 @
79306732
import
os
import
unittest
import
random
from
datetime
import
datetime
from
django.utils
import
timezone
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'app.settings'
)
import
django
django
.
setup
()
from
..forms.article
import
ArticleIndexForm
# from article.models import Summary,Content,Additions
from
common.models
import
Category
,
ArticleSummary
class
TestArticle
(
unittest
.
TestCase
):
"""docstring for TestArticle."""
def
testForm
(
self
):
...
...
@@ -14,11 +16,40 @@ class TestArticle(unittest.TestCase):
form
.
full_clean
()
print
(
form
.
search
())
pass
def
testBbb
(
self
):
aa
=
timezone
.
now
()
# aa.tzname
print
(
aa
)
def
testAAa
(
self
):
from
datetime
import
timezone
,
timedelta
aa
=
timezone
(
timedelta
(
hours
=
8
))
aa
.
tzname
(
None
)
bb
=
datetime
.
now
(
aa
)
print
(
bb
.
tzname
())
print
(
bb
.
tzinfo
)
pass
def
test_clear
(
self
):
ArticleSummary
.
objects
.
all
().
delete
()
pass
def
test_create
(
self
):
"""
Purpose:
"""
aa
=
timezone
.
get_current_timezone
()
bb
=
timezone
.
is_aware
(
timezone
.
now
())
for
cat
in
Category
.
objects
.
filter
(
usage
=
Category
.
Usage
.
Article
).
all
():
num
=
random
.
randint
(
3
,
10
)
for
id
in
range
(
1
,
random
.
randint
(
6
,
33
)):
article
=
ArticleSummary
()
article
.
title
=
f
"
{
cat
.
name
}
#
{
id
}
"
article
.
category
=
cat
article
.
status
=
ArticleSummary
.
Status
.
Passed
# article.create_at=str(datetime.now())
# article.update_at=timezone.now()
article
.
save
()
# article.title=f"{}"
pass
pass
# end def
...
...
democms/adm/urls.py
浏览文件 @
79306732
...
...
@@ -9,7 +9,7 @@ category_urlpatterns=[
]
article_urlpatterns
=
[
path
(
'index/'
,
article
.
ArticleIndexView
.
as_view
(),{},
name
=
'article-index'
),
path
(
'pendingcheck/'
,
article
.
ArticleIndexView
.
as_view
(),{
"catid"
:
0
,
'status'
:
2
},
name
=
'article-pendingcheck'
),
#
path('pendingcheck/',article.ArticleIndexView.as_view(),{"catid":0,'status':2},name='article-pendingcheck'),
# path('index/<int:catid>/<int:status>/<int:page>/<str:keywords>/',article.ArticleIndexView.as_view(),{},name='article-search'),
path
(
'edit/<int:id>/'
,
article
.
ArticleEditView
.
as_view
(),
name
=
'article-edit'
),
path
(
'edit/'
,
article
.
ArticleEditView
.
as_view
(),
name
=
'article-create'
),
...
...
democms/adm/views/article.py
浏览文件 @
79306732
from
django.http
import
HttpRequest
from
django.shortcuts
import
render
from
django.views
import
View
from
django.core.paginator
import
Paginator
from
..forms.article
import
ArticleIndexForm
class
ArticleIndexView
(
View
):
def
get
(
self
,
request
:
HttpRequest
,
catid
=
0
,
status
=
0
):
...
...
@@ -8,13 +9,15 @@ class ArticleIndexView(View):
catid
=
request
.
GET
.
get
(
'catid'
,
catid
)
status
=
request
.
GET
.
get
(
'status'
,
status
)
keywords
=
request
.
GET
.
get
(
'keywords'
,
''
)
data
=
{
"catid"
:
catid
,
"status"
:
status
,
'kewords'
:
keywords
,
'page'
:
page
}
data
=
{
"catid"
:
catid
,
"status"
:
status
,
'ke
y
words'
:
keywords
,
'page'
:
page
}
form
=
ArticleIndexForm
(
data
)
return
render
(
request
,
'adm/article-index.html'
,{})
form
.
full_clean
()
paginator
=
form
.
search
()
return
render
(
request
,
'adm/article-index.html'
,{
'form'
:
form
,
"paginator"
:
paginator
})
def
post
(
self
,
request
:
HttpRequest
,
id
=
0
):
pass
form
=
ArticleIndexForm
(
request
.
POST
)
class
ArticleEditView
(
View
):
def
post
(
self
,
request
:
HttpRequest
,
id
=
0
):
...
...
democms/app/settings.py
浏览文件 @
79306732
...
...
@@ -126,11 +126,11 @@ DEFAULT_ADMMENU=[
'sort'
:
1
,
'path'
:
'index'
,
},
{
'name'
:
'待审核'
,
'sort'
:
1
,
'path'
:
'pendingcheck'
,
},
#
{
#
'name':'待审核',
#
'sort':1,
#
'path':'pendingcheck',
#
},
{
'name'
:
'编辑文档'
,
'sort'
:
1
,
...
...
@@ -187,15 +187,13 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE
=
'en-us'
TIME_ZONE
=
'UTC'
LANGUAGE_CODE
=
'zh-hans'
TIME_ZONE
=
'Asia/Shanghai'
USE_I18N
=
True
USE_L10N
=
True
USE_TZ
=
Tru
e
USE_TZ
=
Fals
e
# Static files (CSS, JavaScript, Images)
...
...
democms/common/forms/__init__.py
0 → 100644
浏览文件 @
79306732
from
django
import
forms
from
django.utils.html
import
format_html
class
ToppingSelect
(
forms
.
Select
):
def
create_option
(
self
,
name
,
value
,
label
,
selected
,
index
,
subindex
=
None
,
attrs
=
None
):
# option = super().create_option(name, value, label, selected, index, subindex, attrs)
# if value:
# option['attrs']['data-price'] = value.instance.order_select
if
value
:
aa
=
"      "
label
=
format_html
(
"%s┊┈┈%s  "
%
(
aa
*
(
value
.
instance
.
layer_select
-
1
),
value
.
instance
.
name
))
option
=
super
().
create_option
(
name
,
value
,
label
,
selected
,
index
,
subindex
,
attrs
)
return
option
\ No newline at end of file
democms/common/models/article.py
浏览文件 @
79306732
from
django.utils
import
timezone
from
django.db
import
models
from
.category
import
Category
from
.tag
import
Tag
...
...
@@ -6,6 +7,7 @@ class ArticleSummary(models.Model):
"""Model definition for Summary."""
class
Status
(
models
.
IntegerChoices
):
"""docstring for Status."""
All
=
0
,
"所有状态"
Unfinished
=
1
,
"编辑中"
PendingCheck
=
2
,
"待审核"
Refused
=
3
,
"审核失败"
...
...
@@ -18,8 +20,8 @@ class ArticleSummary(models.Model):
description
=
models
.
CharField
(
max_length
=
150
)
category
=
models
.
ForeignKey
(
Category
,
on_delete
=
models
.
CASCADE
)
tags
=
models
.
ManyToManyField
(
Tag
)
create_at
=
models
.
DateTimeField
(
auto_now
=
False
,
auto_now_add
=
False
)
update_at
=
models
.
DateTimeField
(
auto_now
=
False
,
auto_now_add
=
False
)
create_at
=
models
.
DateTimeField
(
default
=
timezone
.
now
()
)
update_at
=
models
.
DateTimeField
(
default
=
timezone
.
now
()
)
status
=
models
.
IntegerField
(
choices
=
Status
.
choices
,
default
=
Status
.
Unfinished
)
...
...
democms/common/models/category.py
浏览文件 @
79306732
from
django.db
import
models
import
datetime
# from .fields import FieldGroup
# class ContentClasses(models.Model):
...
...
@@ -57,6 +58,9 @@ class Category(models.Model):
seo_keywords
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
seo_description
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
)
content
=
models
.
TextField
(
blank
=
True
)
create_at
=
models
.
DateTimeField
(
auto_now
=
False
,
auto_now_add
=
True
,
null
=
True
)
update_at
=
models
.
DateTimeField
(
auto_now
=
True
,
auto_now_add
=
False
,
null
=
True
)
# filed_group = models.ForeignKey(FieldGroup, on_delete=models.CASCADE,blank=True)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录