Commit 361504f4 authored by cynddl's avatar cynddl

Implement priority on/off for the article lists

parent 7fef9c56
...@@ -37,3 +37,17 @@ class ArticleViewSet(viewsets.ModelViewSet): ...@@ -37,3 +37,17 @@ class ArticleViewSet(viewsets.ModelViewSet):
article = self.get_object() article = self.get_object()
article.downvote(user_object=request.user.username) article.downvote(user_object=request.user.username)
return self.response_serialized_object(article) return self.response_serialized_object(article)
@detail_route(methods=["post"], url_path="priority/on")
def priority_on(self, request, pk=None, priority=True):
article = self.get_object()
article.priority = True
article.save()
return self.response_serialized_object(article)
@detail_route(methods=["post"], url_path="priority/off")
def priority_off(self, request, pk=None, priority=True):
article = self.get_object()
article.priority = False
article.save()
return self.response_serialized_object(article)
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
<table class="article-table table table-sm my-4"> <table class="article-table table table-sm my-4">
<thead> <thead>
<tr> <tr>
<th>Priority</th> {% if filter_view != "published" %}<th>Priority</th>{% endif %}
<th>ID</th> <th>ID</th>
<th>Date</th> <th>Date</th>
<th>Language</th> <th>Language</th>
...@@ -90,12 +90,19 @@ ...@@ -90,12 +90,19 @@
{% for article in object_list|slice:":10" %} {% for article in object_list|slice:":10" %}
<tr id="row_empty_{{article.id}}" class="empty-row"><td colspan="8"></td></tr> <tr id="row_empty_{{article.id}}" class="empty-row"><td colspan="8"></td></tr>
<tr id="row_{{article.id}}"> <tr id="row_{{article.id}}">
<td class="icon-cell"><i class="fa fa-dot-circle-o" aria-hidden="true" style="color:red"></i></td> {% if filter_view != "published" %}
<td class="icon-cell actions-item" onclick="javascript:call_priority({{article.id}}, {{article.priority|yesno:"false,true"}})">
<i id="priority_{{article.id}}" class="fa fa-star{{ article.priority|yesno:",-o" }}" aria-hidden="true"></i>
</td>
{% endif %}
<td>{{article.id}}</td> <td>{{article.id}}</td>
<td>{{article.created_at |date:'d/m/y'}}<br />{{article.created_at |date:'H:i'}}</td> <td>{{article.created_at |date:'d/m/y'}}<br />{{article.created_at |date:'H:i'}}</td>
<td>{{article.lang}}</td> <td>{{article.lang}}</td>
<td class="title-cell"><a target="_blank" href="{{article.url}}"><strong>{{article.title}}</strong></a></td> <td class="title-cell"><a target="_blank" href="{{article.url}}"><strong>{{article.title}}</strong></a></td>
<td> <td>
{% if filter_view == "published" %}
{{article.und_score}}
{% else %}
<ul class="votes-list"> <ul class="votes-list">
<li class="actions-item" onclick="javascript:call_upvote({{article.id}})"> <li class="actions-item" onclick="javascript:call_upvote({{article.id}})">
<span id="count_up_{{article.id}}">{{article.und_score_up}}</span> <span id="count_up_{{article.id}}">{{article.und_score_up}}</span>
...@@ -106,8 +113,9 @@ ...@@ -106,8 +113,9 @@
<i class="fa fa-thumbs-down" aria-hidden="true" style="color:red"></i> <i class="fa fa-thumbs-down" aria-hidden="true" style="color:red"></i>
</li> </li>
</ul> </ul>
{% endif %}
</td> </td>
<td>{{article.und_votes.first.username}}</td> <td>{{article.created_by}}</td>
<td class="actions-cell"> <td class="actions-cell">
<ul class="actions-list"> <ul class="actions-list">
{% if filter_view == 'flux' %} {% if filter_view == 'flux' %}
...@@ -201,5 +209,12 @@ ...@@ -201,5 +209,12 @@
$("#row_tags_" + id).hide(); $("#row_tags_" + id).hide();
}); });
} }
function call_priority(id, flag) {
var url = "/api/articles/" + id + "/priority/" + (flag ? "on/" : "off/");
$.post(url, {'priority': flag}, function response(data) {
$("#priority_" + id).toggleClass("fa-star").toggleClass("fa-star-o");
});
}
</script> </script>
{% endblock %} {% endblock %}
...@@ -27,7 +27,7 @@ class ArticleListFlux(UDList): ...@@ -27,7 +27,7 @@ class ArticleListFlux(UDList):
qs = Article.objects.filter(status="PUBLISHED") qs = Article.objects.filter(status="PUBLISHED")
elif filter_view == "draft": elif filter_view == "draft":
qs = Article.objects.extra(where=[ qs = Article.objects.extra(where=[
"und_score_up + und_score_down >= 3", "(und_score_up + und_score_down >= 3) or priority",
"status='PENDING'" "status='PENDING'"
]) ])
elif filter_view == "rejected": elif filter_view == "rejected":
...@@ -41,7 +41,7 @@ class ArticleListFlux(UDList): ...@@ -41,7 +41,7 @@ class ArticleListFlux(UDList):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["filter_view"] = self.kwargs.get("filter_view", "draft") context["filter_view"] = self.kwargs.get("filter_view", "draft")
context["nb_draft"] = Article.objects.extra(where=[ context["nb_draft"] = Article.objects.extra(where=[
"und_score_up + und_score_down >= 3", "(und_score_up + und_score_down >= 3) or priority",
"status='PENDING'" "status='PENDING'"
]).count() ]).count()
return context return context
......
...@@ -55,12 +55,12 @@ table.article-table td.icon-cell { ...@@ -55,12 +55,12 @@ table.article-table td.icon-cell {
table.article-table ul { table.article-table ul {
padding: 0; padding: 0;
margin: 0; margin: 0;
}
& li.actions-item { .actions-item {
cursor: pointer; cursor: pointer;
&:--enter { &:--enter {
font-weight: 600; font-weight: 600;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment