diff options
author | Filipp Lepalaan <filipp@mac.com> | 2016-03-21 20:37:11 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2016-03-21 20:37:11 +0200 |
commit | ec867584ef2078492d70b555ca419ea9e01dca8e (patch) | |
tree | 104c93fa71c67b18ad8e4221f8f1f9325178e04e /servo/models | |
parent | 1b6e5ee722f76f594e3d95dfa8d77ac2b9f2173a (diff) | |
download | Servo-ec867584ef2078492d70b555ca419ea9e01dca8e.tar.gz Servo-ec867584ef2078492d70b555ca419ea9e01dca8e.tar.bz2 Servo-ec867584ef2078492d70b555ca419ea9e01dca8e.zip |
Fixed article flag marking
Diffstat (limited to 'servo/models')
-rw-r--r-- | servo/models/note.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/servo/models/note.py b/servo/models/note.py index 40ce021..a598a95 100644 --- a/servo/models/note.py +++ b/servo/models/note.py @@ -637,8 +637,8 @@ class Article(models.Model): product_model = ArrayField(models.CharField(max_length=128), null=True, editable=False) - read_by = ArrayField(models.IntegerField(), null=True) - flagged_by = ArrayField(models.IntegerField(), null=True) + read_by = ArrayField(models.IntegerField(), default=[]) + flagged_by = ArrayField(models.IntegerField(), default=[]) def get_creation_date(self): return self.date_created @@ -651,7 +651,35 @@ class Article(models.Model): def get_title(self): return self.title - + + def get_read_title(self, user): + if user.pk in self.read_by: + return _('Mark as unread') + + return _('Mark as read') + + def get_flagged_title(self, user): + if user.pk in self.flagged_by: + return _('Mark as unflagged') + + return _('Mark as flagged') + + def toggle_read(self, user): + if user.pk in self.read_by: + self.read_by.remove(user.pk) + else: + self.read_by = self.read_by + [user.pk] + + return self.save() + + def toggle_flagged(self, user): + if user.pk in self.flagged_by: + self.flagged_by.remove(user.pk) + else: + self.flagged_by = self.flagged_by + [user.pk] + + return self.save() + @classmethod def from_gsx(cls, article): """ |