Modified:
/lingcod/analysistools/models.py
/lingcod/features/models.py
/lingcod/features/views.py
=======================================
--- /lingcod/analysistools/models.py Thu Jun 23 16:09:51 2011
+++ /lingcod/analysistools/models.py Wed Oct 5 08:50:01 2011
@@ -125,12 +125,26 @@
for f in self.output_fields():
self.__dict__[f.attname] = None
- def save(self, rerun=True, *args, **kwargs):
+ '''
+ Note on keyword args rerun and form: these are extracted from kwargs
so that they will not cause an unexpected
+ keyword argument error during call to super.save
+ Note on rerun: When set to false no output fields will be cleared and
the run method will not be called
+ Note on form: This is passed from feature.views update and create
methods. In the case of m2m fields this needs to
+ be called after super.save. Since it also needs to be called before
self.run, it needs to be called here in this
+ save method rather than its previous location in feature views update
and create (after save has completed)
+ '''
+ def save(self, rerun=True, form=None, *args, **kwargs):
if rerun:
self.clear_output_fields() # get rid of old outputs
super(Analysis, self).save(*args, **kwargs) # have to save
first so it has a pk
+ if form is not None:
+ form.save_m2m()
self.run()
- super(Analysis, self).save(*args, **kwargs)
+ super(Analysis, self).save(*args, **kwargs)
+ else:
+ super(Analysis, self).save(*args, **kwargs) # have to save
first so it has a pk
+ if form is not None:
+ form.save_m2m()
class Meta:
abstract = True
=======================================
--- /lingcod/features/models.py Wed Aug 24 10:23:05 2011
+++ /lingcod/features/models.py Wed Oct 5 08:50:01 2011
@@ -59,7 +59,12 @@
class Meta:
abstract=True
- def save(self, rerun=True, *args, **kwargs):
+ '''
+ Note on keyword args rerun and form: These are extracted from kwargs
so that they will not cause an unexpected
+ keyword argument error during call to super.save. (They are used in
the Analysis model save method, but become
+ superfluous here.)
+ '''
+ def save(self, rerun=True, form=None, *args, **kwargs):
super(Feature, self).save(*args, **kwargs) # Call the "real"
save() method
@models.permalink
=======================================
--- /lingcod/features/views.py Tue Oct 4 17:03:50 2011
+++ /lingcod/features/views.py Wed Oct 5 08:50:01 2011
@@ -224,18 +224,12 @@
if form.is_valid():
m = form.save(commit=False)
'''
- An explanation for the following save-related-code can be
found in the update method below (about 150 lines below)
- where the same code appears for feature edits
+ Note on the following 3 lines:
+ We need to call form.save_m2m after save but before run, this
is accomplished in the Analysis model save method
'''
- save_again = False
- try:
- m.save(rerun=False)
- save_again = True
- except TypeError:
- m.save()
- form.save_m2m()
- if save_again:
- m.save()
+ kwargs = {}
+ kwargs['form']=form
+ m.save(**kwargs)
return to_response(
status=201,
@@ -371,30 +365,9 @@
form = form_class(values, instance=instance, label_suffix='')
if form.is_valid():
m = form.save(commit=False)
- '''
- The following save-related-code fixes the problem that
occurred when save called run before the m2m fields were saved.
- In the case where there are many to many fields and analysis
to be run, we need to save an instance into the db,
- then save the m2m fields, and then run the analysis.
- In order to not break backward compatibility, the second save
(which is only called after save(rerun=False)) is called
- without rerun=True. (This also allows the project developer
to determine rerun on a case-by-case basis.)
-
- The resulting code will either perform the following (if
m.save allows a rerun keyword argument):
- m.save(rerun=False)
- form.save_m2m2()
- m.save()
- Or it will perform the following (if m.save does not allow a
rerun keyword argument):
- m.save()
- form.save_m2m()
- '''
- save_again = False
- try:
- m.save(rerun=False)
- save_again = True
- except TypeError:
- m.save()
- form.save_m2m()
- if save_again:
- m.save()
+ kwargs = {}
+ kwargs['form']=form
+ m.save(**kwargs)
return to_response(
status=200,