Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#8013 closed enhancement (fixed)

Specify default values for parameters

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

Change History (5)

comment:1 Changed 4 years ago 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.

comment:2 Changed 4 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 4 years ago 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.

comment:4 Changed 4 years ago by airadier

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:5 Changed 4 years ago 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 Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from airadier. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.