Skip to content

Commit 8392b22

Browse files
committed
Do logic for save on cache if the notification was read or not
1 parent a45f45d commit 8392b22

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

dbaas/notification/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
url(r"^tasks_running/$", views.running_tasks_api, name="notification:tasks_running"),
99
url(r"^tasks_waiting/$", views.waiting_tasks_api, name="notification:tasks_waiting"),
1010
url(r"^database_tasks/(?P<database_id>\d+)/?$", views.database_tasks, name="notification:database_tasks"),
11-
url(r"^(?P<username>[\w\-\_\.]+)/user_tasks/?$", views.UserTasks.as_view(), name="notification:user_tasks"),
11+
# TODO: see why namespace notification: not work on templatetag {% url %}
12+
url(r"^(?P<username>[\w\-\_\.]*)/user_tasks/?$", views.UserTasks.as_view(), name="notification_user_tasks"),
1213

1314
)

dbaas/notification/views.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ def dispatch(self, request, *args, **kwargs):
7676

7777
@staticmethod
7878
def get_notifications(username):
79-
conn = get_redis_connection('notification')
80-
keys = conn.keys("task_users:{}:*".format(username))
81-
# TODO: can be better
82-
tasks = map(conn.hgetall, keys) if keys else []
83-
return sorted(tasks, key=lambda d: d['updated_at'], reverse=True)
79+
if username:
80+
conn = get_redis_connection('notification')
81+
keys = conn.keys("task_users:{}:*".format(username))
82+
# TODO: can be better
83+
tasks = map(conn.hgetall, keys) if keys else []
84+
return sorted(tasks, key=lambda d: d['updated_at'], reverse=True)
85+
return []
8486

8587
def get(self, *args, **kw):
8688
username = kw.get('username')
@@ -93,8 +95,15 @@ def post(self, *args, **kw):
9395
payload = json.loads(self.request.body)
9496
for task in payload.get('ids', []):
9597
key = "task_users:{}:{}".format(username, task['id'])
96-
task_status = conn.hget(key, 'task_status')
97-
if task_status == task['status']:
98-
conn.hset(key, 'is_new', 0)
98+
# TODO: Do all logic use fields
99+
fields = task.get('fields')
100+
if fields:
101+
for field in fields:
102+
field_key = field.keys()[0]
103+
conn.hset(key, field_key, field[field_key])
104+
else:
105+
task_status = conn.hget(key, 'task_status')
106+
if task_status == task['status']:
107+
conn.hset(key, 'is_new', 0)
99108

100109
return self.render_to_response('ok')

0 commit comments

Comments
 (0)