Modify

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#8013 closed enhancement (fixed)

Specify default values for parameters

Reported by: tudor@… Owned by: Álvaro Iradier
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 (0)

Change History (5)

comment:1 Changed 14 years ago by Álvaro Iradier

Status: newassigned

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

comment:2 Changed 14 years ago by tudor@…

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

comment:3 Changed 14 years ago by Álvaro Iradier

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.

comment:4 Changed 14 years ago by Álvaro Iradier

Resolution: fixed
Status: assignedclosed

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

comment:5 Changed 14 years ago by Álvaro Iradier

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Álvaro Iradier.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.