Index: src/sas/sasgui/perspectives/calculator/model_editor.py
===================================================================
--- src/sas/sasgui/perspectives/calculator/model_editor.py	(revision 07ec7146964cd515d342af9cf28572e1930bfe86)
+++ src/sas/sasgui/perspectives/calculator/model_editor.py	(revision 9f703d077a30b715703519ef5298cdd09bf36b39)
@@ -496,5 +496,5 @@
         if operator == '*':
             name = 'Multi'
-            factor = 'BackGround'
+            factor = 'background'
             f_oper = '+'
         else:
@@ -535,11 +535,11 @@
         if description == '':
             description = name1 + self._operator + name2
-        text = self._operator_choice.GetValue()
-        if text.count('+') > 0:
+        operator_text = self._operator_choice.GetValue()
+        if '+' in operator_text:
             factor = 'scale_factor'
             f_oper = '*'
             default_val = '1.0'
         else:
-            factor = 'BackGround'
+            factor = 'background'
             f_oper = '+'
             default_val = '0.0'
@@ -549,59 +549,10 @@
         except:
             raise
-        lines = SUM_TEMPLATE.split('\n')
-        for line in lines:
-            try:
-                if line.count("scale_factor"):
-                    line = line.replace('scale_factor', factor)
-                    #print "scale_factor", line
-                if line.count("= %s"):
-                    out_f.write(line % (default_val) + "\n")
-                elif line.count("import Model as P1"):
-                    if self.is_p1_custom:
-                        line = line.replace('#', '')
-                        out_f.write(line % name1 + "\n")
-                    else:
-                        out_f.write(line + "\n")
-                elif line.count("import %s as P1"):
-                    if not self.is_p1_custom:
-                        line = line.replace('#', '')
-                        out_f.write(line % (name1) + "\n")
-                    else:
-                        out_f.write(line + "\n")
-                elif line.count("import Model as P2"):
-                    if self.is_p2_custom:
-                        line = line.replace('#', '')
-                        out_f.write(line % name2 + "\n")
-                    else:
-                        out_f.write(line + "\n")
-                elif line.count("import %s as P2"):
-                    if not self.is_p2_custom:
-                        line = line.replace('#', '')
-                        out_f.write(line % (name2) + "\n")
-                    else:
-                        out_f.write(line + "\n")
-                elif line.count("P1 = find_model"):
-                    out_f.write(line % (name1) + "\n")
-                elif line.count("P2 = find_model"):
-                    out_f.write(line % (name2) + "\n")
-
-                elif line.count("self.description = '%s'"):
-                    out_f.write(line % description + "\n")
-                #elif line.count("run") and line.count("%s"):
-                #    out_f.write(line % self._operator + "\n")
-                #elif line.count("evalDistribution") and line.count("%s"):
-                #    out_f.write(line % self._operator + "\n")
-                elif line.count("return") and line.count("%s") == 2:
-                    #print "line return", line
-                    out_f.write(line % (f_oper, self._operator) + "\n")
-                elif line.count("out2")and line.count("%s"):
-                    out_f.write(line % self._operator + "\n")
-                else:
-                    out_f.write(line + "\n")
-            except:
-                raise
+        output = SUM_TEMPLATE.format(model1=name1, model2=name2, 
+            scale_factor_default=default_val, factor_operator=f_oper,
+            operator=self._operator, description=description)
+        output = output.replace("scale_factor", factor)
+        out_f.write(output + "\n")
         out_f.close()
-        #else:
-        #    msg = "Name exists already."
 
     def compile_file(self, path):
@@ -1294,10 +1245,10 @@
     def __init__(self, multiplicity=1):
         Model1DPlugin.__init__(self, name='')
-        P1 = find_model('%s')
-        P2 = find_model('%s')
+        P1 = find_model('{model1}')
+        P2 = find_model('{model2}')
         p_model1 = P1()
         p_model2 = P2()
         ## Setting  model name model description
-        self.description = '%s'
+        self.description = '{description}'
         if self.name.rstrip().lstrip() == '':
             self.name = self._get_name(p_model1.name, p_model2.name)
@@ -1311,5 +1262,5 @@
 
         ## Parameter details [units, min, max]
-        self.details = {}
+        self.details = {{}}
         ## Magnetic Panrameters
         self.magnetic_params = []
@@ -1328,5 +1279,5 @@
         self._set_params()
         ## New parameter:scaling_factor
-        self.params['scale_factor'] = %s
+        self.params['scale_factor'] = {scale_factor_default}
 
         ## Parameter details [units, min, max]
@@ -1538,11 +1489,11 @@
     def run(self, x = 0.0):
         self._set_scale_factor()
-        return self.params['scale_factor'] %s \
-(self.p_model1.run(x) %s self.p_model2.run(x))
+        return self.params['scale_factor'] {factor_operator} \
+(self.p_model1.run(x) {operator} self.p_model2.run(x))
 
     def runXY(self, x = 0.0):
         self._set_scale_factor()
-        return self.params['scale_factor'] %s \
-(self.p_model1.runXY(x) %s self.p_model2.runXY(x))
+        return self.params['scale_factor'] {factor_operator} \
+(self.p_model1.runXY(x) {operator} self.p_model2.runXY(x))
 
     ## Now (May27,10) directly uses the model eval function
@@ -1550,6 +1501,6 @@
     def evalDistribution(self, x = []):
         self._set_scale_factor()
-        return self.params['scale_factor'] %s \
-(self.p_model1.evalDistribution(x) %s \
+        return self.params['scale_factor'] {factor_operator} \
+(self.p_model1.evalDistribution(x) {operator} \
 self.p_model2.evalDistribution(x))
 
@@ -1589,5 +1540,5 @@
     #m2.p_model2.setParam("scale", 100)
     #m2.p_model2.setParam("rg", 100)
-    out2 = m2.p_model1.runXY(0.01) %s m2.p_model2.runXY(0.01)\n
+    out2 = m2.p_model1.runXY(0.01) {operator} m2.p_model2.runXY(0.01)\n
     print "My name is %s."% m1.name
     print out1, " = ", out2
