Skip to content

Commit

Permalink
Fix up how default_props works with ForceScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Grubb committed Sep 1, 2012
1 parent 069eaac commit a751a67
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
45 changes: 27 additions & 18 deletions master/buildbot/status/web/builder.py
Expand Up @@ -25,7 +25,7 @@
map_branches, path_to_authzfail, ActionResource, \
getRequestCharset
from buildbot.schedulers.forcesched import ForceScheduler
from buildbot.schedulers.forcesched import InheritBuildParameter
from buildbot.schedulers.forcesched import InheritBuildParameter, NestedParameter
from buildbot.schedulers.forcesched import ValidationError
from buildbot.status.web.build import BuildsResource, StatusResourceBuild
from buildbot import util
Expand Down Expand Up @@ -168,30 +168,39 @@ def performAction(self, req):
# send the user back to the builder page
defer.returnValue((path_to_builder(req, self.builder_status), msg))

def buildForceContextForField(req, default_props, sch, field):
pname = "%s.%s"%(sch.name, field.fullName)

default = field.default
if isinstance(field, InheritBuildParameter):
# yes, I know, its bad to overwrite the parameter attribute,
# but I dont have any other simple way of doing this atm.
field.choices = field.compatible_builds(master.status, buildername)
if field.choices:
default = field.choices[0]

default = req.args.get(pname, [default])[0]
if field.type=="bool":
default_props[pname] = "checked" if default else ""
else:
# filter out unicode chars, and html stuff
if isinstance(default, unicode):
default = html.escape(default.encode('utf-8','ignore'))
default_props[pname] = default

if isinstance(field, NestedParameter):
for subfield in field.fields:
buildForceContextForField(req, default_props, sch, subfield)

def buildForceContext(cxt, req, master, buildername=None):
force_schedulers = {}
default_props = collections.defaultdict(str)
for sch in master.allSchedulers():
if isinstance(sch, ForceScheduler) and (buildername is None or(buildername in sch.builderNames)):
force_schedulers[sch.name] = sch
for p in sch.all_fields:
pname = "%s.%s"%(sch.name, p.name)
default = p.default
if isinstance(p, InheritBuildParameter):
# yes, I know, its bad to overwrite the parameter attribute,
# but I dont have any other simple way of doing this atm.
p.choices = p.compatible_builds(master.status, buildername)
if p.choices:
default = p.choices[0]
default = req.args.get(pname, [default])[0]
if p.type=="bool":
default_props[pname] = "checked" if default else ""
else:
# filter out unicode chars, and html stuff
if isinstance(default, unicode):
default = html.escape(default.encode('utf-8','ignore'))
default_props[pname] = default
for field in sch.all_fields:
buildForceContextForField(req, default_props, sch, field)

cxt['force_schedulers'] = force_schedulers
cxt['default_props'] = default_props

Expand Down
8 changes: 4 additions & 4 deletions master/buildbot/status/web/templates/forms.html
Expand Up @@ -83,19 +83,19 @@
<div class="row{% for subtype in f.type %} force-{{subtype}}{%endfor%}"{% if f.name %} id="force-{{sch.name}}-{{f.fullName}}"{% endif %}>
{% if 'text' in f.type or 'int' in f.type %}
<span class="label">{{f.label}}</span>
<input type='text' size='{{f.size}}' name='{{f.fullName}}' value='{{default_props[sch.name+"."+f.name]}}' />
<input type='text' size='{{f.size}}' name='{{f.fullName}}' value='{{default_props[sch.name+"."+f.fullName]}}' />
{% elif 'bool' in f.type%}
<input type='checkbox' name='checkbox' value='{{f.fullName}}' {{default_props[sch.name+"."+f.name]}} />
<input type='checkbox' name='checkbox' value='{{f.fullName}}' {{default_props[sch.name+"."+f.fullName]}} />
<span class="label">{{f.label}}</span>
{% elif 'textarea' in f.type %}
<span class="label">{{f.label}}</span>
<textarea name='{{f.fullName}}' rows={{f.rows}} cols={{f.cols}}>{{default_props[sch.name+"."+f.name]}}</textarea>
<textarea name='{{f.fullName}}' rows={{f.rows}} cols={{f.cols}}>{{default_props[sch.name+"."+f.fullName]}}</textarea>
{% elif 'list' in f.type %}
<span class="label">{{f.label}}</span>
<span class="select">
<select name='{{f.fullName}}' {{ f.multiple and "multiple" or ""}}>
{% for c in f.choices %}
<option {{(c in default_props[sch.name+"."+f.name]) and "selected" or ""}}>{{c}}</option>
<option {{(c in default_props[sch.name+"."+f.fullName]) and "selected" or ""}}>{{c}}</option>
{% endfor %}
</select>
</span>
Expand Down

0 comments on commit a751a67

Please sign in to comment.