def deferred_bootstrap_widget(node, kw): parent = kw['request'].context.parent context = get_context_or_parent(parent, u'jobcontainer') bootstraps = get_all_data(Bootstrap, context) availables = [bootstrap.title.encode('utf-8') for bootstrap in bootstraps] widget = CommaSeparatedListWidget( template='kotti_mapreduce:templates/deform/bootstrap-list', available_bootstraps=availables, ) return widget
def deferred_resource_data(node, kw): values = None context = kw['request'].context resource = get_resource_model(context) if resource: order_by = methodcaller('order_by', asc(resource.title)) job_container = get_context_or_parent(context, u'jobcontainer') data = get_all_data(resource, job_container, order_by=order_by) values = map(attrgetter('id', 'title'), data) return SelectWidget(values=values)
def deferred_bootstrap_validator(node, kw): def raise_invalid_bootstrap(node, value): raise colander.Invalid( node, _(u"The Bootstrap is not found.")) request = kw['request'] if request.POST: parent = request.context.parent context = get_context_or_parent(parent, u'jobcontainer') bootstraps = get_all_data(Bootstrap, context) availables = [bootstrap.title for bootstrap in bootstraps] posted_bootstraps = request.params.get('bootstrap_titles') if posted_bootstraps: for posted_bootstrap in posted_bootstraps.split(','): if posted_bootstrap not in availables: return raise_invalid_bootstrap