Exemple #1
0
 def prepare_for_render(self, items_for_selects):
     self.set_widgets({
         'editing_remarks':
         TextAreaWidget(rows=4),
         'area_id':
         Select2Widget(values=items_for_selects['area']),
         'proposition_type_id':
         Select2Widget(values=items_for_selects['proposition_type']),
         **common_widgets(items_for_selects)
     })
 def prepare_for_render(self, items_for_selects):
     widgets = {
         'area_id':
         Select2Widget(values=items_for_selects['area']),
         'voting_id':
         Select2Widget(values=items_for_selects['voting']),
         'proposition_type_id':
         Select2Widget(values=items_for_selects['proposition_type'])
     }
     self.set_widgets(widgets)
Exemple #3
0
 def __init__(self,
              model,
              id_field='id',
              label_field='label',
              default_value=None,
              order_by=None,
              **kw):
     RelationMultiSelectMixin.__init__(self, model, id_field, label_field,
                                       default_value, order_by)
     Select2Widget.__init__(self, **kw)
Exemple #4
0
 def prepare_for_render(self, items_for_selects):
     widgets = {
         'result':
         TextAreaWidget(rows=4),
         'area_id':
         Select2Widget(values=items_for_selects['area']),
         'voting_id':
         Select2Widget(values=items_for_selects['voting']),
         'proposition_type_id':
         Select2Widget(values=items_for_selects['proposition_type']),
         'voting_type':
         Select2Widget(values=items_for_selects['voting_type']),
     }
     self.set_widgets(widgets)
 def prepare_for_render(self, items_for_selects):
     widgets = {
         'voting_type':
         Select2Widget(values=items_for_selects['voting_type']),
         'description': TextAreaWidget(rows=8),
     }
     self.set_widgets(widgets)
Exemple #6
0
class SocialMediaButtons(colander.SchemaNode):
    name = u'social_media_buttons'
    title = _(u'Social media buttons')
    description = _(u'Enable only specific social media buttons.')
    widget = Select2Widget(values=social_media_buttons, multiple=True)
    default = [u'facebook', u'twitter', u'google']
    missing = [u'facebook', u'twitter', u'google']
Exemple #7
0
    def __init__(self,
                 title,
                 name,
                 round=1,
                 missing=0.,
                 widget=None,
                 l_choices=None,
                 desc=None,
                 decimal=100,
                 table_reduce=False,
                 rank=0,
                 required=False,
                 missing_msg='champ requis',
                 primary_key=False):

        # Form display & param
        self.title = title
        self.round = round
        self.name = name
        self.type = float
        self.missing = missing
        self.required = required
        self.missing_msg = missing_msg
        self.desc = desc
        self.mapinit = None

        # Db column
        self.dbcol_ = (name, Colsql(Fltsql, primary_key=primary_key))

        # Table display & param
        self.table_reduce, self.rank, = table_reduce, rank

        if widget is not None:
            self.widget = widget
        else:
            if l_choices:
                self.widget = Select2Widget(values=l_choices)
            else:
                self.widget = MoneyInputWidget(options={'allowZero': True})

        self.processing_form = {
            'form': lambda x: float(x.replace(',', '')) if x else missing,
            'db': lambda x: float(x)
        }
        self.processing_db = {
            'upload': lambda x: float(int(x * decimal)) / decimal,
            'download': lambda x: float(x)
        }

        self.sn = sn(Money(),
                     title=self.title,
                     name=self.name,
                     widget=self.widget,
                     description=desc,
                     required=self.required,
                     missing_msg=self.missing_msg)

        if not required:
            self.sn.missing = missing
Exemple #8
0
def select2_widget_or_hidden(values):
    """ Render a select2 widget or a hidden field if no values were given.
    XXX: Is there a better way to hide unwanted fields?
    """
    if values is None:
        return HiddenWidget(hidden=True)
    else:
        return Select2Widget(values=values)
Exemple #9
0
    def __init__(self,
                 title,
                 name,
                 round=1,
                 missing=-1,
                 widget=None,
                 l_choices=None,
                 desc=None,
                 table_reduce=False,
                 rank=0,
                 required=False,
                 missing_msg='champ requis',
                 primary_key=False):

        # Form display & param
        self.title = title
        self.round = round
        self.name = name
        self.type = int
        self.desc = desc
        self.required = required
        self.missing_msg = missing_msg
        self.mapinit = None

        # Db column
        self.dbcol_ = (name, Colsql(Intsql, primary_key=primary_key))

        # Table display & param
        self.table_reduce, self.rank, = table_reduce, rank

        if widget is not None:
            self.widget = widget
        else:
            if l_choices:
                self.widget = Select2Widget(values=l_choices)
            else:
                self.widget = None

        self.processing_form = {
            'form': lambda x: int(x) if x else missing,
            'db': lambda x: int(x)
        }
        self.processing_db = {
            'upload': lambda x: int(x),
            'download': lambda x: int(x)
        }

        self.sn = sn(Integer(),
                     title=self.title,
                     name=name,
                     widget=self.widget,
                     description=desc,
                     required=self.required,
                     missing_msg=self.missing_msg)

        if not required:
            self.sn.missing = missing
 def prepare_for_render(self, items_for_selects):
     self.set_widgets({
         'proposition_id':
         HiddenWidget(),
         'user_id':
         HiddenWidget(),
         'notes':
         TextAreaWidget(rows=8, missing=None),
         'vote':
         Select2Widget(values=items_for_selects['vote'])
     })
 def prepare_for_render(self, items_for_selects):
     self.set_widgets({
         'title':
         TextAreaWidget(rows=2),
         'abstract':
         TextAreaWidget(rows=4),
         'content':
         TextAreaWidget(rows=8),
         'motivation':
         TextAreaWidget(rows=8),
         'tags':
         Select2Widget(multiple=True,
                       tags=True,
                       values=items_for_selects['tags']),
         'relation_type':
         HiddenWidget(),
         'related_proposition_id':
         HiddenWidget(),
         'area_id':
         Select2Widget(values=items_for_selects['area'])
     })
Exemple #12
0
def deferred_select_widget(node, kw) -> Select2Widget:
    """Return Select2Widget expects `node` to have `choices_getter` `multiple`.

    `choices_getter` is a function attribute accepting `node` and
    `request` and returning a list with selectable option tuples.

    `multiple` is a boolean attribute enabling multiselect.
    """
    choices = []
    if hasattr(node, 'choices_getter'):
        context = kw['context']
        request = kw['request']
        choices = node.choices_getter(context, request)
    multiple = getattr(node, 'multiple', False)
    return Select2Widget(values=choices,
                         multiple=multiple
                         )
def common_widgets(items_for_selects):
    return {
        'title':
        TextAreaWidget(rows=2),
        'abstract':
        TextAreaWidget(rows=4),
        'content':
        TextAreaWidget(rows=8),
        'motivation':
        TextAreaWidget(rows=8),
        'tags':
        Select2Widget(multiple=True,
                      tags=True,
                      values=items_for_selects['tags']),
        'relation_type':
        HiddenWidget(),
        'related_proposition_id':
        HiddenWidget()
    }
Exemple #14
0
 def deserialize(self, field, pstruct):
     if self.multiple:
         return RelationMultiSelectMixin.deserialize(self, field, pstruct)
     else:
         return Select2Widget.deserialize(self, field, pstruct)
Exemple #15
0
 def __init__(
         self, model, id_field='id', label_field='label',
         default_value=None, order_by=None, **kw):
     RelationMultiSelectMixin.__init__(
         self, model, id_field, label_field, default_value, order_by)
     Select2Widget.__init__(self, **kw)
 def prepare_for_render(self, items_for_selects):
     self.set_widgets({
         'area_id':
         Select2Widget(values=items_for_selects['area']),
         **common_widgets(items_for_selects)
     })
 def serialize(self, field, cstruct, **kw):
     if self.multiple:
         cstruct = RelationMultiSelectMixin.serialize(
             self, field, cstruct, **kw)
     return Select2Widget.serialize(self, field, cstruct, **kw)
Exemple #18
0
 def serialize(self, field, cstruct, **kw):
     if self.multiple:
         cstruct = RelationMultiSelectMixin.serialize(
             self, field, cstruct, **kw)
     return Select2Widget.serialize(self, field, cstruct, **kw)
Exemple #19
0
    def __init__(self,
                 title,
                 name,
                 round=1,
                 missing=u'',
                 widget=None,
                 l_choices=None,
                 multiple=False,
                 desc=None,
                 table_reduce=False,
                 rank=0,
                 required=False,
                 missing_msg='champ requis',
                 primary_key=False,
                 codec='utf-8'):

        # Form display
        self.title = title
        self.name = name
        self.round = round
        self.type = unicode
        self.desc = desc
        self.required = required
        self.missing_msg = missing_msg
        self.multiple = multiple
        self.mapinit = None if not self.multiple else []

        # Db column
        self.dbcol_ = (name, Colsql(Strsql(250), primary_key=primary_key))

        # Table display
        self.table_reduce, self.rank = table_reduce, rank

        if widget is not None:
            self.widget = widget
        else:
            if l_choices is not None:
                if len(l_choices) < 1:
                    l_choices = [('', '-')]
                self.widget = Select2Widget(values=l_choices,
                                            multiple=multiple)
            else:
                self.widget = TextInputWidget()

        self.processing_form = {
            'form': lambda x: x.decode(codec) if isinstance(x, str) else x,
            'db': lambda x: x.decode(codec) if isinstance(x, str) else x
        }
        self.processing_db = {
            'upload': lambda x: x.decode(codec) if isinstance(x, str) else x,
            'download': lambda x: x.decode(codec) if isinstance(x, str) else x
        }

        if not multiple:
            self.sn = sn(String(),
                         title=self.title,
                         name=name,
                         widget=self.widget,
                         missing=missing,
                         description=desc,
                         required=self.required,
                         missing_msg=self.missing_msg)
        else:
            self.processing_form.update({
                'form':
                lambda x: ';'.join(map(str, x)) if x else missing,
                'db':
                lambda x: x.split(';')
            })
            self.sn = sn(Set(),
                         title=self.title,
                         name=name,
                         widget=self.widget,
                         description=desc)

        if not required:
            self.sn.missing = missing
 def prepare_for_render(self, items_for_selects):
     widgets = {
         'description': TextAreaWidget(rows=8),
         'policy_id': Select2Widget(values=items_for_selects['policy'])
     }
     self.set_widgets(widgets)
 def prepare_for_render(self, items_for_selects):
     widgets = {
         'groups':
         Select2Widget(multiple=True, values=items_for_selects['groups']),
     }
     self.set_widgets(widgets)
Exemple #22
0
def deferred_etiquetas_widget(node, kw):
    lista_etiquetas = kw.get('lista_etiquetas', [])
    return Select2Widget(values=lista_etiquetas, multiple=True)
 def deserialize(self, field, pstruct):
     if self.multiple:
         return RelationMultiSelectMixin.deserialize(self, field, pstruct)
     else:
         return Select2Widget.deserialize(self, field, pstruct)