Commit 0f9fbbe0 by liuyingying

文章功能总算好了

parent 777a0c3e
*{
box-sizing:border-box;
transition:all .5s;
-moz-transition:all .5s;
-webkit-transition:all .5s;
-o-transition:all .5s;
margin:0;
padding: 0;
}
body{
background-color: rgba(253, 253, 253, .3);
width:100%;
}
button{
/* border: solid 1px black; */
border-radius: 5px;
cursor: pointer;
}
select{
height: 30px;
font-weight: 200;
}
a{
text-decoration: none;
}
\ No newline at end of file
*{
box-sizing:border-box;
transition:all .5s;
-moz-transition:all .5s;
-webkit-transition:all .5s;
-o-transition:all .5s;
margin:0;
padding: 0;
}
html, body{
overflow: scroll;
width:100%;
height:100%;
min-width: 1250px;
}
button{
width:50px;
height:30px;
margin:5px 10px;
float: right;
background-color: rgb(52, 133, 251);
color: white;
border:none;
}
nav{
width:100%;
height:40px;
position: fixed;
/*border-bottom: solid 1px #e3e6e8;*/
background:white;
}
nav a{
font-size:18px;
font-weight: bold;
}
nav>div{
width:100%;
height:40px;
border-bottom: solid 1px #ececec
}
nav span{
height:40px;
line-height: 40px;
padding-left:15px;
}
#bar > span{
float: right;
width: 150px;
font-size: 12px;
line-height: 30px;
height: 30px;
margin: 5px 10px;
text-align: center;
}
#hunter,
#bar{
width:50%;
height:100%;
float: left;
}
.middle_div{
width: 100%;
height: 40px;
margin-top: 40px;
background-color: #e6e6e6;
}
.title{
width:40%;
float: left;
height:100%;
padding:5px 10px;
}
.title label{
font-size:14px;
}
.title input{
width:90%;
height:30px;
}
#myfile{
width: 300px;
height: 30px;
margin: 10px;
/* line-height: 30px; */
font-size: 14px;
display: block;
float: right;
}
#error_log{
color:red;
font-size:12px;
width:100px;
height:40px;
line-height: 40px;
float: right;
}
.grey_text{
color: #999999;
font-size:12px;
width:100px;
height:40px;
line-height: 40px;
float: right;
}
textarea{
width:100%;
height:100%;
}
#markdownCnt{
width:100%;
padding-top:10px;
}
#markdownCnt >div>label{
width:100%;
height:0;
display: none;
}
#markdownCnt>div{
width:50%;
height:100%;
float: left;
}
#markdownCnt div:first-child{
padding-left:10px;
}
#markdownCnt textarea{
min-height: 1000px;
}
#textCnt{
padding-right: 10px;
}
/* Markdown解析样式 */
blockquote {
color: rgba(0,0,0,.5);
padding-left: 1.5em;
border-left: 5px solid rgba(0,0,0,.1);
}
blockquote {
display: block;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 40px;
-webkit-margin-end: 40px;
}
ul li {
line-height: 20px;
list-style: circle;
}
code {
background-color: rgba(0,0,0,.05);
display: block;
padding: .5em;
-webkit-text-size-adjust: none;
overflow-x: auto;
white-space: pre;
}
img{
width: 80%;
margin: 0 auto;
display: block;
}
/* Markdown解析样式 */
a{
color: black;
text-decoration: none;
}
.navbar{
background-color: black;
color: #FF9800;
}
.btns{
width:auto;
float: right;
padding: 15px 15px;
height: 50px;
line-height: 20px;
}
.btns > button{
margin-right: 20px;
}
#save, #publish, #return{
float: left;
}
.file_ipt{
width: 50%;
height: 100%;
float: right;
font-size: 16px;
}
#return{
height: 50px;
line-height: 30px;
}
button:hover{
background-color: #306cc5;
}
svg{
width:100%;
height: 100%;
}
textarea{
border:0;
outline: none;
}
/*article*/
#title_view{
width:100%;
text-align: center;
font-weight: bold;
}
.attachment {
width:70%;
margin:0 auto;
}
.attachment a{
font-size: 12px;
color: blue;
text-decoration: underline;
float:right;
}
.attachment span{
float: right;
font-size:12px;
}
.contain{
width: 100%;
padding-top: 60px;
}
#content_view{
width: 70%;
margin: 0 auto;
}
#right_bar span{
float: right;
font-size: 12px;
line-height: 30px;
height: 30px;
margin: 5px 0;
}
#right_bar{
padding-right: 20px;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -301,6 +301,7 @@ blockquote>p{
.wrap ul{
display: block;
width:100%;
cursor: pointer;
padding-right: 20px;
}
......@@ -343,6 +344,19 @@ ul:after{
margin: -10px 0 20px;
z-index: -999;
}
.small_text a{
color:blue;
font-size: 12px;
text-decoration: underline;
cursor: pointer;
z-index: auto;
}
.small_text a:hover,
.small_text a:active{
color: darkgrey;
font-size:12px !important;
}
.li_small_text{
font-size: 14px;
color: grey;
......@@ -363,7 +377,7 @@ ul:after{
.right{
float:right !important;
height: 20px !important;
margin: -10px 0 20px;
margin: 0 0 20px;
z-index: -999;
font-size:14px;
}
......@@ -559,6 +573,10 @@ section > .smaller_box{
height:35px;
float: right;
}
.add_one > a{
float: right;
margin: 5px 20px;
}
.add_one button{
width:30px;
height:30px;
......@@ -566,7 +584,6 @@ section > .smaller_box{
border:none;
background: transparent;
margin-right: 15px;
}
li svg{
margin:10px 5px;
......
......@@ -2,10 +2,49 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hunter.article</title>
<title>HT-{{ article.title }}</title>
{% load static %}
<link rel="icon" href="{% static 'hunter/images/logo.ico' %}" type="text/icon">
<script src="{% static 'hunter/jquery-1.9.1.min.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'hunter/md/markdown.css' %}">
<script type="text/javascript" src="{% static 'hunter/md/showdown.js' %}"></script>
</head>
<body>
{{ article }}
<p>article</p>
<nav>
<div>
<div id="hunter">
<span><a href="/">HUNTER</a></span>
</div>
<div id="right_bar" class="">
<span>{{ article.author }}</span>
<span>作者:</span>
</div>
</div>
</nav>
<div class="contain">
<div id="title_view"> {{ article.title }}</div>
<div id="content_view" style="display: none;">{{ article.content }}</div>
</div>
<div class="attachment" id="attachment" >
<a target="_blank" download="{{ article.attachment }}" href="{% static 'hunter/articles/' %}{{ article.attachment }}">{{ article.attachment }}</a>
</div>
<script>
$(document).ready(function() {
convMDtoHTML();
});
function convMDtoHTML(){
var text = document.getElementById("content_view").innerHTML;
var converter = new showdown.Converter();
var html = converter.makeHtml(text);
$("#content_view").empty();
$("#content_view").append(html);
$("#content_view").css('display','block');
if($('#attachment a').text()){
$('#attachment').append('<span>附件下载:</span>');
}
}
</script>
</body>
</html>
\ No newline at end of file
......@@ -3,7 +3,54 @@
<head>
<meta charset="UTF-8">
<title>hunter.detail</title>
{% load static %}
<link rel="icon" href="{% static 'hunter/images/logo.ico' %}" type="text/icon">
<link rel="stylesheet" type="text/css" href="{% static 'hunter/detail.css' %}">
<script src="{% static 'hunter/jquery-1.9.1.min.js' %}"></script>
</head>
<body>
<nav>
<div>
<div id="hunter">
<span><a href="/">HUNTER</a></span>
</div>
<div id="bar" class="">
</div>
</div>
</nav>
<div>
<div class="wrap">
{% for year,publications in publication_year_list.items %}
<blockquote><p>{{ year }}</p></blockquote>
{% if publications %}
{% for publication in publications %}
<ul>
<li><a href="{% static 'hunter/publications/' %}{{ publication.link }}" target="_blank">{{ publication.title }}</a></li>
<li>{{ publication.date }}</li>
<li>{{ publication.journalname }}</li>
<li>{{ publication.publishType }}</li>
<li>{{ publication.authors }}</li>
</ul>
{% endfor %}
{% endif %}
{% endfor %}
</div>
<div class="wrap">
{% for year, cves in cve_year_list.items %}
<blockquote ><p>{{ year }}</p></blockquote>
{% if cves %}
{% for cve in cves %}
<ul>
<li class="cve_big_text"><a href="{{ cve.url }}" target="_blank">{{ cve.identifier }}</a></li>
<li class="li_right">{{ cve.datetime }}</li>
<li class="li_right">{{ cve.software }}</li>
<li class="li_right">{{ cve.bugType }}</li>
<li class="li_long li_small_text">{{ cve.description }}</li>
</ul>
{% endfor %}
{% endif %}
{% endfor %}
</div>
</div>
</body>
</html>
\ No newline at end of file
......@@ -60,7 +60,7 @@
{% for user in users %}
<ul>
<li>
<a href="{% url 'hunter:user' user.userID %}" target="_blank">{{ user.name_hanzi }}</a>
<a href="{% url 'hunter:detail' user.userID %}" target="_blank">{{ user.name_hanzi }}</a>
</li>
<li class="user_mail">{{ user.mailAddress }}</li>
</ul>
......@@ -240,7 +240,7 @@
let i = $(".bottom>a").index(this);
click_bar(i);
});
let storage = window.sessionStorage;
let storage = window.localStorage;
if (!storage["userID"]&&!storage["username"]){
}else{
......@@ -250,9 +250,9 @@
};
function logout(){
let session = window.sessionStorage;
session['username']="";
session['password']="";
let storage = window.localStorage;
storage['username']="";
storage['password']="";
$('#top_bar').empty();
$('#top_bar').append("<ul><li onclick='login()'>登录</li></ul>");
}
......@@ -289,7 +289,7 @@
console.log(response);
if(response['message']==="success"){
let user_id=response['userid'];
let storage = window.sessionStorage;
let storage = window.localStorage;
storage['username'] = username;
storage['userID'] = user_id;
console.log(storage);
......@@ -322,7 +322,7 @@
function logout(){
$('#top_bar').empty();
$('#top_bar').append('<button onclick="show_log()">登录</button>');
let storage = window.sessionStorage;
let storage = window.localStorage;
storage.clear();
console.log(storage);
}
......
......@@ -120,9 +120,9 @@
</span>
<div class="add_one">
<button onclick="addArt()">
<svg t="1587711895133" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3772" width="20" height="20"><path d="M512 1024C229.2224 1024 0 794.7776 0 512 0 229.2224 229.2224 0 512 0 794.7776 0 1024 229.2224 1024 512 1024 794.7776 794.7776 1024 512 1024ZM716.8 486.4 537.6 486.4 537.6 307.2 486.4 307.2 486.4 486.4 307.2 486.4 307.2 537.6 486.4 537.6 486.4 716.8 537.6 716.8 537.6 537.6 716.8 537.6 716.8 486.4Z" p-id="3773" fill="#6e829e"></path></svg>
</button>
<a href="{% url 'hunter:write_art' %}">
<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>
</a>
</div>
</div>
<div class="wrap smaller_wrap">
......@@ -141,6 +141,7 @@
{# </button></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>
</ul>
{% endfor %}
{% endif %}
......@@ -157,7 +158,7 @@
</footer>
<script type="text/javascript" src="{% static 'hunter/bootstrap.min.js' %}"></script>
<script type="text/javascript" src="{% static 'hunter/bootstrap-datetimepicker.js' %}" charset="UTF-8"></script>
<script type="text/javascript" src="{% static 'hunter//bootstrap-datetimepicker.zh-CN.js' %}" charset="UTF-8"></script>
<script type="text/javascript" src="{% static 'hunter/bootstrap-datetimepicker.zh-CN.js' %}" charset="UTF-8"></script>
<script type="text/javascript">
$('.form_datetime').datetimepicker({
//language: 'fr',
......@@ -194,22 +195,22 @@
<script type="text/javascript">
window.onload=function(){
let session = window.sessionStorage;
let storage = window.localStorage;
let url = window.location.pathname;
let id = url.split('/')[2];
if(id!==sessionStorage["userID"]){
if(id!==storage["userID"]){
console.log($('#username').val());
window.location.href='/';
}else{
$('#username').append(session['username']);
$('.userID')[0].id=session['userID'];
$('#username').append(storage['username']);
$('.userID')[0].id=storage['userID'];
}
};
function exit(){
let session = window.sessionStorage;
session['username']="";
session['userID']="";
let storage = window.localStorage;
storage['username']="";
storage['userID']="";
window.location.href='/';
}
var submit_what = '';
......@@ -329,8 +330,8 @@
$('#edit_title').append('添加CVE');
}
function submit_cve(){
let session = window.sessionStorage;
let owner = session['username'];
let storage = window.localStorage;
let owner = storage['username'];
let cve_id = $('input[name="identifier"]').val();
let bugtype = $('input[name="bugtype"]').val();
let date = $('#date_input').val();
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>写文章</title>
{% load static %}
<link rel="icon" href="{% static 'hunter/images/logo.ico' %}" type="text/icon">
<script src="{% static 'hunter/jquery-1.9.1.min.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'hunter/md/markdown.css' %}">
<script type="text/javascript" src="{% static 'hunter/md/showdown.js' %}"></script>
<script type="text/javascript" src="{% static 'hunter/bootstrap.min.js' %}"></script>
</head>
<body>
<nav>
<div>
<div id="hunter">
<span><a href="/">HUNTER</a></span>
</div>
<div id="bar" class="">
<span id="username"></span>
<button onclick="saveArt()">保存</button>
</div>
</div>
</nav>
<div class="middle_div">
<div class="title">
<label for="title">标题</label>
<input type="text" id="title" required>
</div>
<input name="myfile" id="myfile" type="file" >
<div class="grey_text">多个文件请打包</div>
<div id="error_log"></div>
</div>
<div id="markdownCnt">
<div>
<label for="originCnt">原文</label>
<textarea id = "originCnt" class="" oninput="compile()" placeholder="Start your writing">{{ articleCnt }}</textarea>
<!-- <button onclick="compile()">转换</button> -->
</div>
<div id="textCnt" class="halfView">
</div>
</div>
</body>
<script>
$(document).ready(function() {
var height = window.innerHeight;
$('#markdownCnt').css("height",height*0.88);
getUsername();
compile();
//拖离
document.addEventListener('dragleave',function(e){e.preventDefault();});
//拖后放
document.addEventListener('drop',function(e){e.preventDefault();});
//拖进
document.addEventListener('dragenter',function(e){e.preventDefault();});
//拖来拖去
document.addEventListener('dragover',function(e){e.preventDefault();});
var boxImg = document.getElementById("originCnt");
boxImg.addEventListener("drop",function(e){
e.preventDefault();
var fileList = e.dataTransfer.files;
if(fileList.length===0){return false;}
else if(fileList.length>1){
console.log("暂不支持多图同时上传");
return false;
}
else if(fileList[0].type.indexOf('image')===-1){
alert("文章中只能插入图片哦");
return false;
}
else{
console.log(fileList[0].name);
var formData = new FormData();
formData.append('image', fileList[0]);
$.ajax({
type:"post",
url:'/uploadImg/',//ajaxurl
async:false,
dataType:"text",
data:formData,
processData : false,
contentType : false,
success:function(data){
if(data){
var addMDHTML='!['+fileList[0].name+']('+data+')';
console.log(addMDHTML);
                 $("#originCnt").val($("#originCnt").val()+addMDHTML);
compile();
}else{
console.log(data)
}
},error:function(e){
console.log(e)
}
});
}
});
},false);
function saveArt(){
let username = document.getElementById("username").innerHTML;
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("username",username);
formdata.append("title",title);
formdata.append("content",content);
$.ajax({
url:'/write/',
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'];
console.log(username);
if(username){
$("#username").text(username);
}else{
$("#username").text('你好');
{#alert("请先登录");#}
{#window.location.href="/";#}
}
}
function compile(){
var text = document.getElementById("originCnt").value;
var converter = new showdown.Converter();
let md_html = converter.makeHtml(text);
document.getElementById("textCnt").innerHTML = md_html;
}
</script>
</html>
\ No newline at end of file
......@@ -4,10 +4,13 @@ from . import views
app_name = 'hunter'
urlpatterns = [
path('', views.index, name='index'),
path('/index/', views.index, name='index'),
path('index/', views.index, name='index'),
# path('<int:pk>/', views.UserDetail.as_view(), name='user'),
# path('<int:pk>/article/', views.ArticleDetail.as_view(), name='article'),
path('user/<int:user_id>/', views.user, name='user'),
path('user/detail/<int:user_id>/', views.detail, name='detail'),
path('write/', views.write_art, name='write_art'),
path('uploadImg/', views.uploadImg, name='uploadImg'),
path('article/<int:article_id>/', views.article, name='article'),
path('login/', views.login, name='login'),
path('delete/publication/', views.delete_publication, name='delete_publication'),
......
......@@ -6,6 +6,7 @@ from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import os
from django.db.utils import ProgrammingError
import datetime
from django.shortcuts import redirect
from django.core.exceptions import ValidationError
import json
......@@ -120,7 +121,6 @@ def user(request, user_id):
for art in my_article_list:
year = str(art.editDateTime)[0:4]
art.editDateTime = str(art.editDateTime)[5:10]
u = User.objects.filter(userID=art.authorID).values('name')
art.authorID = username
if year in my_article_year_list.keys():
my_article_year_list[year].append(art)
......@@ -143,16 +143,108 @@ def user(request, user_id):
'cve_year_list': my_cve_year_list,
'article_year_list': my_article_year_list,
}
return render(request, 'hunter/user.html', context)
def detail(request, user_id):
usr = get_object_or_404(User, pk=user_id)
username = usr.name
my_publication_year_list = {}
pub_ids = PubToUser.objects.filter(username=username).all().values("pubID")
for pub_id in pub_ids:
pub = get_object_or_404(Publications, pk=pub_id['pubID'])
year = str(pub.date)[0:4]
pub.date = str(pub.date)[5:10]
pub.link = pub.link.split('/')[-1]
if year in my_publication_year_list.keys():
my_publication_year_list[year].append(pub)
else:
my_publication_year_list[year] = [pub]
my_bug_list = Bugs.objects.filter(owner=username).order_by('-datetime')
my_cve_year_list = {}
for cve in my_bug_list:
year = str(cve.datetime)[0:4]
cve.datetime = str(cve.datetime)[5:10]
if year in my_cve_year_list.keys():
my_cve_year_list[year].append(cve)
else:
my_cve_year_list[year] = [cve]
context = {
'user': usr,
'publication_year_list': my_publication_year_list,
'cve_year_list': my_cve_year_list,
}
return render(request, 'hunter/detail.html', context)
def article(request, article_id):
art = get_object_or_404(Articles, pk=article_id)
author = get_object_or_404(User, pk=art.authorID)
art.author = author.name
return render(request, 'hunter/article.html', {'article': art})
@csrf_exempt
def write_art(request):
if request.is_ajax():
username = request.POST.get('username', '')
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(name=username).userID
except ObjectDoesNotExist as e:
response = JsonResponse({"message": 0, 'error':'用户不存在,请检查是否登录'})
return response
try:
Articles.objects.create(articleID=articleID, authorID=authorID, title=title, content=content,
editDateTime=editdatetime,
attachment=link)
response = JsonResponse({"message": 1})
except ProgrammingError as e:
response = JsonResponse({"message": 0, 'error': '数据库错误'})
return response
return render(request, 'hunter/write.html')
@csrf_exempt
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', 'hunter/articles/images', file_obj.name)
link_path = os.path.join('/static', 'hunter/articles/images', file_obj.name)
with open(file_path,'wb') as f:
for chunk in file_obj.chunks():
f.write(chunk)
return HttpResponse(link_path)
@csrf_exempt
def delete_publication(request):
pub_id = request.POST['pub_id']
print(pub_id)
......
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