Commit 85ceb07a authored by okhin's avatar okhin 🚴

Merge branch '58-la-methode-set_flags-ne-fonctionne-pas' into 'rp2'

Resolve "La méthode set_flags ne fonctionne pas"

See merge request !50
parents f49a1bfe 2df9d57f
Pipeline #2655 passed with stages
in 4 minutes and 45 seconds
......@@ -6,6 +6,6 @@ router = routers.DefaultRouter()
router.register(r"articles", ArticleViewSet)
router.register(r"articles-by-tag/(?P<filter_tag>.+)", ArticleTag)
# router.register(r"articles-search/(?P<search_keywords>.+)", ArticleSearch)
router.register(r"articles-search/(?P<search_keywords>.+)", ArticleSearch)
urlpatterns = router.urls
......@@ -96,6 +96,15 @@ class ArticleViewSet(ArticleMixin, ArticleFilterMixin, viewsets.ModelViewSet):
Set the boolean priority of an article to False.
permissions ```rp.can_change_priority```
set_flags:
Set the boolean value of flags of an article. The flags are given as a
dictionary of boolean such as :
{ 'quote': True, 'speak': False, 'archive': False }
There is currently no other flags.
permissions ```rp.can_edit```
"""
queryset = Article.objects.all()
serializer_class = ArticleSerializer
......
......@@ -126,36 +126,6 @@ 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()
def toggle_archive(self):
"""Toggle the archive flag"""
self.archive = not self.archive
self.save()
def toggle_quote(self):
"""Toggle the quote flag"""
self.quote = not self.quote
self.save()
@transition(field=status, source=['DRAFT', 'NEW', 'PUBLISHED'],
target=RETURN_VALUE('DRAFT', 'NEW', 'PUBLISHED',),
permission="rp.can_edit")
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.status
# Finite state logic
@transition(field=status, source='DRAFT', target='PUBLISHED',
permission="rp.can_change_status")
......
......@@ -55,47 +55,6 @@ class TestArticle(TestCase):
assert not self.article.quote
assert not self.article.speak
def test_toggle_flags(self):
self.newarticle.toggle_archive()
assert self.newarticle.archive
self.newarticle.toggle_archive()
assert not self.newarticle.archive
self.newarticle.toggle_quote()
assert self.newarticle.quote
self.newarticle.toggle_quote()
assert not self.newarticle.quote
self.newarticle.toggle_speak()
assert self.newarticle.speak
self.newarticle.toggle_speak()
assert not self.newarticle.speak
def test_set_flags(self):
# Method signature is set_flags(boolean: archive = False,
# boolean: speak = False,
# boolean: quote = False)
# All falsg set to their default values
self.newarticle.set_flags()
assert not self.newarticle.archive
assert not self.newarticle.speak
assert not self.newarticle.quote
self.newarticle.set_flags(speak=True)
assert not self.newarticle.archive
assert self.newarticle.speak
assert not self.newarticle.quote
self.newarticle.set_flags(quote=True)
assert not self.newarticle.archive
assert not self.newarticle.speak
assert self.newarticle.quote
self.newarticle.set_flags(quote=True, speak=True)
assert not self.newarticle.archive
assert self.newarticle.speak
assert self.newarticle.quote
def test_update(self):
old_title = self.article.title
self.article.title = old_title[::-1]
......
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