##// END OF EJS Templates
flash: fixed display problem with flash messages on error pages.
marcink -
r4219:237de134 stable
parent child Browse files
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,23 +684,14 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 if messages:
687 messages = flash.pop_messages(session=session, request=request) or []
678 688 for message in messages:
679 subdata = {}
680 if hasattr(message.message, 'rsplit'):
681 flash_data = message.message.rsplit('|DELIM|', 1)
682 org_message = flash_data[0]
683 if len(flash_data) > 1:
684 subdata = json.loads(flash_data[1])
685 else:
686 org_message = message.message
687 689 payloads.append({
688 690 'message': {
689 'message': u'{}'.format(org_message),
691 'message': u'{}'.format(message.message),
690 692 'level': message.category,
691 693 'force': True,
692 'subdata': subdata
694 'subdata': message.sub_data
693 695 }
694 696 })
695 697 return json.dumps(payloads)
General Comments 0
You need to be logged in to leave comments. Login now