Skip to content

Commit

Permalink
Merge pull request #24 from gojuukaze/dev
Browse files Browse the repository at this point in the history
v2.0.3
  • Loading branch information
gojuukaze authored Dec 30, 2020
2 parents e9cfd55 + acd81e4 commit 2b5ada3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/app_models/content_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Meta:

created_time = models.DateTimeField(verbose_name="创建时间", default=timezone.now, editable=False)
modified_time = models.DateTimeField(verbose_name="修改时间", auto_now=True)
sorted_num = models.IntegerField(verbose_name="排序号", default=0)

def __str__(self):
if len(self.title) <= 15:
Expand Down
2 changes: 1 addition & 1 deletion app/db_manager/content_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_article_by_title(title):


def filter_article_order_by_id(desc=True):
return Article.objects.filter().order_by('-id' if desc else 'id')
return Article.objects.filter().order_by("-sorted_num", '-id' if desc else 'id')


def all_article():
Expand Down
18 changes: 18 additions & 0 deletions app/migrations/0005_article_sorted_num.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.9 on 2020-12-29 15:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app', '0004_auto_20191207_1737'),
]

operations = [
migrations.AddField(
model_name='article',
name='sorted_num',
field=models.IntegerField(default=0, verbose_name='排序号'),
),
]
7 changes: 7 additions & 0 deletions app/templates/app/admin/article_title.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<a href="{% url 'admin:app_article_change' article.id %}">编辑</a> |
<a href="{{ article.url }}" target="_blank">查看</a> |
<a id='copy_a_url{{ article.id }}' href="javascript:void(0);" data-clipboard-text="{{ article.url }}">复制链接</a> |
<a href="{% url 'app:set_article_top' article.id %}">
{% if article.sorted_num != 0 %}
取消置顶
{% else%}
置顶
{% endif %}
</a> |

<a href="{% url 'admin:app_article_delete' article.id %}" style="color: red">删除</a>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/urls/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
urlpatterns = [
path('', views_class.Home.as_view(), name='index'),
path('article/<int:article_id>', views_class.DetailArticle.as_view(), name='detail_article'),
path('article/set_top/<int:article_id>', views.set_article_top_view, name='set_article_top'),

path('category/<int:category_id>', views_class.CategoryArticle.as_view(), name='category_article'),
path('tag/<int:tag_id>', views_class.TagArticle.as_view(), name='tag_article'),
Expand Down
18 changes: 18 additions & 0 deletions app/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.shortcuts import render
from django.urls import reverse
from django.views.decorators.csrf import requires_csrf_token
from django.core.exceptions import ObjectDoesNotExist

from app.db_manager.config_manager import get_config_by_id
from app.db_manager.content_manager import get_article_meta_by_article, get_article_by_id
Expand Down Expand Up @@ -100,3 +101,20 @@ def get_config_html(request, config_id):
{'schema': config.v2_schema,
'value': json.dumps(config.v2_config),
'script': config.v2_script})


@permission_required('app', raise_exception=True)
def set_article_top_view(request, article_id):
"""
设置置顶/取消置顶
"""
try:
article_obj = get_article_by_id(article_id)
if article_obj.sorted_num:
article_obj.sorted_num = 0
else:
article_obj.sorted_num = 1
article_obj.save()
except:
raise ObjectDoesNotExist()
return HttpResponseRedirect(reverse('admin:app_article_changelist'))
3 changes: 3 additions & 0 deletions base_theme/templates/base_theme/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<div class="box">
<h1 class="title">
<a class="red_a" href="{% url 'app:detail_article' a.id %}">{{ a.title }}</a>
{% if a.sorted_num != 0 %}
<span style="font-size: 15px; float: right">[置顶]</span>
{% endif %}
</h1>
<div class="field is-grouped is-grouped-multiline" style="color: #aaa">
<span class="icon"><i class="far fa-calendar-alt"></i></span>
Expand Down

0 comments on commit 2b5ada3

Please sign in to comment.