添加文档排序功能并编写部分使用说明
22
app_doc/migrations/0005_auto_20190727_1232.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Generated by Django 2.2.3 on 2019-07-27 04:32
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app_doc', '0004_auto_20190717_0939'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='doc',
|
||||
options={'ordering': ['create_time', '-sort'], 'verbose_name': '文档', 'verbose_name_plural': '文档'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='doc',
|
||||
name='sort',
|
||||
field=models.IntegerField(default=99, verbose_name='排序'),
|
||||
),
|
||||
]
|
||||
@ -23,6 +23,7 @@ class Doc(models.Model):
|
||||
content = models.TextField(verbose_name="文档内容")
|
||||
parent_doc = models.IntegerField(default=0,verbose_name="上级文档")
|
||||
top_doc = models.IntegerField(default=0,verbose_name="所属项目")
|
||||
sort = models.IntegerField(verbose_name='排序',default=99)
|
||||
create_user = models.ForeignKey(User,on_delete=models.CASCADE)
|
||||
create_time = models.DateTimeField(auto_now_add=True)
|
||||
modify_time = models.DateTimeField(auto_now=True)
|
||||
@ -33,6 +34,7 @@ class Doc(models.Model):
|
||||
class Meta:
|
||||
verbose_name = '文档'
|
||||
verbose_name_plural = verbose_name
|
||||
# ordering = ['-create_time','sort']
|
||||
|
||||
# 文档模板模型
|
||||
class DocTemp(models.Model):
|
||||
|
||||
@ -8,7 +8,7 @@ register = template.Library()
|
||||
# 获取文档的子文档
|
||||
@register.filter(name='get_next_doc')
|
||||
def get_next_doc(value):
|
||||
return Doc.objects.filter(parent_doc=value)
|
||||
return Doc.objects.filter(parent_doc=value).order_by('sort')
|
||||
|
||||
# 获取文档的所属文集
|
||||
@register.filter(name='get_doc_top')
|
||||
|
||||
@ -45,7 +45,7 @@ def project_index(request,pro_id):
|
||||
# 获取搜索词
|
||||
kw = request.GET.get('kw','')
|
||||
if kw == '':
|
||||
doc = Doc.objects.filter(top_doc=int(pro_id)).order_by('id')
|
||||
doc = Doc.objects.filter(top_doc=int(pro_id)).order_by('sort')
|
||||
# 获取文集第一篇文档作为默认内容
|
||||
if doc.count() > 0:
|
||||
doc = doc[0]
|
||||
@ -54,7 +54,7 @@ def project_index(request,pro_id):
|
||||
else: # 搜索结果
|
||||
search_result = Doc.objects.filter(top_doc=int(pro_id),pre_content__icontains=kw)
|
||||
# 获取文集下所有一级文档
|
||||
project_docs = Doc.objects.filter(top_doc=int(pro_id), parent_doc=0)
|
||||
project_docs = Doc.objects.filter(top_doc=int(pro_id), parent_doc=0).order_by('sort')
|
||||
return render(request,'app_doc/project.html',locals())
|
||||
except Exception as e:
|
||||
return HttpResponse('请求出错')
|
||||
@ -129,7 +129,7 @@ def doc(request,pro_id,doc_id):
|
||||
# 获取文档内容
|
||||
doc = Doc.objects.get(id=int(doc_id))
|
||||
# 获取文集下一级文档
|
||||
project_docs = Doc.objects.filter(top_doc=doc.top_doc, parent_doc=0)
|
||||
project_docs = Doc.objects.filter(top_doc=doc.top_doc, parent_doc=0).order_by('sort')
|
||||
return render(request,'app_doc/project.html',locals())
|
||||
else:
|
||||
return HttpResponse('参数错误')
|
||||
@ -149,6 +149,7 @@ def create_doc(request):
|
||||
doctemp_list = DocTemp.objects.filter(create_user=request.user).values('id','name','create_time')
|
||||
return render(request,'app_doc/create_doc.html',locals())
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
return HttpResponse('请求出错')
|
||||
elif request.method == 'POST':
|
||||
try:
|
||||
@ -157,6 +158,7 @@ def create_doc(request):
|
||||
doc_name = request.POST.get('doc_name','')
|
||||
doc_content = request.POST.get('content','')
|
||||
pre_content = request.POST.get('pre_content','')
|
||||
sort = request.POST.get('sort','')
|
||||
if project != '' and doc_name != '' and project != '-1':
|
||||
doc = Doc.objects.create(
|
||||
name=doc_name,
|
||||
@ -164,12 +166,14 @@ def create_doc(request):
|
||||
pre_content= pre_content,
|
||||
parent_doc= int(parent_doc) if parent_doc != '' else 0,
|
||||
top_doc= int(project),
|
||||
sort = sort if sort != '' else 99,
|
||||
create_user=request.user
|
||||
)
|
||||
return JsonResponse({'status':True,'data':'创建成功'})
|
||||
else:
|
||||
return JsonResponse({'status':False,'data':'参数错误'})
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
return JsonResponse({'status':False,'data':'请求出错'})
|
||||
else:
|
||||
return JsonResponse({'status':False,'data':'方法不允许'})
|
||||
@ -198,6 +202,7 @@ def modify_doc(request,doc_id):
|
||||
doc_name = request.POST.get('doc_name', '') # 文档名称
|
||||
doc_content = request.POST.get('content', '') # 文档内容
|
||||
pre_content = request.POST.get('pre_content', '') # 文档Markdown格式内容
|
||||
sort = request.POST.get('sort', '') # 文档排序
|
||||
if doc_id != '' and project != '' and doc_name != '' and project != '-1':
|
||||
# 更新文档内容
|
||||
Doc.objects.filter(id=int(doc_id)).update(
|
||||
@ -205,6 +210,7 @@ def modify_doc(request,doc_id):
|
||||
content=doc_content,
|
||||
pre_content=pre_content,
|
||||
parent_doc=int(parent_doc) if parent_doc != '' else 0,
|
||||
sort=sort if sort != '' else 99,
|
||||
)
|
||||
return JsonResponse({'status': True,'data':'修改成功'})
|
||||
else:
|
||||
|
||||
BIN
db.sqlite3
BIN
media/201907/2019-07-27134531102843.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
media/201907/2019-07-27143257939483.png
Normal file
|
After Width: | Height: | Size: 94 KiB |
BIN
media/201907/2019-07-27144625887847.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
media/201907/2019-07-27144831731390.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
media/201907/2019-07-27145211532794.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
media/201907/2019-07-27150400032008.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
media/201907/2019-07-27150534099911.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
media/201907/2019-07-27175551618645.png
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
media/201907/2019-07-27175803741664.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
@ -98,6 +98,7 @@ body, html {
|
||||
background-color: #fafafa;
|
||||
border-right: 1px solid #e6e6e6;
|
||||
width:300px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.doc-body {
|
||||
|
||||
@ -7,13 +7,17 @@
|
||||
<link href="{% static 'layui/css/layui.css' %}" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{% static 'editor.md/css/editormd.css' %}" />
|
||||
<link href="{% static 'style.css' %}" rel="stylesheet">
|
||||
{% block custom_style %}{% endblock %}
|
||||
</head>
|
||||
<body class="layui-layout-body">
|
||||
<div class="layui-header">
|
||||
<div class="layui-main">
|
||||
<a class="logo" href="{% url 'pro_list' %}">
|
||||
{# <img src="/media/logo.png" />#}
|
||||
<h1><strong>MrDoc</strong></h1>
|
||||
<h1>
|
||||
<strong>MrDoc</strong>
|
||||
<span style="font-size: 16px;">{% block subtitle %}{% endblock %}</span>
|
||||
</h1>
|
||||
</a>
|
||||
<ul class="layui-nav layui-layout-right">
|
||||
{% if request.user.is_authenticated %}
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
{% extends 'app_doc/create_base.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block title %}新建文档{% endblock %}
|
||||
{% block subtitle %}新建文档{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="create-doc-form">
|
||||
<div class="layui-form">
|
||||
<label class="layui-form-label">文档标题</label>
|
||||
<label class="layui-form-label">标题</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="doc-name" id="doc-name" required lay-verify="required" placeholder="请输入文档标题" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
<label class="doc-form-label">所属文集</label>
|
||||
<label class="doc-form-label">所属</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="pro_id" lay-verify="required" lay-filter="project" id="project">
|
||||
<option value=""></option>
|
||||
@ -25,11 +26,15 @@
|
||||
<option value=""></option>
|
||||
</select>
|
||||
</div>
|
||||
<label class="doc-form-label">排序</label>
|
||||
<div class="layui-input-inline">
|
||||
<input class="layui-input" placeholder="99" style="width:50px;" name="sort" id="sort"/>
|
||||
</div>
|
||||
<label class="doc-form-label">
|
||||
<button class="layui-btn layui-btn-primary" id="sel-doctemp">插入模板</button>
|
||||
<button class="layui-btn layui-btn-primary layui-btn-sm" id="sel-doctemp">插入模板</button>
|
||||
</label>
|
||||
<label class="doc-form-label">
|
||||
<button class="layui-btn layui-btn-normal" onclick="createDoc()">保存</button>
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm" onclick="createDoc()">保存</button>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@ -97,6 +102,7 @@
|
||||
'doc_name':$("#doc-name").val(),
|
||||
'content':editor.getHTML(),
|
||||
'pre_content':editor.getMarkdown(),
|
||||
'sort':$("#sort").val(),
|
||||
}
|
||||
console.log(data)
|
||||
$.post("{% url 'create_doc' %}",data,function(r){
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{% extends 'app_doc/create_base.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block title %}新建文档模板{% endblock %}
|
||||
{% block subtitle %}新建模板{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="create-doc-form">
|
||||
|
||||
@ -1,15 +1,30 @@
|
||||
{% extends 'app_doc/create_base.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block title %}修改文档{% endblock %}
|
||||
{% block subtitle %}修改文档{% endblock %}
|
||||
|
||||
{% block custom_style %}
|
||||
<style>
|
||||
ul li{
|
||||
list-style:disc;
|
||||
}
|
||||
ul > li > ul > li{
|
||||
list-style-type: circle;
|
||||
}
|
||||
ol li{
|
||||
list-style-type: decimal;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="create-doc-form">
|
||||
<div class="layui-form">
|
||||
<label class="layui-form-label">文档标题</label>
|
||||
<label class="doc-form-label">标题</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="doc-name" id="doc-name" required lay-verify="required" placeholder="请输入文档标题" value="{{ doc.name }}" class="layui-input" >
|
||||
</div>
|
||||
<label class="doc-form-label">所属文集</label>
|
||||
<label class="doc-form-label">文集</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="pro_id" lay-verify="required" lay-filter="project" id="project" disabled>
|
||||
<option value="{{ project.id }}">{{ project.name }}</option>
|
||||
@ -21,11 +36,15 @@
|
||||
<option value="0"></option>
|
||||
</select>
|
||||
</div>
|
||||
<label class="doc-form-label">排序</label>
|
||||
<div class="layui-input-inline">
|
||||
<input class="layui-input" placeholder="99" style="width:50px;" name="sort" id="sort" value="{{doc.sort}}"/>
|
||||
</div>
|
||||
<label class="doc-form-label">
|
||||
<button class="layui-btn layui-btn-primary" id="sel-doctemp">插入模板</button>
|
||||
<button class="layui-btn layui-btn-primary layui-btn-sm" id="sel-doctemp">插入模板</button>
|
||||
</label>
|
||||
<label class="doc-form-label">
|
||||
<button class="layui-btn layui-btn-normal" onclick="createDoc()">保存</button>
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm" onclick="createDoc()">保存</button>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@ -66,15 +85,16 @@
|
||||
'doc_name':$("#doc-name").val(),
|
||||
'content':editor.getHTML(),
|
||||
'pre_content':editor.getMarkdown(),
|
||||
'sort':$("#sort").val(),
|
||||
}
|
||||
$.post("{% url 'modify_doc' doc_id=doc.id %}",data,function(r){
|
||||
if(r.status){
|
||||
//创建成功
|
||||
//修改成功
|
||||
layer.msg('保存成功,即将跳转',function(){
|
||||
window.location.href = "{% url 'doc' pro_id=doc.top_doc doc_id=doc.id %}";
|
||||
});
|
||||
}else{
|
||||
//创建失败
|
||||
//修改失败
|
||||
layer.msg('保存失败');
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{% extends 'app_doc/create_base.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block title %}修改文档模板{% endblock %}
|
||||
{% block subtitle %}修改文档模板{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="create-doc-form">
|
||||
|
||||
@ -95,6 +95,9 @@
|
||||
<a class="btn pull-left" aria-label="" href="{% url 'modify_doc' doc_id=doc.id %}">
|
||||
<i class="fa fa-edit"></i> 修改文档
|
||||
</a>
|
||||
<a class="btn pull-left" aria-label="" href="{% url 'create_doc' %}" target="_blank">
|
||||
<i class="fa fa-edit"></i> 新建文档
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<!-- 文档主体 -->
|
||||
|
||||
@ -71,7 +71,7 @@
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-inline">
|
||||
<button class="layui-btn layui-btn-fluid layui-btn-radius layui-btn-normal" lay-submit lay-filter="formDemo" type="submit">登录</button>
|
||||
<button class="layui-btn layui-btn-fluid layui-btn-radius layui-btn-normal" lay-submit lay-filter="formDemo" type="submit">注册并登录</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||