Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hunter-ht.cn
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘莹莹
hunter-ht.cn
Commits
ca8d19f6
Commit
ca8d19f6
authored
May 21, 2020
by
liuyingying
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
资源存储路径
parent
49e5cb4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
91 deletions
+48
-91
view_api.py
hunter/views/view_api.py
+47
-47
view_page.py
hunter/views/view_page.py
+1
-44
No files found.
hunter/views/view_api.py
View file @
ca8d19f6
...
...
@@ -90,54 +90,54 @@ def profile_submit(request):
def
save_article
(
request
):
userID
=
request
.
POST
.
get
(
'userID'
,
''
)
title
=
request
.
POST
.
get
(
'title'
,
''
)
content
=
request
.
POST
.
get
(
'content'
,
''
)
editdatetime
=
datetime
.
datetime
.
now
()
.
date
()
is_have_file
=
request
.
POST
[
'isHaveFile'
]
link
=
""
# 加入判断题目是否已存在
is_have
=
Articles
.
objects
.
filter
(
title
=
title
)
.
count
()
if
is_have
>
0
:
return
JsonResponse
({
'message'
:
0
,
'error'
:
'该题目已存在'
})
# 是否上传附件
if
int
(
is_have_file
)
>
0
:
myfile
=
request
.
FILES
[
'myfile'
]
if
Articles
.
objects
.
filter
(
attachment
=
myfile
.
name
)
.
count
():
return
JsonResponse
({
'message'
:
0
,
'error'
:
'文件已存在'
})
else
:
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
destination
=
os
.
path
.
join
(
BASE_DIR
,
'hunter'
,
'static'
,
'hunter/articles'
,
myfile
.
name
)
if
os
.
path
.
exists
(
destination
):
os
.
remove
(
destination
)
with
open
(
destination
,
'wb+'
)
as
dest
:
for
chunk
in
myfile
.
chunks
():
dest
.
write
(
chunk
)
dest
.
close
()
link
=
myfile
.
name
# 写入数据库
if
Articles
.
objects
.
last
()
is
None
:
articleID
=
1
userID
=
request
.
POST
.
get
(
'userID'
,
''
)
title
=
request
.
POST
.
get
(
'title'
,
''
)
content
=
request
.
POST
.
get
(
'content'
,
''
)
editdatetime
=
datetime
.
datetime
.
now
()
.
date
()
is_have_file
=
request
.
POST
[
'isHaveFile'
]
link
=
""
# 加入判断题目是否已存在
is_have
=
Articles
.
objects
.
filter
(
title
=
title
)
.
count
()
if
is_have
>
0
:
return
JsonResponse
({
'message'
:
0
,
'error'
:
'该题目已存在'
})
# 是否上传附件
if
int
(
is_have_file
)
>
0
:
myfile
=
request
.
FILES
[
'myfile'
]
if
Articles
.
objects
.
filter
(
attachment
=
myfile
.
name
)
.
count
():
return
JsonResponse
({
'message'
:
0
,
'error'
:
'文件已存在'
})
else
:
articleID
=
Articles
.
objects
.
last
()
.
articleID
+
1
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
destination
=
os
.
path
.
join
(
BASE_DIR
,
'static'
,
'articles'
,
myfile
.
name
)
if
os
.
path
.
exists
(
destination
):
os
.
remove
(
destination
)
with
open
(
destination
,
'wb+'
)
as
dest
:
for
chunk
in
myfile
.
chunks
():
dest
.
write
(
chunk
)
dest
.
close
()
link
=
myfile
.
name
# 判断作者是否存在
try
:
authorID
=
User
.
objects
.
get
(
userID
=
userID
)
except
ObjectDoesNotExist
as
e
:
response
=
JsonResponse
({
"message"
:
0
,
'error'
:
'用户不存在,请检查是否登录'
})
return
response
# 将文章写入数据库
try
:
Articles
.
objects
.
create
(
articleID
=
articleID
,
authorID
=
userID
,
title
=
title
,
content
=
content
,
editDateTime
=
editdatetime
,
attachment
=
link
)
response
=
JsonResponse
({
"message"
:
1
})
except
ProgrammingError
as
e
:
response
=
JsonResponse
({
"message"
:
0
,
'error'
:
'数据库错误'
})
return
response
# 写入数据库
if
Articles
.
objects
.
last
()
is
None
:
articleID
=
1
else
:
articleID
=
Articles
.
objects
.
last
()
.
articleID
+
1
# 判断作者是否存在
try
:
authorID
=
User
.
objects
.
get
(
userID
=
userID
)
except
ObjectDoesNotExist
as
e
:
response
=
JsonResponse
({
"message"
:
0
,
'error'
:
'用户不存在,请检查是否登录'
})
return
response
# 将文章写入数据库
try
:
Articles
.
objects
.
create
(
articleID
=
articleID
,
authorID
=
userID
,
title
=
title
,
content
=
content
,
editDateTime
=
editdatetime
,
attachment
=
link
)
response
=
JsonResponse
({
"message"
:
1
})
except
ProgrammingError
as
e
:
response
=
JsonResponse
({
"message"
:
0
,
'error'
:
'数据库错误'
})
return
response
return
response
# 保存修改后的文章
...
...
@@ -528,4 +528,4 @@ def add_sub_score(request):
return
response
else
:
response
=
JsonResponse
({
"message"
:
"用户不存在"
})
return
response
\ No newline at end of file
return
response
\ No newline at end of file
hunter/views/view_page.py
View file @
ca8d19f6
...
...
@@ -220,49 +220,6 @@ def article_html(request, article_id):
# 写文章页面
def
write_art_html
(
request
):
if
request
.
is_ajax
():
userID
=
request
.
POST
.
get
(
'userID'
,
''
)
title
=
request
.
POST
.
get
(
'title'
,
''
)
content
=
request
.
POST
.
get
(
'content'
,
''
)
editdatetime
=
datetime
.
datetime
.
now
()
.
date
()
is_have_file
=
request
.
POST
[
'isHaveFile'
]
link
=
""
# 加入判断题目是否相同
is_have
=
Articles
.
objects
.
filter
(
title
=
title
)
.
count
()
if
is_have
>
0
:
return
JsonResponse
({
'message'
:
0
,
'error'
:
'该题目已存在'
})
if
int
(
is_have_file
)
>
0
:
myfile
=
request
.
FILES
[
'myfile'
]
if
Articles
.
objects
.
filter
(
attachment
=
myfile
.
name
)
.
count
():
return
JsonResponse
({
'message'
:
0
,
'error'
:
'文件已存在'
})
else
:
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
destination
=
os
.
path
.
join
(
BASE_DIR
,
'hunter'
,
'static'
,
'hunter/articles'
,
myfile
.
name
)
if
os
.
path
.
exists
(
destination
):
os
.
remove
(
destination
)
with
open
(
destination
,
'wb+'
)
as
dest
:
for
chunk
in
myfile
.
chunks
():
dest
.
write
(
chunk
)
dest
.
close
()
link
=
myfile
.
name
if
Articles
.
objects
.
last
()
is
None
:
articleID
=
1
else
:
articleID
=
Articles
.
objects
.
last
()
.
articleID
+
1
try
:
authorID
=
User
.
objects
.
get
(
userID
=
userID
)
except
ObjectDoesNotExist
as
e
:
response
=
JsonResponse
({
"message"
:
0
,
'error'
:
'用户不存在,请检查是否登录'
})
return
response
try
:
Articles
.
objects
.
create
(
articleID
=
articleID
,
authorID
=
userID
,
title
=
title
,
content
=
content
,
editDateTime
=
editdatetime
,
attachment
=
link
)
response
=
JsonResponse
({
"message"
:
1
})
except
ProgrammingError
as
e
:
response
=
JsonResponse
({
"message"
:
0
,
'error'
:
'数据库错误'
})
return
response
return
response
return
render
(
request
,
'write.html'
)
...
...
@@ -277,7 +234,7 @@ def edit_art_html(request, article_id):
def
uploadImg
(
request
):
file_obj
=
request
.
FILES
.
get
(
"image"
)
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
file_path
=
os
.
path
.
join
(
BASE_DIR
,
'
hunter'
,
'
static'
,
'articles/images'
,
file_obj
.
name
)
file_path
=
os
.
path
.
join
(
BASE_DIR
,
'static'
,
'articles/images'
,
file_obj
.
name
)
link_path
=
os
.
path
.
join
(
'/static'
,
'articles/images'
,
file_obj
.
name
)
with
open
(
file_path
,
'wb'
)
as
f
:
for
chunk
in
file_obj
.
chunks
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment