CJ hai 11 meses
pai
achega
ee10ee8e06

+ 7 - 0
blog/controller/article.py

@@ -45,6 +45,13 @@ def cancel_show_index(request, pk):
     article.save()
     return HttpResponseRedirect('/')  # 跳转到主界面
 
+@login_required(login_url='/login')
+def show_show_index(request, pk):
+    article = models.Article.objects.get(id=int(pk))
+    article.is_top = True
+    article.save()
+    return HttpResponseRedirect('/')  # 跳转到主界面
+
 
 def new(request):
     return render(request, 'management/article/new_article.html')

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

@@ -25,6 +25,7 @@ urlpatterns = [
     path('get_all_article', article.get_all_article),
     path('to_edit/<pk>', article.to_edit),
     path('cancel_show_index/<pk>', article.cancel_show_index),
+    path('show_show_index/<pk>', article.show_show_index),
     path(r'<pk>.html', article.show_article),
     path('edit_article', article.edit_article),
     path('delete_article', article.delete_article),

+ 8 - 2
templates/category.html

@@ -98,7 +98,10 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a></div>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
+                                          {% if  is_login %}
+                                                <a title="置顶" href="/article/show_show_index/{{ item.id }}"><i class="icon home"></i></a>
+                                            {% endif %}</div>
                                         <div class="extra text">{{ item.intro }}
                                             &nbsp;&nbsp;&nbsp;Tags:
                                             {% for tag in item.tags %}
@@ -118,7 +121,10 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a></div>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
+                                          {% if  is_login %}
+                                                <a title="置顶" href="/article/show_show_index/{{ item.id }}"><i class="icon home"></i></a>
+                                            {% endif %}</div>
                                         {% autoescape off %}
                                             <div class="extra images">
                                                 {{ item.html_text }}

+ 7 - 3
templates/index.html

@@ -14,7 +14,7 @@
                     <div class="ui divider"></div>
                     {% for item in articles_new %}
                         {% if item.status == 1 %}
-                            {% if item.type == 1 %}
+                            {% if item.type == 1  and item.is_top%}
                                 <div class="event">
                                     <div class="label">
                                         <img src="/user_avatar/{{ item.user_id }}">
@@ -25,7 +25,11 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a></div>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
+                                            {% if  is_login %}
+                                                <a title="取消置顶" href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
+                                            {% endif %}</div>
+
                                         <div class="extra text">{{ item.intro }}
                                             &nbsp;&nbsp;&nbsp;Tags:
                                             {% for tag in item.tags %}
@@ -47,7 +51,7 @@
                                             发布了{{ item.category__name }}:<a
                                                     href="/article/{{ item.id }}.html">{{ item.title }}</a>
                                             {% if  is_login %}
-                                                <a href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
+                                                <a title="取消置顶" href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
                                             {% endif %}</div>
 
                                         {% if '<iframe' in item.intro %}