Commit 1bcfb3c0 by liuyingying

天呐好饿

parent 65e908e1
......@@ -82,7 +82,7 @@ button{
color:white;
}
#login_btn, #submit_btn{
background: #ffffff;
background: #6e829e;
font-size: 16px;
}
......@@ -443,7 +443,7 @@ footer .copyright a:hover{
width:100%;
height:50px;
}
#edit_content span{
#edit_content label{
width: 25%;
height: 45px;
float: left;
......@@ -451,7 +451,7 @@ footer .copyright a:hover{
line-height: 45px;
text-align: right;
}
#edit_content input{
#edit_content>form>div>input{
width: 65%;
height: 45px;
font-size: 16px;
......@@ -532,11 +532,39 @@ section > .smaller_box{
.smaller_wrap button{
border:none;
outline: none;
background-image: url("./images/logo.ico");
}
.smaller_wrap blockquote{
padding: 10px 0;
}
.smaller_wrap blockquote>p{
font-size:18px;
}
.add_one{
width:100%;
height:40px;
}
.add_one button{
width:30px;
height:30px;
float: right;
border-radius:15px;
}
.add_one button svg{
margin:5px;
}
.add_one button:hover svg{
width:30px;
height:30px;
border-radius:15px;
margin:0;
}
.myfile{
float: right;
}
.myfile >input{
background: transparent !important;
border: none !important;
outline: none !important;
display: block;
}
\ No newline at end of file
......@@ -66,6 +66,7 @@
</ul>
{% endfor %}
{% endif %}
</div>
{% endfor %}
</div>
......
......@@ -9,5 +9,7 @@ urlpatterns = [
# path('<int:pk>/article/', views.ArticleDetail.as_view(), name='article'),
path('user/<int:user_id>/', views.user, name='user'),
path('article/<int:article_id>/', views.article, name='article'),
path('login/', views.login, name='login')
path('login/', views.login, name='login'),
path('delete/publication/<int:pub_id>', views.delete_publication, name='delete_publication'),
path('add/publication/', views.add_publication, name = 'add_publication'),
]
\ No newline at end of file
......@@ -4,6 +4,10 @@ from .models import *
from django.core.exceptions import ObjectDoesNotExist
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import os
from django.db.utils import ProgrammingError
from django.shortcuts import redirect
from django.core.exceptions import ValidationError
import json
from django.views import generic
from django.db.models.aggregates import Count
......@@ -144,3 +148,56 @@ def user(request, user_id):
def article(request, article_id):
art = get_object_or_404(Articles, pk=article_id)
return render(request, 'hunter/article.html', {'article': art})
def delete_publication(request, pub_id):
print(pub_id)
try:
PubToUser.objects.filter(pubID=pub_id).delete()
Publications.objects.filter(pubID=pub_id).delete()
except ObjectDoesNotExist as e:
response = JsonResponse({"message": 0})
return response
response = JsonResponse({"message": 1})
return response
@csrf_exempt
def add_publication(request):
title = request.POST['title']
print(title)
authors = request.POST['authors']
myfile = request.FILES['myfile']
str=','.decode('utf-8')
authors = authors.replace(str, ',')
journalname = request.POST.get('journalname')
date = request.POST.get('date')
index = request.POST.get('index')
if Publications.objects.last() is None:
pubID = 1
else:
pubID = Publications.objects.last().pubID+1
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
destination = os.path.join(BASE_DIR,'hunter', 'static', 'hunter/publications', 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 = os.path.join('static','publications',myfile.name)
try:
Publications.objects.create(pubID=pubID, title=title,link=link, messages='kidding', authors = authors,journalname=journalname,date=date,indexType=index)
except ProgrammingError as e:
return render(request, 'user.html', {'message':'Publications表错误:' + e})
authorArr = authors.split(',')
for author in authorArr:
try:
PubToUser.objects.create(pubID = pubID,username=author)
return redirect(request, 'index.html', {'uploadMessage': '文件上传成功'})
except ProgrammingError as e:
return render(request, 'index.html', {'uploadError': 'PubToUser数据表错误:' + e})
# message["warning"] = "上传成功"
# return HttpResponse(json.dumps(message), content_type='application/json')
return redirect(request, 'index.html')
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