예제 #1
0
def get_billform_for(project, set_default=True, **kwargs):
    """Return an instance of BillForm configured for a particular project.

    :set_default: if set to True, on GET methods (usually when we want to
                  display the default form, it will call set_default on it.

    """
    form = BillForm(**kwargs)
    if form.original_currency.data == "None":
        form.original_currency.data = project.default_currency

    if form.original_currency.data != CurrencyConverter.default:
        choices = copy.copy(form.original_currency.choices)
        choices.remove((CurrencyConverter.default, CurrencyConverter.default))
        choices.sort(key=lambda rates: ""
                     if rates[0] == project.default_currency else rates[0])
        form.original_currency.choices = choices
    else:
        form.original_currency.render_kw = {"default": True}
        form.original_currency.data = CurrencyConverter.default

    form.original_currency.label = Label(
        "original_currency",
        "Currency (Default: %s)" % (project.default_currency))
    active_members = [(m.id, m.name) for m in project.active_members]

    form.payed_for.choices = form.payer.choices = active_members
    form.payed_for.default = [m.id for m in project.active_members]

    if set_default and request.method == "GET":
        form.set_default()
    return form
예제 #2
0
파일: forms.py 프로젝트: imfht/flaskapps
    def fill(self, bill, project):
        self.payer.data = bill.payer_id
        self.amount.data = bill.amount
        self.what.data = bill.what
        self.external_link.data = bill.external_link
        self.original_currency.data = bill.original_currency
        self.date.data = bill.date
        self.payed_for.data = [int(ower.id) for ower in bill.owers]

        self.original_currency.label = Label("original_currency",
                                             _("Currency"))
        self.original_currency.description = _(
            "Project default: %(currency)s",
            currency=render_localized_currency(project.default_currency,
                                               detailed=False),
        )
예제 #3
0
 def __init__(self, label='', op=SubmitReview, model_name='', *args, **kwargs):
     super(UserSelectForm, self).__init__(*args, **kwargs)
     self.related_user.choices = get_related_user(model_name, op=op)
     if label:
         self.related_user.label = Label('related_user', label)
예제 #4
0
 def __init__(self, label='', *args, **kwargs):
     super(MeetingFileForm, self).__init__(*args, **kwargs)
     if label:
         self.meetingFile.label = Label('meetingFile', label)
예제 #5
0
 def __init__(self, label='', *args, **kwargs):
     super(ContractFileForm, self).__init__(*args, **kwargs)
     if label:
         self.contractFile.label = Label('contractFile', label)
예제 #6
0
 def set_name(self, new_name):
     self.submit.label = Label("", new_name)
예제 #7
0
    def __init__(self,
                 label=None,
                 validators=None,
                 filters=tuple(),
                 description='',
                 id=None,
                 default=None,
                 widget=None,
                 render_kw=None,
                 _form=None,
                 _name=None,
                 _prefix='',
                 _translations=None,
                 _meta=None,
                 new_row=None,
                 end_row=None,
                 form_group_class='',
                 table=None,
                 column=None,
                 is_position=None,
                 use_ratio=None,
                 is_date_type=None,
                 is_footer=None,
                 footer_class=None,
                 hidden=None,
                 add_calc=None,
                 form_row_class=None):  # NCH01 add args after _meta
        """
        Construct a new field.

        :param label:
            The label of the field.
        :param validators:
            A sequence of validators to call when `validate` is called.
        :param filters:
            A sequence of filters which are run on input data by `process`.
        :param description:
            A description for the field, typically used for help text.
        :param id:
            An id to use for the field. A reasonable default is set by the form,
            and you shouldn't need to set this manually.
        :param default:
            The default value to assign to the field, if no form or object
            input is provided. May be a callable.
        :param widget:
            If provided, overrides the widget used to render the field.
        :param dict render_kw:
            If provided, a dictionary which provides default keywords that
            will be given to the widget at render time.
        :param _form:
            The form holding this field. It is passed by the form itself during
            construction. You should never pass this value yourself.
        :param _name:
            The name of this field, passed by the enclosing form during its
            construction. You should never pass this value yourself.
        :param _prefix:
            The prefix to prepend to the form name of this field, passed by
            the enclosing form during construction.
        :param _translations:
            A translations object providing message translations. Usually
            passed by the enclosing form during construction. See
            :doc:`I18n docs <i18n>` for information on message translations.
        :param _meta:
            If provided, this is the 'meta' instance from the form. You usually
            don't pass this yourself.

        If `_form` and `_name` isn't provided, an :class:`UnboundField` will be
        returned instead. Call its :func:`bind` method with a form instance and
        a name to construct the field.
        """
        if _translations is not None:
            self._translations = _translations

        # NCH01 override class
        if new_row is not None:
            self.new_row = new_row

        if end_row is not None:
            self.end_row = end_row

        if table is not None:
            self.table = table

        if column is not None:
            self.column = column

        if is_position is not None:
            self.is_position = is_position

        if use_ratio is not None:
            self.use_ratio = use_ratio

        if is_date_type is not None:
            self.is_date_type = is_date_type

        if is_footer is not None:
            self.is_footer = is_footer

        if footer_class is not None:
            self.footer_class = footer_class

        if hidden is not None:
            self.hidden = hidden

        if add_calc is not None:
            self.add_calc = add_calc

        if form_row_class is not None:
            self.form_row_class = form_row_class

        self.form_group_class = form_group_class
        # END NCH01 override class
        if _meta is not None:
            self.meta = _meta
        elif _form is not None:
            self.meta = _form.meta
        else:
            raise TypeError("Must provide one of _form or _meta")

        self.default = default
        self.description = description
        self.render_kw = render_kw
        self.filters = filters
        self.flags = Flags()
        self.name = _prefix + _name
        self.short_name = _name
        self.type = type(self).__name__

        self.check_validators(validators)
        self.validators = validators or self.validators

        self.id = id or self.name
        self.label = Label(
            self.id, label if label is not None else self.gettext(
                _name.replace('_', ' ').title()))

        if widget is not None:
            self.widget = widget

        for v in itertools.chain(self.validators, [self.widget]):
            flags = getattr(v, 'field_flags', ())
            for f in flags:
                setattr(self.flags, f, True)
예제 #8
0
파일: approve.py 프로젝트: GSIL-Monitor/wxk
 def __init__(self, model_name='', label='', *args, **kwargs):
     super(FileForm, self).__init__(*args, **kwargs)
     if label:
         self.file.label = Label('file', label)