aboutsummaryrefslogtreecommitdiffstats
path: root/servo
diff options
context:
space:
mode:
Diffstat (limited to 'servo')
-rw-r--r--servo/migrations/0053_auto_20160321_2013.py26
-rw-r--r--servo/migrations/0054_auto_20160321_2018.py26
-rw-r--r--servo/migrations/0055_auto_20160321_2027.py26
-rw-r--r--servo/models/note.py34
-rwxr-xr-xservo/templates/notes/list_notes.html2
-rw-r--r--servo/templates/notes/view_article.html4
-rwxr-xr-xservo/templates/notes/view_note.html4
-rw-r--r--servo/urls/note.py2
-rw-r--r--servo/views/note.py21
9 files changed, 132 insertions, 13 deletions
diff --git a/servo/migrations/0053_auto_20160321_2013.py b/servo/migrations/0053_auto_20160321_2013.py
new file mode 100644
index 0000000..22d7b2e
--- /dev/null
+++ b/servo/migrations/0053_auto_20160321_2013.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.4 on 2016-03-21 18:13
+from __future__ import unicode_literals
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('servo', '0052_auto_20160321_1835'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='article',
+ name='flagged_by',
+ field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), default=[], size=None),
+ ),
+ migrations.AlterField(
+ model_name='article',
+ name='read_by',
+ field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), default=[], size=None),
+ ),
+ ]
diff --git a/servo/migrations/0054_auto_20160321_2018.py b/servo/migrations/0054_auto_20160321_2018.py
new file mode 100644
index 0000000..d1c04d6
--- /dev/null
+++ b/servo/migrations/0054_auto_20160321_2018.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.4 on 2016-03-21 18:18
+from __future__ import unicode_literals
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('servo', '0053_auto_20160321_2013'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='article',
+ name='flagged_by',
+ field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), null=True, size=None),
+ ),
+ migrations.AlterField(
+ model_name='article',
+ name='read_by',
+ field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), null=True, size=None),
+ ),
+ ]
diff --git a/servo/migrations/0055_auto_20160321_2027.py b/servo/migrations/0055_auto_20160321_2027.py
new file mode 100644
index 0000000..496f868
--- /dev/null
+++ b/servo/migrations/0055_auto_20160321_2027.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.4 on 2016-03-21 18:27
+from __future__ import unicode_literals
+
+import django.contrib.postgres.fields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('servo', '0054_auto_20160321_2018'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='article',
+ name='flagged_by',
+ field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), default=[], size=None),
+ ),
+ migrations.AlterField(
+ model_name='article',
+ name='read_by',
+ field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), default=[], size=None),
+ ),
+ ]
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):
"""
diff --git a/servo/templates/notes/list_notes.html b/servo/templates/notes/list_notes.html
index 30fdb3d..187d421 100755
--- a/servo/templates/notes/list_notes.html
+++ b/servo/templates/notes/list_notes.html
@@ -35,7 +35,7 @@
<ul class="nav nav-list">
<li class="nav-header">{% trans "Messages" %}</li>
<li class="{% active request "inbox" %}"><a href="{% url 'notes-list_notes' kind="inbox" %}">{% trans "Inbox" %} <span class="badge pull-right">{{ inbox_count|safe }}</span></a></li>
- <li class="{% active request "articles" %}"><a href="{% url 'notes-list_notes' kind="articles" %}">{% trans "GSX" %}</a></li>
+ <li class="{% active request "articles" %}"><a href="{% url 'notes-list_notes' kind="articles" %}">{% trans "Articles" %}</a></li>
<li class="{% active request "flagged" %}"><a href="{% url 'notes-list_notes' kind="flagged" %}">{% trans "Flagged" %}</a></li>
<li class="{% active request "sent" %}"><a href="{% url 'notes-list_notes' kind="sent" %}">{% trans "Sent" %}</a></li>
<!--<li class="{% active request "escalations" %}"><a href="{% url 'notes-list_notes' kind="escalations" %}">{% trans "Escalations" %}</a></li>//-->
diff --git a/servo/templates/notes/view_article.html b/servo/templates/notes/view_article.html
index 99fd486..d0576eb 100644
--- a/servo/templates/notes/view_article.html
+++ b/servo/templates/notes/view_article.html
@@ -8,8 +8,8 @@
<i class="icon-flag"></i> <span class="caret"></span>
</a>
<ul class="dropdown-menu">
- <li><a href="{% url 'notes-toggle_flag' note.pk 'read' %}" class="nofollow">{{ note.get_read_title }}</a></li>
- <li><a href="{% url 'notes-toggle_flag' note.pk 'flagged' %}" class="nofollow">{{ note.get_flagged_title }}</a></li>
+ <li><a href="{% url 'notes-toggle_flag' 'articles' note.pk 'read' %}" class="nofollow">{{ read_title }}</a></li>
+ <li><a href="{% url 'notes-toggle_flag' 'articles' note.pk 'flagged' %}" class="nofollow">{{ flagged_title }}</a></li>
</ul>
</div>
{% endblock note_buttons %}
diff --git a/servo/templates/notes/view_note.html b/servo/templates/notes/view_note.html
index 05000f6..8f51406 100755
--- a/servo/templates/notes/view_note.html
+++ b/servo/templates/notes/view_note.html
@@ -8,8 +8,8 @@
<i class="icon-flag"></i> <span class="caret"></span>
</a>
<ul class="dropdown-menu">
- <li><a href="{% url 'notes-toggle_flag' note.pk 'read' %}" class="nofollow">{{ note.get_read_title }}</a></li>
- <li><a href="{% url 'notes-toggle_flag' note.pk 'flagged' %}" class="nofollow">{{ note.get_flagged_title }}</a></li>
+ <li><a href="{% url 'notes-toggle_flag' 'inbox' note.pk 'read' %}" class="nofollow">{{ note.get_read_title }}</a></li>
+ <li><a href="{% url 'notes-toggle_flag' 'inbox' note.pk 'flagged' %}" class="nofollow">{{ note.get_flagged_title }}</a></li>
</ul>
</div>
{% endblock note_buttons %}
diff --git a/servo/urls/note.py b/servo/urls/note.py
index 98bf1bb..5f74de3 100644
--- a/servo/urls/note.py
+++ b/servo/urls/note.py
@@ -19,7 +19,7 @@ urlpatterns = [
name="notes-create_to_customer"),
url(r'^(?P<pk>\d+)/toggle/tag/(?P<tag_id>\d+)/$', toggle_tag,
name="notes-toggle_tag"),
- url(r'^(?P<pk>\d+)/toggle/(?P<flag>[a-z]+)/$', toggle_flag,
+ url(r'^(?P<kind>\w+)/(?P<pk>\d+)/toggle_(?P<flag>[a-z]+)/$', toggle_flag,
name="notes-toggle_flag"),
url(r'^(?P<parent>\d+)/reply/$', edit, name="notes-reply"),
url(r'^(?P<pk>\d+)/edit/$', edit, name="notes-edit"),
diff --git a/servo/views/note.py b/servo/views/note.py
index 416e845..162b297 100644
--- a/servo/views/note.py
+++ b/servo/views/note.py
@@ -59,8 +59,7 @@ def prep_list_view(request, kind):
all_notes = Note.objects.all().order_by("-created_at")
if kind == "articles":
- all_notes = Article.objects.all()
- #all_notes = all_notes.filter(order=None).order_by("is_read", "-created_at")
+ all_notes = Article.objects.all().order_by('-date_created')
if kind == "inbox":
all_notes = all_notes.filter(order=None).order_by("is_read", "-created_at")
if kind == "sent":
@@ -287,7 +286,18 @@ def templates(request, template_id=None):
return render(request, 'notes/templates.html', {'templates': templates})
-def toggle_flag(request, pk, flag):
+def toggle_flag(request, kind, pk, flag):
+ if kind == 'articles':
+ note = get_object_or_404(Article, pk=pk)
+ if flag == 'flagged':
+ note.toggle_flagged(request.user)
+ return HttpResponse(note.get_flagged_title(request.user))
+ if flag == 'read':
+ note.toggle_read(request.user)
+ return HttpResponse(note.get_read_title(request.user))
+
+ return HttpResponse(getattr(note, 'get_%s_title' % flag)())
+
field = 'is_%s' % flag
note = get_object_or_404(Note, pk=pk)
attr = getattr(note, field)
@@ -318,12 +328,15 @@ def list_notes(request, kind="inbox"):
def view_note(request, kind, pk):
+ data = prep_list_view(request, kind)
+
if kind == 'articles':
note = get_object_or_404(Article, pk=pk)
+ data['read_title'] = note.get_read_title(request.user)
+ data['flagged_title'] = note.get_flagged_title(request.user)
else:
note = get_object_or_404(Note, pk=pk)
- data = prep_list_view(request, kind)
data['title'] = note.get_title()
data['note'] = note