Commit 545b2f87 by liuyingying

是否选择发布

parent bb75078f
......@@ -15,14 +15,12 @@
<div id="edit_title">修改</div>
<div id="edit_content">
<div>
<label for="title">文章标题:</label>
<input id="title" name="title" type="text">
<label>是否公开发布:</label>
<select name="isPublish" id = 'isPublish'>
<option value="1" selected>公开(在首页显示)</option>
<option value="0" >不公开(仅自己可见)</option>
</select>
</div>
<div>
<label for="url">文章地址:</label>
<input id="url" name="url" type="text">
</div>
</div>
<div id="error_log">{{ error_message }}</div>
<div id="btn_edit">
......@@ -246,6 +244,7 @@
let myfile = $("input[name='myfile']")[0].files[0];
let storage = window.localStorage;
let username = storage.username;
let isPublish = $('#isPublish option:selected').val();
let formatData = new FormData();
formatData.append("myfile", myfile);
formatData.append("title", title);
......@@ -254,6 +253,7 @@
formatData.append("date", date);
formatData.append("type", type);
formatData.append("username", username);
formatData.append("isPublish", isPublish);
$.ajax({
url:"{% url 'hunter:add_publication' %} ",
......@@ -556,7 +556,13 @@
' </div>\n' +
' <div class="myfile" >\n' +
' <input type="file" name="myfile" required>\n' +
' </div>';
' </div>'+'<div>\n' +
' <label>是否公开发布:</label>\n' +
' <select name="isPublish" id = \'isPublish\'>\n' +
' <option value="1" selected>公开(在首页显示)</option>\n' +
' <option value="0" >不公开(仅自己可见)</option>\n' +
' </select>\n' +
' </div>';
$('#edit_content').append(input_html);
}
function submit_edit(){
......
......@@ -140,6 +140,48 @@
},
});
}
function saveArtPrivate(){
let username = document.getElementById("username").innerHTML;
let storage = window.localStorage;
let userID = storage['userID'];
let title = document.getElementById("title").value;
let content = document.getElementById("originCnt").value;
if(title.length<=0){
$('#error_log').empty();
$('#error_log').append('标题不能为空');
return;
}
let formdata = new FormData();
let files = $('input[name="myfile"]')[0].files;
if(files.length>0){
let myfile =files[0];
formdata.append("myfile",myfile);
formdata.append("isHaveFile", "1");
}else{
formdata.append("isHaveFile", "0");
}
formdata.append("userID",userID);
formdata.append("title",title);
formdata.append("content",content);
$.ajax({
url:'/save/private',
type:'post',
data:formdata,
processData : false, // 使数据不做处理
contentType : false, // 不要设置Content-Type请求头
success:function (response) {
if(response["message"]){
alert('上传成功');
let storage = window.localStorage;
window.location.href="/user/"+storage.userID;
}else{
$('#error_log').empty();
$('#error_log').append(response['error']);
}
},
});
}
function getUsername(){
let storage=window.localStorage;
let username=storage['username'];
......
......@@ -56,7 +56,7 @@ def index(request):
else:
user_type_list_former[member_type] = [u]
publication_list = Publications.objects.order_by('-date')
publication_list = Publications.objects.filter(isOpen='1').order_by('-date')
publication_year_list = {}
for pub in publication_list:
year = str(pub.date)[0:4]
......@@ -373,6 +373,7 @@ def add_publication(request):
print(title)
authors = request.POST['authors']
uploadby = request.POST['username']
publishType = request.POST['type']
myfile = request.FILES['myfile']
print(authors)
s=','
......@@ -382,6 +383,7 @@ def add_publication(request):
date = request.POST.get('date')
print(date)
index = request.POST.get('index')
isPublish=request.POST['isPublish']
if Publications.objects.filter(title=title).count() > 0:
return JsonResponse({'message': 0, "error": "该标题已存在"})
if Publications.objects.last() is None:
......@@ -398,7 +400,7 @@ def add_publication(request):
dest.close()
link = myfile.name
try:
Publications.objects.create(pubID=pubID, title=title,link=link, messages='kidding', authors = authors,journalname=journalname,uploadByUser=uploadby,date=date,)
Publications.objects.create(pubID=pubID, title=title,link=link, messages='kidding', authors = authors,journalname=journalname,uploadByUser=uploadby,date=date,publishType=publishType, isOpen=isPublish)
except ProgrammingError as e:
return JsonResponse({"message": 0})
authorArr = authors.split(',').strip()
......
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