Show More
@@ -598,9 +598,10 b' class _Message(object):' | |||||
598 | * ``category``: the category specified when the message was created. |
|
598 | * ``category``: the category specified when the message was created. | |
599 | """ |
|
599 | """ | |
600 |
|
600 | |||
601 | def __init__(self, category, message): |
|
601 | def __init__(self, category, message, sub_data=None): | |
602 | self.category = category |
|
602 | self.category = category | |
603 | self.message = message |
|
603 | self.message = message | |
|
604 | self.sub_data = sub_data or {} | |||
604 |
|
605 | |||
605 | def __str__(self): |
|
606 | def __str__(self): | |
606 | return self.message |
|
607 | return self.message | |
@@ -663,7 +664,17 b' class Flash(object):' | |||||
663 | # of strings. |
|
664 | # of strings. | |
664 | for cat in self.categories: |
|
665 | for cat in self.categories: | |
665 | for msg in session.pop_flash(queue=cat): |
|
666 | for msg in session.pop_flash(queue=cat): | |
666 | messages.append(_Message(cat, msg)) |
|
667 | sub_data = {} | |
|
668 | if hasattr(msg, 'rsplit'): | |||
|
669 | flash_data = msg.rsplit('|DELIM|', 1) | |||
|
670 | org_message = flash_data[0] | |||
|
671 | if len(flash_data) > 1: | |||
|
672 | sub_data = json.loads(flash_data[1]) | |||
|
673 | else: | |||
|
674 | org_message = msg | |||
|
675 | ||||
|
676 | messages.append(_Message(cat, org_message, sub_data=sub_data)) | |||
|
677 | ||||
667 | # Map messages from the default queue to the 'notice' category. |
|
678 | # Map messages from the default queue to the 'notice' category. | |
668 | for msg in session.pop_flash(): |
|
679 | for msg in session.pop_flash(): | |
669 | messages.append(_Message('notice', msg)) |
|
680 | messages.append(_Message('notice', msg)) | |
@@ -673,25 +684,16 b' class Flash(object):' | |||||
673 |
|
684 | |||
674 | def json_alerts(self, session=None, request=None): |
|
685 | def json_alerts(self, session=None, request=None): | |
675 | payloads = [] |
|
686 | payloads = [] | |
676 | messages = flash.pop_messages(session=session, request=request) |
|
687 | messages = flash.pop_messages(session=session, request=request) or [] | |
677 |
|
|
688 | for message in messages: | |
678 | for message in messages: |
|
689 | payloads.append({ | |
679 |
|
|
690 | 'message': { | |
680 |
|
|
691 | 'message': u'{}'.format(message.message), | |
681 | flash_data = message.message.rsplit('|DELIM|', 1) |
|
692 | 'level': message.category, | |
682 | org_message = flash_data[0] |
|
693 | 'force': True, | |
683 |
|
|
694 | 'subdata': message.sub_data | |
684 | subdata = json.loads(flash_data[1]) |
|
695 | } | |
685 |
|
|
696 | }) | |
686 | org_message = message.message |
|
|||
687 | payloads.append({ |
|
|||
688 | 'message': { |
|
|||
689 | 'message': u'{}'.format(org_message), |
|
|||
690 | 'level': message.category, |
|
|||
691 | 'force': True, |
|
|||
692 | 'subdata': subdata |
|
|||
693 | } |
|
|||
694 | }) |
|
|||
695 | return json.dumps(payloads) |
|
697 | return json.dumps(payloads) | |
696 |
|
698 | |||
697 | def __call__(self, message, category=None, ignore_duplicate=True, |
|
699 | def __call__(self, message, category=None, ignore_duplicate=True, |
General Comments 0
You need to be logged in to leave comments.
Login now