Popup window not displaying Django messages

1.2k Views Asked by At

I have a Django website that displays different gantt charts based on user selections. I have a bunch of Django's logging messages in my code and want to be able to set and then display in a popup window once the user hits a submit button, but I can't seem to get the messages to display in the popup.

My views.py looks like this:

from django.contrib import messages

def gantt_search(request):

  if request.method == 'POST':
    messages.info(request,"Query submitted, beginning query results render for:")

    form_start = WINDOW_START_Form(request.POST,section_label="WINDOW_START")

    if form_start.is_valid():
        WS_raw = form_start.cleaned_data['WINDOW_START']
        messages.info(request,"Window Start time: {WS}".format(WS=WS_raw))

    else:
        messages.error(request,"The start date you entered is incorrectly formatted.")

  else:
    messages.info(request,"Rendering query page")
    form_start = WINDOW_START_Form(section_label="WINDOW_START")

  return render(request, 'InterfaceApp/table_search.html', {'window_start': form_start})

def msgs(request):
   m = messages.get_messages(request)
   return render_to_response('InterfaceApp/messages.html',{'message':m})

The results template contains the code I have to display the popup link and looks like this:

<html>
  <head>
    <title>Search Results</title>
    <meta charset="utf-8">
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script language="javascript" type="text/javascript">
      function popitup(url) {
          newwindow=window.open(url,'{{title}}','height=200,width=150');
          if (window.focus) {newwindow.focus()}
          return false;
      }
    </script>
  </head>
  <body>
    <div class="container">
      <a href="messages.html" onclick="return popitup('/InterfaceApp/msgs')" > {% trans 'View Log Messages' %}
      </a>
    </div>
  </body>
</html>

The messages.html template looks like this:

<body>
 <div class="container">
  <h2>Messages</h2>
  {{ message }}
 </div>
 <div class="containter">
  {% if messages %}
  <ul class="messages">
      {% for message in messages %}
      <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
          {% if message.level == DEFAULT_MESSAGE_LEVELS.DEBUG %}Important: {% endif %}
          {{ message }}
      </li>
      {% endfor %}
  </ul>
  {% endif %}
 </div>
</body>

The popup window works alright, but when it opens I see <django.contrib.messages.storage.fallback.FallbackStorage object at 0x10965bdd0> instead of a list of the messages. The messages do display correctly at the top of my results page when it's rendered but I don't want them there.

Can anyone tell me how to fix this?

Thanks!

0

There are 0 best solutions below