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