Ticket #8013 (closed enhancement: fixed)

Opened 3 years ago

Last modified 2 years ago

Specify default values for parameters

Reported by: tudor@stuffo.info Assigned to: airadier
Priority: normal Component: ParametrizedTemplatesPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

Is there possible to specify some default values for a field?

Attachments

Change History

11/10/10 17:54:29 changed by airadier

  • status changed from new to assigned.

Not now, but sounds like an interesting feature. Patches are accepted, or I'll take a look when I get some free time.

11/11/10 14:17:48 changed by tudor@stuffo.info

I've made the changes this morning. This is for 0.11

Index: parametrizedtemplates/parametrizedtemplates.py
===================================================================
--- parametrizedtemplates/parametrizedtemplates.py      (revision 9404)
+++ parametrizedtemplates/parametrizedtemplates.py      (working copy)
@@ -121,10 +121,10 @@
     def _find_fields(self, text):
         fields = []
         existing_fields = []
-        for match in re.finditer(r'{{\s*(.*?)\s*,\s*(.*?)\s*(?:,\s*(.*?)\s*)?}}', text):
+        for match in re.finditer(r'{{\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*(?:,\s*(.*?)\s*)?}}', text):
             if match.group(1) not in existing_fields:
                 existing_fields.append(match.group(1))
-                fields.append((match.group(1), match.group(2), match.group(3)))
+                fields.append((match.group(1), match.group(2), match.group(3), match.group(4)))
         
         return fields
         
Index: parametrizedtemplates/templates/newpage.html
===================================================================
--- parametrizedtemplates/templates/newpage.html        (revision 9404)
+++ parametrizedtemplates/templates/newpage.html        (working copy)
@@ -50,8 +50,8 @@
         <div class="field">
             <label for="field_${field[0]}">${field[1]}:</label><br/>
             <py:choose test="">
-                <textarea py:when="field[2] == 'textarea'" name="field_${field[0]}" id="field_${field[0]}" class="template_textarea" value=""/>
-                <input py:otherwise="" type="text" name="field_${field[0]}" id="field_${field[0]}" class="template_text" value=""/>
+                <textarea py:when="field[2] == 'textarea'" name="field_${field[0]}" id="field_${field[0]}" class="template_textarea">${field[3]}</textarea>
+                <input py:otherwise="" type="text" name="field_${field[0]}" id="field_${field[0]}" class="template_text" value="${field[3]}"/>
             </py:choose>
             <em>${field[0]}</em>
         </div>

Maybe you could include the change in your next release. Cheers

11/11/10 14:27:37 changed by airadier

Thanks very much! I would only change the regular expression to use named groups, it's quite complicated. I'm taking it for next release.

Greets.

11/18/10 11:14:30 changed by airadier

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [9437]) Added support for default value in the parameters. Closes #8013

11/18/10 11:14:57 changed by airadier

Feature included in version 0.3. Changes from your patch are:

  • Using named groups, the regular expression was getting quite complicated.
  • Keep the "field_type" parameter optional. If you specify a default value, field_type must be specified too. If not, both can be omitted.

Add/Change #8013 (Specify default values for parameters)




Change Properties
Action