Commit 2df9d57f authored by Okhin's avatar Okhin
Browse files

Removing the flag logic, it's useless and can be done via update commands

parent f49a1bfe
Pipeline #2653 passed with stages
in 3 minutes and 43 seconds
...@@ -6,6 +6,6 @@ router = routers.DefaultRouter() ...@@ -6,6 +6,6 @@ router = routers.DefaultRouter()
router.register(r"articles", ArticleViewSet) router.register(r"articles", ArticleViewSet)
router.register(r"articles-by-tag/(?P<filter_tag>.+)", ArticleTag) 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 urlpatterns = router.urls
...@@ -96,6 +96,15 @@ class ArticleViewSet(ArticleMixin, ArticleFilterMixin, viewsets.ModelViewSet): ...@@ -96,6 +96,15 @@ class ArticleViewSet(ArticleMixin, ArticleFilterMixin, viewsets.ModelViewSet):
Set the boolean priority of an article to False. Set the boolean priority of an article to False.
permissions ```rp.can_change_priority``` permissions ```rp.can_change_priority```
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() queryset = Article.objects.all()
serializer_class = ArticleSerializer serializer_class = ArticleSerializer
...@@ -126,36 +126,6 @@ class Article(models.Model): ...@@ -126,36 +126,6 @@ class Article(models.Model):
""" Returns article title. """ """ Returns article title. """
return self.title return self.title
# Flags logic
def toggle_speak(self):
"""Toggle the speak flag"""
self.speak = not self.speak
def toggle_archive(self):
"""Toggle the archive flag"""
self.archive = not self.archive
def toggle_quote(self):
"""Toggle the quote flag"""
self.quote = not self.quote
@transition(field=status, source=['DRAFT', 'NEW', 'PUBLISHED'],
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
return self.status
# Finite state logic # Finite state logic
@transition(field=status, source='DRAFT', target='PUBLISHED', @transition(field=status, source='DRAFT', target='PUBLISHED',
permission="rp.can_change_status") permission="rp.can_change_status")
...@@ -55,47 +55,6 @@ class TestArticle(TestCase): ...@@ -55,47 +55,6 @@ class TestArticle(TestCase):
assert not self.article.quote assert not self.article.quote
assert not self.article.speak assert not self.article.speak
def test_toggle_flags(self):
assert self.newarticle.archive
assert not self.newarticle.archive
assert self.newarticle.quote
assert not self.newarticle.quote
assert self.newarticle.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
assert not self.newarticle.archive
assert not self.newarticle.speak
assert not self.newarticle.quote
assert not self.newarticle.archive
assert self.newarticle.speak
assert not self.newarticle.quote
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): def test_update(self):
old_title = self.article.title old_title = self.article.title
self.article.title = old_title[::-1] self.article.title = old_title[::-1]
Supports Markdown
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