##// 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 * ``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,23 +684,14 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 if messages:
678 for message in messages:
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 payloads.append({
689 payloads.append({
688 'message': {
690 'message': {
689 'message': u'{}'.format(org_message),
691 'message': u'{}'.format(message.message),
690 'level': message.category,
692 'level': message.category,
691 'force': True,
693 'force': True,
692 'subdata': subdata
694 'subdata': message.sub_data
693 }
695 }
694 })
696 })
695 return json.dumps(payloads)
697 return json.dumps(payloads)
General Comments 0
You need to be logged in to leave comments. Login now