def delete(self, *args, **kwargs):
     """
     Remove KML cache before removing scenario 
     """
     from kml_caching import remove_kml_cache
     remove_kml_cache(self)
     super(Scenario, self).delete(*args, **kwargs)    
Exemple #2
0
 def delete(self, *args, **kwargs):
     """
     Remove KML cache before removing scenario 
     """
     from kml_caching import remove_kml_cache
     remove_kml_cache(self)
     super(Scenario, self).delete(*args, **kwargs)    
 def save(self, rerun=None, *args, **kwargs):
     if rerun is None and self.pk is None:
         rerun = True
     if rerun is None and self.pk is not None: #if editing a scenario and no value for rerun is given
         rerun = False
         if not rerun:
             orig = Scenario.objects.get(pk=self.pk)
             #TODO: keeping this in here til I figure out why self.lease_blocks and self.geometry_final_area are emptied when run() is not called
             remove_kml_cache(self)
             rerun = True
             #if getattr(orig, 'name') != getattr(self, 'name'):
             #    #print 'name has changed'
             #    remove_kml_cache(self) 
             #    rerun = True
             if not rerun:
                 for f in Scenario.input_fields():
                     # Is original value different from form value?
                     if getattr(orig, f.name) != getattr(self, f.name):
                         #print 'input_field, %s, has changed' %f.name
                         remove_kml_cache(self)
                         rerun = True
                         break                                                                                                                   
             if not rerun:
                 '''
                     the substrates need to be grabbed, then saved, then grabbed again because 
                     both getattr calls (orig and self) return the same original list until the model has been saved 
                     (perhaps because form.save_m2m has to be called), after which calls to getattr will 
                     return the same list (regardless of whether we use orig or self)
                 ''' 
                 orig_weas = set(getattr(self, 'input_wea').all())   
                 orig_substrates = set(getattr(self, 'input_substrate').all())  
                 orig_sediments = set(getattr(self, 'input_sediment').all())                    
                 super(Scenario, self).save(rerun=False, *args, **kwargs)  
                 new_weas = set(getattr(self, 'input_wea').all())                   
                 new_substrates = set(getattr(self, 'input_substrate').all()) 
                 new_sediments = set(getattr(self, 'input_sediment').all())   
                 if orig_substrates != new_substrates or orig_sediments != new_sediments or orig_weas != new_weas:
                     remove_kml_cache(self) 
                     rerun = True    
         super(Scenario, self).save(rerun=rerun, *args, **kwargs)
     else: #editing a scenario and rerun is provided 
         super(Scenario, self).save(rerun=rerun, *args, **kwargs)
Exemple #4
0
 def save(self, rerun=None, *args, **kwargs):
     if rerun is None and self.pk is None:
         rerun = True
     if rerun is None and self.pk is not None: #if editing a scenario and no value for rerun is given
         rerun = False
         if not rerun:
             orig = Scenario.objects.get(pk=self.pk)
             #TODO: keeping this in here til I figure out why self.lease_blocks and self.geometry_final_area are emptied when run() is not called
             remove_kml_cache(self)
             rerun = True
             #if getattr(orig, 'name') != getattr(self, 'name'):
             #    #print 'name has changed'
             #    remove_kml_cache(self) 
             #    rerun = True
             if not rerun:
                 for f in Scenario.input_fields():
                     # Is original value different from form value?
                     if getattr(orig, f.name) != getattr(self, f.name):
                         #print 'input_field, %s, has changed' %f.name
                         remove_kml_cache(self)
                         rerun = True
                         break                                                                                                                   
             if not rerun:
                 '''
                     the substrates need to be grabbed, then saved, then grabbed again because 
                     both getattr calls (orig and self) return the same original list until the model has been saved 
                     (perhaps because form.save_m2m has to be called), after which calls to getattr will 
                     return the same list (regardless of whether we use orig or self)
                 ''' 
                 orig_weas = set(getattr(self, 'input_wea').all())   
                 orig_substrates = set(getattr(self, 'input_substrate').all())  
                 orig_sediments = set(getattr(self, 'input_sediment').all())                    
                 super(Scenario, self).save(rerun=False, *args, **kwargs)  
                 new_weas = set(getattr(self, 'input_wea').all())                   
                 new_substrates = set(getattr(self, 'input_substrate').all()) 
                 new_sediments = set(getattr(self, 'input_sediment').all())   
                 if orig_substrates != new_substrates or orig_sediments != new_sediments or orig_weas != new_weas:
                     remove_kml_cache(self) 
                     rerun = True    
         super(Scenario, self).save(rerun=rerun, *args, **kwargs)
     else: #editing a scenario and rerun is provided 
         super(Scenario, self).save(rerun=rerun, *args, **kwargs)