Skip to content
GitLab
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
60d8e115
Commit
60d8e115
authored
Apr 22, 2017
by
luxcem
Browse files
moves rp models and adds votes migrations
parent
ec33d53e
Changes
4
Hide whitespace changes
Inline
Side-by-side
apps/rp/migrations/0002_undvotes.py
0 → 100644
View file @
60d8e115
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-04-22 14:18
from
__future__
import
unicode_literals
from
django.conf
import
settings
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
migrations
.
swappable_dependency
(
settings
.
AUTH_USER_MODEL
),
(
'contenttypes'
,
'0002_remove_content_type_name'
),
(
'rp'
,
'0001_initial'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'UnDVotes'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'score'
,
models
.
IntegerField
(
default
=
True
)),
(
'object_id'
,
models
.
PositiveIntegerField
()),
(
'content_type'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'contenttypes.ContentType'
)),
(
'user'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
settings
.
AUTH_USER_MODEL
)),
],
),
]
apps/rp/models/__init__.py
View file @
60d8e115
from
.vote
import
UnDVotes
,
UnDVotedMixin
# noqa
from
.article
import
Article
# noqa
apps/rp/models.py
→
apps/rp/models
/article
.py
View file @
60d8e115
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
taggit.managers
import
TaggableManager
from
.vote
import
UnDVotedMixin
class
Article
(
models
.
Model
):
class
Article
(
UnDVotedMixin
):
url
=
models
.
URLField
(
"URL"
)
lang
=
models
.
CharField
(
_
(
"Language"
),
max_length
=
50
)
metadata
=
models
.
TextField
(
_
(
"Opengraph metadata"
))
...
...
apps/rp/models/vote
s
.py
→
apps/rp/models/vote.py
View file @
60d8e115
...
...
@@ -36,6 +36,9 @@ class UnDVotedMixin(models.Model):
#: Score of the model
und_score
=
models
.
IntegerField
(
default
=
0
)
class
Meta
:
abstract
=
True
def
upvote
(
self
,
user
):
diff_score
=
0
try
:
...
...
@@ -86,6 +89,3 @@ class UnDVotedMixin(models.Model):
score
=
self
.
und_votes
.
aggregate
(
Sum
(
"score"
))[
"score__sum"
]
or
0
# Update self score, use update and filter to avoid triggering signals
self
.
__class__
.
objects
.
filter
(
id
=
self
.
id
).
update
(
und_score
=
score
)
class
Meta
:
abstract
=
True
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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