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
9c347d50
Commit
9c347d50
authored
May 15, 2019
by
Okhin
Browse files
Adding boolean flags and methos on the Article
parent
3aed3da5
Pipeline
#2604
passed with stages
in 3 minutes and 8 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/migrations/0022_auto_20190515_1050.py
0 → 100644
View file @
9c347d50
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2019-05-15 10:50
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'rp'
,
'0021_auto_20190507_1438'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'article'
,
name
=
'archive'
,
field
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'Article archived'
),
),
migrations
.
AddField
(
model_name
=
'article'
,
name
=
'quote'
,
field
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'Article directly quotes us'
),
),
migrations
.
AddField
(
model_name
=
'article'
,
name
=
'speak'
,
field
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'Article speaks of us'
),
),
]
apps/rp/models.py
View file @
9c347d50
...
...
@@ -91,12 +91,23 @@ class Article(models.Model):
#: priority: True if article have priority
priority
=
models
.
BooleanField
(
default
=
False
)
#:
Comma separated list of short tags to describe the article (eg: "Privacy", "Copyright").
#:
List of tags used to add subject and topics to an article
tags
=
TaggableManager
(
blank
=
True
)
#: Score of the article, modifiedby upvote and downvote methods
score
=
models
.
IntegerField
(
default
=
0
)
#: If the publication is "archived" (not visible by default from the public
#: feeds), this flag is set to True
archive
=
models
.
BooleanField
(
_
(
"Article archived"
),
default
=
False
)
#: If the article is quoting something LQDN said or wrote
quote
=
models
.
BooleanField
(
_
(
"Article directly quotes us"
),
default
=
False
)
#: If the article speaks about something LQDN did or wrote
speak
=
models
.
BooleanField
(
_
(
"Article speaks of us"
),
default
=
False
)
class
Meta
:
verbose_name
=
_
(
"Article"
)
verbose_name_plural
=
_
(
"Articles"
)
...
...
@@ -115,6 +126,36 @@ class Article(models.Model):
""" Returns article title. """
return
self
.
title
# Flags logic
def
toggle_speak
(
self
):
"""Toggle the speak flag"""
self
.
speak
=
not
self
.
speak
self
.
save
()
return
self
def
toggle_archive
(
self
):
"""Toggle the archive flag"""
self
.
archive
=
not
self
.
archive
self
.
save
()
return
self
def
toggle_quote
(
self
):
"""Toggle the quote flag"""
self
.
quote
=
not
self
.
quote
self
.
save
()
return
self
def
set_flags
(
self
,
archive
=
False
,
speak
=
False
,
quote
=
False
):
"""
This method is used to set _all_ the flags in the state their given as
arguments of this method. The default is False which will unset all flags.
"""
self
.
archive
=
archive
self
.
speak
=
speak
self
.
quote
=
quote
self
.
save
()
return
self
# Finite state logic
@
transition
(
field
=
status
,
source
=
'DRAFT'
,
target
=
'PUBLISHED'
,
...
...
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