[cig-commits] r12060 - in cs/portal/trunk/northridge/SeismoWebPortal: . templates/SeismoWebPortal

leif at geodynamics.org leif at geodynamics.org
Fri May 30 08:48:39 PDT 2008


Author: leif
Date: 2008-05-30 08:48:39 -0700 (Fri, 30 May 2008)
New Revision: 12060

Modified:
   cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
   cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html
Log:
Fixed CMT parser crash when results are returned from the "quick" CMT
catalog.


Modified: cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py	2008-05-30 04:41:42 UTC (rev 12059)
+++ cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py	2008-05-30 15:48:39 UTC (rev 12060)
@@ -507,6 +507,7 @@
     @classmethod
     def search(cls, request):
         import urllib2
+        from itertools import chain
 
         if not request.GET.get('itype'):
             t = loader.get_template('SeismoWebPortal/event_search.html')
@@ -527,7 +528,7 @@
         src.close()
 
         # Make sure secondary objects exist in the database.
-        for event in parser.cmtList:
+        for event in chain(parser.cmtList, parser.quickCMTList):
             # The try-get()-except shouldn't be necessary, but simply
             # using save() causes Django to die in the database backend.
             try:
@@ -542,7 +543,8 @@
                 r.save()
 
         t = loader.get_template('SeismoWebPortal/event_search_results.html')
-        c = Context({'event_list': parser.cmtList,
+        c = Context({'eventCount': len(parser.cmtList) + len(parser.quickCMTList),
+                     'eventList': chain(parser.cmtList, parser.quickCMTList),
                      'error': parser.error,
                      'root': request.root,
                      })
@@ -575,6 +577,8 @@
         HTMLParser.__init__(self)
         self.state = 0
         self.cmtList = []
+        self.quickCMTList = []
+        self.currentCMTList = self.cmtList
         self.error = None
         
     def handle_starttag(self, tag, attrs):
@@ -605,7 +609,10 @@
             elif data.startswith('CMT search error'):
                 self.state = -1
         elif self.state == 3:
-            self.cmtList = cmt.CMTSolution.parse(StringIO(data))
+            if data == 'From Quick CMT catalog':
+                self.currentCMTList = self.quickCMTList
+                return
+            self.currentCMTList.extend(cmt.CMTSolution.parse(StringIO(data)))
         elif self.state == -2:
             self.error = data
             self.state = -3

Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html	2008-05-30 04:41:42 UTC (rev 12059)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/event_search_results.html	2008-05-30 15:48:39 UTC (rev 12060)
@@ -5,7 +5,7 @@
 <p><span class=error>{{ error }}</span></p>
 {% endif %}
 
-{% if event_list %}
+{% if eventCount %}
     <table rules=cols>
         <colgroup><col class=odd><col class=even><col class=odd><col class=even><col class=odd><col class=even><col class=odd></colgroup>
 
@@ -22,7 +22,7 @@
         </thead>
 
         <tbody>
-        {% for event in event_list %}
+        {% for event in eventList %}
         <tr class="{% cycle odd,even %}">
             <td>
                 <!-- an inline event creation form, already filled-out -->



More information about the cig-commits mailing list