소스 검색

样式调整

yangchaojie 1 일 전
부모
커밋
0ae5df9f4d
3개의 변경된 파일34개의 추가작업 그리고 1개의 파일을 삭제
  1. 22 1
      blog/controller/article.py
  2. 1 0
      blog/router/article_url/article_url.py
  3. 11 0
      templates/management/article/article.html

+ 22 - 1
blog/controller/article.py

@@ -4,7 +4,8 @@ from datetime import datetime
 from django.contrib.auth.decorators import login_required
 from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
 from django.http import JsonResponse, HttpResponseRedirect
-from django.shortcuts import render
+from django.shortcuts import render, redirect
+from django.urls import reverse
 
 import blog
 from blog import models
@@ -37,6 +38,26 @@ def draft(request):
                                                    draft=True)
     return render(request, 'management/article/draft.html', context={'articles': articles})
 
+@login_required(login_url='/login')
+def set_status(request,pk):
+
+    article = models.Article.objects.filter(id=int(pk)).first()
+    if article is not None:
+        if article.status == 0:
+            article.status = 1
+        else:
+            article.status = 0
+        article.save()
+        # 把所有 GET 参数重新编码(可能包含 page,也可能不包含)
+        query = request.GET.urlencode()  # e.g. "page=2&foo=bar" 或者 ""
+
+        # 构造基础列表页 URL
+        base = '/management/article'  # 或者直接 '/management/article'
+
+        # 如果有任何查询参数,就拼接 ?xxx,否则直接跳
+        redirect_url = f'{base}?{query}' if query else base
+        return redirect(redirect_url)
+
 
 @login_required(login_url='/login')
 def cancel_show_index(request, pk):

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

@@ -29,5 +29,6 @@ urlpatterns = [
     path(r'<pk>.html', article.show_article),
     path('edit_article', article.edit_article),
     path('delete_article', article.delete_article),
+    path('set_status/<pk>', article.set_status),
 ]
 urlpatterns += staticfiles_urlpatterns()

+ 11 - 0
templates/management/article/article.html

@@ -47,6 +47,17 @@
                     <strong style="color: orange">草稿</strong>
                 {% endif %} </td>
                 <td><a onclick="deleteConfirm({{ article.id }})" href="#" class="button" style="color: red">删除</a>
+                    {% if request.GET.page %}
+                        <a href="/management/article/set_status/{{ article.id }}?page={{ request.GET.page }}"
+                           class="button">
+                    {% else %}
+                        <a href="/management/article/set_status/{{ article.id }}" class="button">
+                    {% endif %}                        {% if  article.status == 0 %}
+                        发布
+                    {% elif article != 0 %}
+                        设为草稿
+                    {% endif %}
+                    </a>
                 </td>
             </tr>
         {% endfor %}