Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
361504f4
Commit
361504f4
authored
Apr 28, 2017
by
cynddl
Browse files
Implement priority on/off for the article lists
parent
7fef9c56
Changes
4
Hide whitespace changes
Inline
Side-by-side
apps/rp/api/views.py
View file @
361504f4
...
...
@@ -37,3 +37,17 @@ class ArticleViewSet(viewsets.ModelViewSet):
article
=
self
.
get_object
()
article
.
downvote
(
user_object
=
request
.
user
.
username
)
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
)
apps/rp/templates/rp/article_list.html
View file @
361504f4
...
...
@@ -76,7 +76,7 @@
<table
class=
"article-table table table-sm my-4"
>
<thead>
<tr>
<th>
Priority
</th>
{% if filter_view != "published" %}
<th>
Priority
</th>
{% endif %}
<th>
ID
</th>
<th>
Date
</th>
<th>
Language
</th>
...
...
@@ -90,12 +90,19 @@
{% for article in object_list|slice:":10" %}
<tr
id=
"row_empty_{{article.id}}"
class=
"empty-row"
><td
colspan=
"8"
></td></tr>
<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.created_at |date:'d/m/y'}}
<br
/>
{{article.created_at |date:'H:i'}}
</td>
<td>
{{article.lang}}
</td>
<td
class=
"title-cell"
><a
target=
"_blank"
href=
"{{article.url}}"
><strong>
{{article.title}}
</strong></a></td>
<td>
{% if filter_view == "published" %}
{{article.und_score}}
{% else %}
<ul
class=
"votes-list"
>
<li
class=
"actions-item"
onclick=
"javascript:call_upvote({{article.id}})"
>
<span
id=
"count_up_{{article.id}}"
>
{{article.und_score_up}}
</span>
...
...
@@ -106,8 +113,9 @@
<i
class=
"fa fa-thumbs-down"
aria-hidden=
"true"
style=
"color:red"
></i>
</li>
</ul>
{% endif %}
</td>
<td>
{{article.
und_votes.first.username
}}
</td>
<td>
{{article.
created_by
}}
</td>
<td
class=
"actions-cell"
>
<ul
class=
"actions-list"
>
{% if filter_view == 'flux' %}
...
...
@@ -201,5 +209,12 @@
$
(
"
#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>
{% endblock %}
apps/rp/views/articles.py
View file @
361504f4
...
...
@@ -27,7 +27,7 @@ class ArticleListFlux(UDList):
qs
=
Article
.
objects
.
filter
(
status
=
"PUBLISHED"
)
elif
filter_view
==
"draft"
:
qs
=
Article
.
objects
.
extra
(
where
=
[
"und_score_up + und_score_down >= 3"
,
"
(
und_score_up + und_score_down >= 3
) or priority
"
,
"status='PENDING'"
])
elif
filter_view
==
"rejected"
:
...
...
@@ -41,7 +41,7 @@ class ArticleListFlux(UDList):
context
=
super
().
get_context_data
(
**
kwargs
)
context
[
"filter_view"
]
=
self
.
kwargs
.
get
(
"filter_view"
,
"draft"
)
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'"
]).
count
()
return
context
...
...
static/src/components/table.css
View file @
361504f4
...
...
@@ -55,12 +55,12 @@ table.article-table td.icon-cell {
table
.article-table
ul
{
padding
:
0
;
margin
:
0
;
}
&
li
.actions-item
{
cursor
:
pointer
;
.actions-item
{
cursor
:
pointer
;
&:--enter
{
font-weight
:
600
;
}
&:--enter
{
font-weight
:
600
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment