| __author__ = 'hanl' |
| |
| |
| class MessageHandler(object): |
| def isError(self, response): |
| pass |
| |
| def notifyNext(self, json, notify_func): |
| pass |
| |
| |
| class NotificationHandler(MessageHandler): |
| def __init__(self): |
| pass |
| |
| def isError(self, response): |
| try: |
| raw_json = response.json() |
| if raw_json.get('errors') or raw_json.get('error') or raw_json.get('err'): |
| return True |
| except ValueError: |
| if response.status_code != 200: |
| return True |
| return False |
| |
| def getMessage(self, response): |
| pass |
| |
| def notifyNext(self, json, notify_func): |
| print "having a notification %s" % str(json) |
| if json.get('errors'): |
| for error in json.get("errors"): |
| notify_func(error[1], "danger") |
| elif json.get('error'): |
| if json.get('error_description'): |
| notify_func(json.get('error_description'), "danger") |
| else: |
| notify_func(json.get('error'), "danger") |
| elif json.get('err'): |
| notify_func(json.get('errstr'), "danger") |
| return None |
| |
| def getLocalized(self, code): |
| # return _("status_" + str(code)) |
| return "this is a default message" |
| |