@@ -76,11 +76,13 @@ def dispatch(self, request, *args, **kwargs):
76
76
77
77
@staticmethod
78
78
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 []
84
86
85
87
def get (self , * args , ** kw ):
86
88
username = kw .get ('username' )
@@ -93,8 +95,15 @@ def post(self, *args, **kw):
93
95
payload = json .loads (self .request .body )
94
96
for task in payload .get ('ids' , []):
95
97
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 )
99
108
100
109
return self .render_to_response ('ok' )
0 commit comments