def company_node(**kw): """ Return a schema node for company selection """ widget_options = kw.pop('widget_options', {}) return colander.SchemaNode( colander.Integer(), widget=get_deferred_company_choices(widget_options), **kw) company_choice_node = forms.mk_choice_node_factory( company_node, resource_name=u'une entreprise') company_filter_node_factory = forms.mk_filter_node_factory( company_node, empty_filter_msg=u'Toutes les entreprises', ) # Customer node related tools @colander.deferred def deferred_company_customer_validator(node, kw): """ Ensure we don't query customers from other companies """ company = kw['request'].context values = [customer.id for customer in company.customers] return colander.OneOf(values) def customer_node(is_admin=False, widget_options=None, **kwargs):
widget_options = kw.pop('widget_options', {}) return colander.SchemaNode( colander.Set() if multiple else colander.Integer(), widget=get_deferred_company_choices(widget_options), **kw ) company_choice_node = forms.mk_choice_node_factory( company_node, resource_name=u'une entreprise', resource_name_plural=u'de zéro à plusieurs entreprises', ) company_filter_node_factory = forms.mk_filter_node_factory( company_node, empty_filter_msg=u'Toutes les entreprises', ) # Customer node related tools @colander.deferred def deferred_company_customer_validator(node, kw): """ Ensure we don't query customers from other companies """ company = kw['request'].context values = [ i[0] for i in DBSESSION().query( Customer.id ).filter(Customer.company_id == company.id)
""" Return a schema node for user selection roles: allow to restrict the selection to the given roles (to select between admin, contractor and manager) """ widget_options = kw.pop('widget_options', {}) return colander.SchemaNode( colander.Set() if multiple else colander.Integer(), widget=get_deferred_user_choice(roles, widget_options), **kw ) contractor_filter_node_factory = forms.mk_filter_node_factory( user_node, empty_filter_msg=u'Tous les travailleurs', title=u'Travailleur', ) conseiller_choice_node = forms.mk_choice_node_factory( user_node, resource_name=u"un conseiller", roles=['manager', 'admin'], ) conseiller_filter_node_factory = forms.mk_filter_node_factory( user_node, empty_filter_msg='Tous les conseillers', roles=['manager', 'admin'], )
def user_node(roles=None, multiple=False, **kw): """ Return a schema node for user selection roles: allow to restrict the selection to the given roles (to select between admin, contractor and manager) """ widget_options = kw.pop('widget_options', {}) return colander.SchemaNode( colander.Set() if multiple else colander.Integer(), widget=get_deferred_user_choice(roles, widget_options), **kw) contractor_filter_node_factory = forms.mk_filter_node_factory( user_node, empty_filter_msg=u'Tous les travailleurs', title=u'Travailleur', ) conseiller_choice_node = forms.mk_choice_node_factory( user_node, resource_name=u"un conseiller", roles=['manager', 'admin'], ) conseiller_filter_node_factory = forms.mk_filter_node_factory( user_node, empty_filter_msg='Tous les conseillers', roles=['manager', 'admin'], )
def user_node(roles=None, **kw): """ Return a schema node for user selection roles: allow to restrict the selection to the given roles (to select between admin, contractor and manager) """ widget_options = kw.pop('widget_options', {}) return colander.SchemaNode(colander.Integer(), widget=get_deferred_user_choice( roles, widget_options), **kw) contractor_filter_node_factory = forms.mk_filter_node_factory( user_node, empty_filter_msg=u'Tous les travailleurs', title=u'Travailleur', ) conseiller_choice_node = forms.mk_choice_node_factory( user_node, resource_name=u"un conseiller", roles=['manager', 'admin'], ) conseiller_filter_node_factory = forms.mk_filter_node_factory( user_node, empty_filter_msg='Tous les conseillers', roles=['manager', 'admin'], )