Commit 06391d94 by liuyingying

文章编辑功能

parent 5d885006
......@@ -98,7 +98,6 @@ nav span{
.grey_text{
color: #999999;
font-size:12px;
width:100px;
height:40px;
line-height: 40px;
float: right;
......@@ -128,7 +127,7 @@ textarea{
min-height: 1000px;
}
#textCnt{
padding-right: 10px;
padding: 10px;
}
/* Markdown解析样式 */
blockquote {
......
......@@ -236,6 +236,7 @@ nav>div{
#former_member{
margin-top:30px;
background-color: #ffffff;
border: solid 1px #6e829e;
}
.left-bar{
......
......@@ -166,8 +166,7 @@
<li>{{ art.author }}</li>
<li class="right"><button onclick="deleArt({{ art.articleID }})"><svg t="1587713476030" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4730" width="20" height="20"><path d="M864 128H544v-16a32 32 0 0 0-64 0v16H160a32 32 0 0 0 0 64h704a32 32 0 0 0 0-64z m-64 128a32 32 0 0 0-32 32v592H256V288a32 32 0 0 0-64 0v624a32 32 0 0 0 32 32h576a32 32 0 0 0 32-32V288a32 32 0 0 0-32-32zM416 784V304a32 32 0 0 0-64 0v480a32 32 0 0 0 64 0z m128 0V304a32 32 0 0 0-64 0v480a32 32 0 0 0 64 0z m128 0V304a32 32 0 0 0-64 0v480a32 32 0 0 0 64 0z" fill="#b34340" p-id="4731"></path></svg>
</button></li>
{# <li class="right"><button onclick="editArt({{ art.articleID }})"><svg t="1587711451871" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2741" width="20" height="20"><path d="M863.079412 351.09129a29.2569 29.2569 0 0 1 58.5138 0v555.881108a117.027602 117.027602 0 0 1-117.027601 117.027602H219.427602a117.027602 117.027602 0 0 1-117.027602-117.027602V146.292987a117.027602 117.027602 0 0 1 117.027602-117.027602h380.339706a29.2569 29.2569 0 0 1 0 58.513801H219.427602a58.513801 58.513801 0 0 0-58.513801 58.513801v760.679411a58.513801 58.513801 0 0 0 58.513801 58.513801h585.138009a58.513801 58.513801 0 0 0 58.513801-58.513801V351.09129zM855.414104 10.306913a29.2569 29.2569 0 1 1 44.587516 37.916943l-248.683654 292.569005a29.2569 29.2569 0 1 1-44.587516-37.916943l248.683654-292.569005zM307.198303 526.632692h263.312104a29.2569 29.2569 0 0 1 0 58.513801H307.198303a29.2569 29.2569 0 0 1 0-58.513801z m0 175.541403h409.596606a29.2569 29.2569 0 0 1 0 58.513801H307.198303a29.2569 29.2569 0 0 1 0-58.513801z" p-id="2742" fill="#6e829e"></path></svg>#}
{# </button></li>#}
<li class="right"><a href="{% url 'hunter:edit_art' art.articleID %}" target="_blank">编辑</a></li>
<li class="middle_text right">{{ art.editDateTime }}</li>
<li class="small_text right">{{ art.authorID }}</li>
<li class="small_text right"><a target="_blank" download="{{ art.attachment }}" href="{% static 'hunter/articles/' %}{{ art.attachment }}">{{ art.attachment }}</a></li>
......
......@@ -11,9 +11,13 @@ urlpatterns = [
path('user/edit/profile/<int:user_id>/', views.profile_edit, name='profile_edit'),
path('profile_submit/', views.profile_submit, name='profile_submit'),
path('user/detail/<int:user_id>/', views.detail, name='detail'),
path('write/', views.write_art, name='write_art'),
path('save/edit/article/', views.save_edit_art, name='save_edit_art'),
path('uploadImg/', views.uploadImg, name='uploadImg'),
path('article/<int:article_id>/', views.article, name='article'),
path('edit/article/<int:article_id>/', views.edit_art, name='edit_art'),
path('add/article/url/', views.add_url_article, name='add_url_article'),
path('login/', views.login, name='login'),
path('delete/publication/', views.delete_publication, name='delete_publication'),
......
......@@ -284,7 +284,58 @@ def write_art(request):
except ProgrammingError as e:
response = JsonResponse({"message": 0, 'error': '数据库错误'})
return response
return render(request, 'hunter/write.html')
return render(request, 'hunter/write.html')\
@csrf_exempt
def save_edit_art(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']
articleID = request.POST.get('articleID')
link=""
try:
a = Articles.objects.get(articleID=articleID)
authorID = a.authorID
print(authorID)
print(userID)
if int(authorID) != int(userID):
response = JsonResponse({"message": 0, 'error': '文章作者与当前用户不符'})
return response
except ObjectDoesNotExist as e:
response = JsonResponse({"message": 0, 'error': '文章不存在,请检查链接'})
return response
if int(is_have_file) > 0:
myfile = request.FILES['myfile']
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
try:
Articles.objects.filter(articleID=articleID).update(title=title, content=content,
editDateTime=editdatetime,
attachment=link)
response = JsonResponse({"message": 1})
return response
except ProgrammingError as e:
response = JsonResponse({"message": 0, 'error': '数据库错误'})
return response
else:
try:
Articles.objects.filter(articleID=articleID).update(title=title, content=content,
editDateTime=editdatetime)
response = JsonResponse({"message": 1})
return response
except ProgrammingError as e:
response = JsonResponse({"message": 0, 'error': '数据库错误'})
return response
@csrf_exempt
......@@ -505,3 +556,7 @@ def profile_submit(request):
except ObjectDoesNotExist as e:
return JsonResponse({"message":0,'error':e})
def edit_art(request, article_id):
art = get_object_or_404(Articles, pk=article_id)
return render(request, 'hunter/editArticle.html', {'article': art})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment