Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
rpteam
rp
Commits
e5551869
Commit
e5551869
authored
Apr 23, 2017
by
cynddl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scores for up and down vote
parent
9f652de1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
apps/rp/models/vote.py
apps/rp/models/vote.py
+10
-1
apps/rp/templates/rp/article_list.html
apps/rp/templates/rp/article_list.html
+2
-2
No files found.
apps/rp/models/vote.py
View file @
e5551869
...
...
@@ -39,6 +39,8 @@ class UnDVotedMixin(models.Model):
und_votes
=
GenericRelation
(
UnDVotes
)
#: Score of the model
und_score
=
models
.
IntegerField
(
default
=
0
)
und_score_up
=
models
.
IntegerField
(
default
=
0
)
und_score_down
=
models
.
IntegerField
(
default
=
0
)
class
Meta
:
abstract
=
True
...
...
@@ -63,6 +65,7 @@ class UnDVotedMixin(models.Model):
diff_score
=
1
self
.
und_score
+=
diff_score
self
.
und_score_up
+=
diff_score
# Update self score, use update and filter to avoid triggering signals
self
.
__class__
.
objects
.
filter
(
id
=
self
.
id
).
update
(
und_score
=
F
(
"und_score"
)
+
diff_score
)
...
...
@@ -87,13 +90,19 @@ class UnDVotedMixin(models.Model):
diff_score
=
-
1
self
.
und_score
+=
diff_score
self
.
und_score_down
+=
diff_score
# Update self score, use update and filter to avoid triggering signals
self
.
__class__
.
objects
.
filter
(
id
=
self
.
id
).
update
(
und_score
=
F
(
"und_score"
)
+
diff_score
)
def
update_und_score
(
self
):
"""Reset score to the correct count (should not be necessary)"""
score
=
self
.
und_votes
.
aggregate
(
Sum
(
"score"
))[
"score__sum"
]
or
0
score_up
=
self
.
und_votes
.
filter
(
score
=
1
).
count
()
score_down
=
self
.
und_votes
.
filter
(
score
=-
1
).
count
()
score
=
score_up
+
score_down
self
.
und_score_up
=
score_up
self
.
und_score_down
=
score_down
self
.
und_score
=
score
# Update self score, use update and filter to avoid triggering signals
self
.
__class__
.
objects
.
filter
(
id
=
self
.
id
).
update
(
und_score
=
score
)
apps/rp/templates/rp/article_list.html
View file @
e5551869
...
...
@@ -61,8 +61,8 @@
<td
class=
"title-cell"
><a
target=
"_blank"
href=
"{{article.url}}"
><strong>
{{article.title}}
</strong></a></td>
<td>
<ul
class=
"votes-list"
>
<li><a
href=
""
>
+
3
<i
class=
"fa fa-thumbs-up"
aria-hidden=
"true"
style=
"color:green"
></i></a></li>
<li><a
href=
""
>
-
2
<i
class=
"fa fa-thumbs-down"
aria-hidden=
"true"
style=
"color:red"
></i></a></li>
<li><a
href=
""
>
+
{{article.und_score_up}}
<i
class=
"fa fa-thumbs-up"
aria-hidden=
"true"
style=
"color:green"
></i></a></li>
<li><a
href=
""
>
-
{{article.und_score_down}}
<i
class=
"fa fa-thumbs-down"
aria-hidden=
"true"
style=
"color:red"
></i></a></li>
</ul>
</td>
<td>
{{article.und_votes.first.username}}
</td>
...
...
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