Index: trunk/ippToPsps/jython/objectbatch.py
===================================================================
--- trunk/ippToPsps/jython/objectbatch.py	(revision 33687)
+++ trunk/ippToPsps/jython/objectbatch.py	(revision 33688)
@@ -96,20 +96,22 @@
     def insertMags(self, cpsTable):
 
-        # do this properly with photcode table
-        filters = ['g', 'r', 'i', 'z', 'y']
+        # list of all filters we are interested in
+        allFilters = ['g', 'r', 'i', 'z', 'y']
         
+        # this loop looks into the DVO Photcodes tables and gets the 'CODE' for each the filters above that are listed
+        filters = []
+        for filter in allFilters:
+            code = self.scratchDb.getCodeForThisFilter(filter)
+            if code < 0: continue
+            filters.append([code, filter])
+        
+        # the 'code' now defines the order in the cps file that the mags are listed for a given filter
         for filter in filters:
 
-            if filter == "g": index = 4
-            elif filter == "r": index = 3
-            elif filter == "i": index = 2
-            elif filter == "z": index = 1
-            elif filter == "y": index = 0
-
             sql = "UPDATE Object \
-                   JOIN " + cpsTable + " AS cps ON (cps.row = (Object.row*5)-" + str(index) + ") \
+                   JOIN " + cpsTable + " AS cps ON (cps.row = (Object.row*5)-" + str(filter[0]) + ") \
                    SET \
-                   " + filter + "MeanMag = MAG, \
-                   " + filter + "MeanMagErr = MAG_ERR"
+                   " + filter[1] + "MeanMag = MAG, \
+                   " + filter[1] + "MeanMagErr = MAG_ERR"
 
             self.scratchDb.execute(sql)
