CJ 1 年間 前
コミット
fca347caff

+ 55 - 18
blog/controller/article.py

@@ -24,6 +24,18 @@ def article(request):
     return render(request, 'management/article/article.html', context={'articles': articles})
 
 
+@login_required(login_url='/login')
+def draft(request):
+    page = request.GET.get('page')
+    search_title = request.GET.get('search_title')
+    search_content = request.GET.get('search_content')
+    if page is None:
+        page = 0
+    articles = blog.controller.article.get_article(is_paginator=True, page=int(page), search_title=search_title,
+                                                   search_content=search_content, draft=True)
+    return render(request, 'management/article/draft.html', context={'articles': articles})
+
+
 def new(request):
     return render(request, 'management/article/new_article.html')
 
@@ -41,7 +53,7 @@ def show_article(request, pk):
     result = get_record_and_tags()
 
     return render(request, 'blog.html', context={'article': article, 'records': result['records'],
-               'tags': result['tags']})
+                                                 'tags': result['tags']})
 
 
 @login_required(login_url='/')
@@ -219,8 +231,9 @@ def set_tag(articles):
 
 
 def get_article(top: int = -1, page: int = -1, is_paginator: bool = False, category: models.Category = None,
-                tag: models.Tags = None, search_title: str = None, search_content: str = None, date_record: str = None):
-    if category is None and tag is None and date_record is None:
+                tag: models.Tags = None, search_title: str = None, search_content: str = None, date_record: str = None,
+                draft: bool = False):
+    if category is None and tag is None and date_record is None and draft == False:
         search_dict = dict()
         if search_title:
             search_dict['title__contains'] = search_title
@@ -238,21 +251,22 @@ def get_article(top: int = -1, page: int = -1, is_paginator: bool = False, categ
     elif date_record is not None:
         date_format = "%Y-%m"
         date = datetime.strptime(date_record, date_format)
-        articles = models.Article.objects.filter(created_time__year=date.year,created_time__month=date.month).order_by('-created_time').values('id', 'title',
-                                                                                                       'intro',
-                                                                                                       'category',
-                                                                                                       'user',
-                                                                                                       'created_time',
-                                                                                                       'type',
-                                                                                                       'cover__file_net_path',
-                                                                                                       'music__file_net_path',
-                                                                                                       'status',
-                                                                                                       'category__name',
-                                                                                                       'user__first_name',
-                                                                                                       'user_id',
-                                                                                                       'user__last_name',
-                                                                                                       'is_top',
-                                                                                                       'html_text').distinct()
+        articles = models.Article.objects.filter(created_time__year=date.year, created_time__month=date.month).order_by(
+            '-created_time').values('id', 'title',
+                                    'intro',
+                                    'category',
+                                    'user',
+                                    'created_time',
+                                    'type',
+                                    'cover__file_net_path',
+                                    'music__file_net_path',
+                                    'status',
+                                    'category__name',
+                                    'user__first_name',
+                                    'user_id',
+                                    'user__last_name',
+                                    'is_top',
+                                    'html_text').distinct()
     elif tag is not None:
         articles = models.Article.objects.filter(tags__name=tag.name).order_by('-created_time').values('id', 'title',
                                                                                                        'intro',
@@ -270,6 +284,29 @@ def get_article(top: int = -1, page: int = -1, is_paginator: bool = False, categ
                                                                                                        'tags__name',
                                                                                                        'is_top',
                                                                                                        'html_text')
+    elif draft:
+        search_dict = dict()
+        search_dict['status'] = 0
+
+        if search_title:
+            search_dict['title__contains'] = search_title
+        if search_content:
+            search_dict['markdown_text__contains'] = search_content
+        articles = models.Article.objects.filter(**search_dict).order_by('-created_time').values('id', 'title',
+                                                                                                 'intro',
+                                                                                                 'category',
+                                                                                                 'user',
+                                                                                                 'created_time',
+                                                                                                 'type',
+                                                                                                 'cover__file_net_path',
+                                                                                                 'music__file_net_path',
+                                                                                                 'status',
+                                                                                                 'category__name',
+                                                                                                 'user__first_name',
+                                                                                                 'user_id',
+                                                                                                 'user__last_name',
+                                                                                                 'is_top',
+                                                                                                 'html_text').distinct()
     else:
         articles = models.Article.objects.filter(category=category).order_by('-created_time').values('id', 'title',
                                                                                                      'intro',

+ 1 - 0
blog/router/admin_url/admin_url.py

@@ -29,6 +29,7 @@ urlpatterns = [
     path('category/', include('blog.router.category_url.category_url')),
     path('files', files.files, name='admin_files'),
     path('files/', include('blog.router.files_url.files_url')),
+    path('draft', article.draft, name='admin_draft'),
 
 ]
 urlpatterns += staticfiles_urlpatterns()

+ 3 - 1
templates/category.html

@@ -86,7 +86,8 @@
                         </ul>
                     </nav>
                     {% for item in articles %}
-                        {% if item.type == 1 %}
+                        {% if item.status == 1 %}
+                             {% if item.type == 1 %}
                             <div class="event">
                                 <div class="label">
                                     <img src="/user_avatar/{{ item.user_id }}">
@@ -124,6 +125,7 @@
 
                             </div>
                         {% endif %}
+                        {% endif %}
                     {% endfor %}
 
 

+ 3 - 1
templates/index.html

@@ -12,7 +12,8 @@
                     <h2>动态</h2>
                     <div class="ui divider"></div>
                     {% for item in articles_new %}
-                        {% if item.type == 1 %}
+                    {% if item.status == 1 %}
+                         {% if item.type == 1 %}
                             <div class="event">
                                 <div class="label">
                                     <img src="/user_avatar/{{ item.user_id }}">
@@ -52,6 +53,7 @@
 
                             </div>
                         {% endif %}
+                    {% endif %}
                     {% endfor %}
 
                     {% if is_login %}

+ 1 - 0
templates/management/_common/base.html

@@ -139,6 +139,7 @@
             <a href="{% url 'admin_category' %}" class="item"><i class="th list icon"></i>分类管理</a>
             <a href="{% url 'admin_tags' %}" class="item"><i class="linkify icon"></i>标签管理</a>
             <a href="{% url 'admin_files' %}" class="item"><i class="file icon"></i>文件管理</a>
+            <a href="{% url 'admin_draft' %}" class="item"><i class="trash icon"></i>草稿箱</a>
             {#            <a class="item">标签</a>#}
             {#            <a class="item">分类</a>#}
         </div>

+ 104 - 0
templates/management/article/draft.html

@@ -0,0 +1,104 @@
+{% extends 'management/_common/base.html' %}
+{% load page_tag %}
+
+{% block content %}
+    <form style="padding: 0;" action="/management/draft" method="get">
+        <div style="padding: 0" class="ui input">
+            <input name="search_title" type="text" style="margin-right: 5px" placeholder="标题">
+            <input name='search_content' type="text" style="margin-right: 5px" placeholder="内容">
+            <button type="submit" class="ui button primary"><i class="search icon"></i>搜索</button>
+            <a href="/management/draft" type="reset" class="ui button secondary"><i class="refresh icon"></i>重置</a>
+        </div>
+    </form>
+
+    <table style="padding: 0" class="ui celled table">
+        <thead>
+        <tr>
+            <th>封面</th>
+            <th>标题</th>
+            <th>分类</th>
+            <th>创建时间</th>
+            <th>置顶</th>
+            <th>状态</th>
+            <th>操作</th>
+        </tr>
+        </thead>
+        <tbody>
+        {% for article in articles %}
+            <tr>
+                <td>{{ article.cover__file_net_path }}</td>
+                <td><a href="/management/article/to_edit/{{ article.id }}">{{ article.title }}</a></td>
+                <td>{{ article.category__name }}</td>
+                <td>{{ article.created_time }}</td>
+                <td>{{ article.is_top }}</td>
+                <td>{% if article.status == 1 %}
+                    <strong style="color: green">发布</strong>
+                {% elif article.status == 0 %}
+                    <strong style="color: orange">草稿</strong>
+                {% endif %} </td>
+                <td><a onclick="deleteConfirm({{ article.id }})" href="#" class="button" style="color: red">删除</a>
+                </td>
+            </tr>
+        {% endfor %}
+        </tbody>
+        <tfoot>
+        <tr>
+            <th colspan="7">
+                <div class="ui right floated pagination menu">
+                    {% if articles.number > 1 %}
+                        <a href="?page={{ articles.number|add:-1 }}" class="icon item">
+                            <i class="left chevron icon"></i>
+                        </a>
+                    {% else %}
+                        <a class="icon item">
+                            <i class="left chevron icon"></i>
+                        </a>
+                    {% endif %}
+
+                    {% for page in articles.paginator.page_range %}
+                        {% circle_page articles.number page %}
+                    {% endfor %}
+                    {% if articles.number <  articles.paginator.num_pages %}
+
+                        <a href="?page={{ articles.number | add:1 }}" class="icon item">
+                            <i class="right chevron icon"></i>
+                        </a>
+                    {% else %}
+                        <a class="icon item">
+                            <i class="right chevron icon"></i>
+                        </a>
+                    {% endif %}
+
+                </div>
+            </th>
+        </tr>
+        </tfoot>
+    </table>
+    <div class="ui mini test modal">
+        <div class="header">
+            警告
+        </div>
+        <div class="content">
+            <p>确认删除该文章?</p>
+        </div>
+        <div class="actions">
+            <div class="ui negative button">
+                取消
+            </div>
+            <a id="deleteBtn" href="" class="ui positive right labeled icon button">
+                确认
+                <i class="checkmark icon"></i>
+            </a>
+        </div>
+    </div>
+
+{% endblock %}
+{% block js %}
+    <script>
+        function deleteConfirm(id) {
+            $('.mini.modal')
+                .modal('show')
+            $("#deleteBtn").attr('href', '/management/article/delete_article?id=' + id)
+        }
+    </script>
+{% endblock %}

+ 0 - 1
templates/management/article/edit_article.html

@@ -263,7 +263,6 @@
             if (title === '' || title === undefined) {
                 title = '未命名标题'
             }
-            localStorage.setItem(title, html)
             $('#title').val($('#page_title').val())
         }
     }

+ 21 - 4
templates/management/article/new_article.html

@@ -109,9 +109,11 @@
 <div id="top-container" style="padding-left: 6px;">
     <p style="text-align:right;padding: 2px;">
         <a class="ui button secondary mini" href="/management"><i class="angle left icon"></i>返回</a>
+        <a class="ui button youtube mini" id="restore" onclick="restore()"><i class="trash alternate icon"></i>恢复</a>
         <a class="ui button primary mini" onclick="submit(-1)"><i class="send icon"></i>发布</a>
     </p>
 </div>
+
 <div style="border-bottom: 1px solid #e8e8e8;">
     <div id="editor-toolbar"></div>
 </div>
@@ -178,7 +180,7 @@
         <div onclick="submit(1)" class="ui primary approve button">
             发布
         </div>
-        <div onclick="submit(2)" class="ui secondary approve button">
+        <div onclick="submit(0)" class="ui secondary approve button">
             保存
         </div>
     </div>
@@ -193,6 +195,7 @@
 
 <!-- <script src="https://cdn.jsdelivr.net/npm/@wangeditor/editor@latest/dist/index.min.js"></script> -->
 <script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
+
 <script>
 
     const E = window.wangEditor
@@ -248,13 +251,19 @@
             }
         },
         onChange(editor) {
-           const html = editor.getHtml()
+            const html = editor.getHtml()
             let title = $('#page_title').val()
             if (title === '' || title === undefined) {
                 title = '未命名标题'
             }
-            localStorage.setItem(title, html)
-            $('#title').val($('#page_title').val())
+            if (html.length > 50) {
+                localStorage.setItem('article_buffer', JSON.stringify({
+                    'title': title,
+                    'html': html
+                }))
+                $('#title').val($('#page_title').val())
+            }
+
         }
     }
     E.Boot.registerElemToHtml(imageToHtmlConf);
@@ -283,6 +292,14 @@
             editor.focus(true) // focus 到末尾
         }
     })
+
+    function restore() {
+        if (localStorage.getItem('article_buffer') !== null) {
+            let item = JSON.parse(localStorage.getItem('article_buffer'))
+            $('#page_title').val(item.title)
+            editor.dangerouslyInsertHtml(item.html)
+        }
+    }
 </script>
 <script>
     function submit(flag) {