Esempio n. 1
0
class BillForm(FlaskForm):
    date = DateField(_("Date"), validators=[Required()], default=datetime.now)
    what = StringField(_("What?"), validators=[Required()])
    payer = SelectField(_("Payer"), validators=[Required()], coerce=int)
    amount = CommaDecimalField(_("Amount paid"), validators=[Required()])
    payed_for = SelectMultipleField(_("For whom?"),
                                    validators=[Required()],
                                    coerce=int)
    submit = SubmitField(_("Submit"))
    submit2 = SubmitField(_("Submit and add a new one"))

    def save(self, bill, project):
        bill.payer_id = self.payer.data
        bill.amount = self.amount.data
        bill.what = self.what.data
        bill.date = self.date.data
        bill.owers = [
            Person.query.get(ower, project) for ower in self.payed_for.data
        ]

        return bill

    def fill(self, bill):
        self.payer.data = bill.payer_id
        self.amount.data = bill.amount
        self.what.data = bill.what
        self.date.data = bill.date
        self.payed_for.data = [int(ower.id) for ower in bill.owers]

    def set_default(self):
        self.payed_for.data = self.payed_for.default

    def validate_amount(self, field):
        if field.data == 0:
            raise ValidationError(_("Bills can't be null"))
Esempio n. 2
0
class BookingSearchForm(IndicoForm):
    room_ids = SelectMultipleField('Rooms', [DataRequired()], coerce=int)

    start_date = DateField('Start Date', [InputRequired()],
                           parse_kwargs={'dayfirst': True})
    start_time = TimeField('Start Time', [InputRequired()])
    end_date = DateField('End Date', [InputRequired()],
                         parse_kwargs={'dayfirst': True})
    end_time = TimeField('End Time', [InputRequired()])

    booked_for_name = StringField('Booked For Name')
    reason = StringField('Reason')

    is_only_mine = BooleanField('Only Mine')
    is_only_my_rooms = BooleanField('Only My Rooms')
    is_only_confirmed_bookings = BooleanField('Only Confirmed Bookings')
    is_only_pending_bookings = BooleanField('Only Prebookings')

    is_rejected = BooleanField('Is Rejected')
    is_cancelled = BooleanField('Is Cancelled')
    is_archived = BooleanField('Is Archived')

    uses_vc = BooleanField(_('Uses Videoconference'))
    needs_vc_assistance = BooleanField(_('Videoconference Setup Assistance'))
    needs_assistance = BooleanField('General Assistance')

    @generated_data
    def start_dt(self):
        return datetime.combine(self.start_date.data, self.start_time.data)

    @generated_data
    def end_dt(self):
        return datetime.combine(self.end_date.data, self.end_time.data)
class AddPlantForm(Form):
    pname = StringField(' Plant Name', [
        validators.Length(min=4, max=25),
        validators.DataRequired(),
    ])
    fertilizer = StringField('Fertilizer', [
        validators.Length(min=4, max=25),
        validators.DataRequired(),
    ])
    weather = SelectField('Weather',
                          choices=[('summer', 'Summer'), ('winter', 'Winter'),
                                   ('all_season', 'All Season')])
    sunlight = SelectField('Sunlight',
                           choices=[('mild', 'Mild'), ('moderate', 'Moderate'),
                                    ('extreme', 'Extreme')])
    potsize = SelectField('Pot Size',
                          choices=[('small', 'Small'), ('medium', 'Medium'),
                                   ('large', 'Large')])
    water = IntegerField("Water Requirement (in ml)")
    special = TextField('Special Requirements', [
        validators.Length(min=4, max=100),
    ])
    uses = SelectMultipleField("Uses",
                               choices=[("cosmetic", "Cosmetic"),
                                        ("medicinal", "Medicinal"),
                                        ("decorative", "Decorative"),
                                        ("edible", "Edible")])
Esempio n. 4
0
class BillForm(FlaskForm):
    date = DateField(_("Date"),
                     validators=[DataRequired()],
                     default=datetime.now)
    what = StringField(_("What?"), validators=[DataRequired()])
    payer = SelectField(_("Payer"), validators=[DataRequired()], coerce=int)
    amount = CalculatorStringField(_("Amount paid"),
                                   validators=[DataRequired()])
    external_link = URLField(
        _("External link"),
        validators=[Optional()],
        description=_("A link to an external document, related to this bill"),
    )
    payed_for = SelectMultipleField(_("For whom?"),
                                    validators=[DataRequired()],
                                    coerce=int)
    submit = SubmitField(_("Submit"))
    submit2 = SubmitField(_("Submit and add a new one"))

    def save(self, bill, project):
        bill.payer_id = self.payer.data
        bill.amount = self.amount.data
        bill.what = self.what.data
        bill.external_link = self.external_link.data
        bill.date = self.date.data
        bill.owers = [
            Person.query.get(ower, project) for ower in self.payed_for.data
        ]
        return bill

    def fake_form(self, bill, project):
        bill.payer_id = self.payer
        bill.amount = self.amount
        bill.what = self.what
        bill.external_link = ""
        bill.date = self.date
        bill.owers = [
            Person.query.get(ower, project) for ower in self.payed_for
        ]

        return bill

    def fill(self, bill):
        self.payer.data = bill.payer_id
        self.amount.data = bill.amount
        self.what.data = bill.what
        self.external_link.data = bill.external_link
        self.date.data = bill.date
        self.payed_for.data = [int(ower.id) for ower in bill.owers]

    def set_default(self):
        self.payed_for.data = self.payed_for.default

    def validate_amount(self, field):
        if field.data == 0:
            raise ValidationError(_("Bills can't be null"))
Esempio n. 5
0
class NewBookingCriteriaForm(NewBookingFormBase):
    room_ids = SelectMultipleField('Rooms', [DataRequired()], coerce=int)
    flexible_dates_range = RadioField('Flexible days', coerce=int, default=0,
                                      choices=[(0, _('Exact')),
                                               (1, '±{}'.format(_('1 day'))),
                                               (2, '±{}'.format(_('2 days'))),
                                               (3, '±{}'.format(_('3 days')))])

    def validate_flexible_dates_range(self, field):
        if self.repeat_frequency.data == RepeatFrequency.DAY:
            field.data = 0
Esempio n. 6
0
class CreateScadSemReForm(Form):
    # my_choices = [('1', _('VEHICLES')), ('2', _('Cars')), ('3', _('Motorcycles'))]
    my_choices = [('Vh', 'Vehicles'), ('Cr', 'Cars'), ('Mr', 'Motorcycles')]
    startDate = DateField(
        "Start Date",
        default=date.today(),
        format='%Y-%m-%d',
        validators=[DataRequired(message="You need to enter the start date")],
    )
    endDate = DateField(
        "End Date",
        validators=[DataRequired(message="You need to enter the end date.")],
        format='%Y-%m-%d')
    reList = SelectMultipleField("Select RE(s)",
                                 choices=my_choices,
                                 id="reList")
Esempio n. 7
0
class BillForm(FlaskForm):
    date = DateField(_("Date"),
                     validators=[DataRequired()],
                     default=datetime.now)
    what = StringField(_("What?"), validators=[DataRequired()])
    payer = SelectField(_("Payer"), validators=[DataRequired()], coerce=int)
    amount = CalculatorStringField(_("Amount paid"),
                                   validators=[DataRequired()])
    currency_helper = CurrencyConverter()
    original_currency = SelectField(_("Currency"), validators=[DataRequired()])
    external_link = URLField(
        _("External link"),
        validators=[Optional()],
        description=_("A link to an external document, related to this bill"),
    )
    payed_for = SelectMultipleField(_("For whom?"),
                                    validators=[DataRequired()],
                                    coerce=int)
    submit = SubmitField(_("Submit"))
    submit2 = SubmitField(_("Submit and add a new one"))

    def save(self, bill, project):
        bill.payer_id = self.payer.data
        bill.amount = self.amount.data
        bill.what = self.what.data
        bill.external_link = self.external_link.data
        bill.date = self.date.data
        bill.owers = [
            Person.query.get(ower, project) for ower in self.payed_for.data
        ]
        bill.original_currency = self.original_currency.data
        bill.converted_amount = self.currency_helper.exchange_currency(
            bill.amount, bill.original_currency, project.default_currency)
        return bill

    def fake_form(self, bill, project):
        bill.payer_id = self.payer
        bill.amount = self.amount
        bill.what = self.what
        bill.external_link = ""
        bill.date = self.date
        bill.owers = [
            Person.query.get(ower, project) for ower in self.payed_for
        ]
        bill.original_currency = CurrencyConverter.no_currency
        bill.converted_amount = self.currency_helper.exchange_currency(
            bill.amount, bill.original_currency, project.default_currency)

        return bill

    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),
        )

    def set_default(self):
        self.payed_for.data = self.payed_for.default

    def validate_amount(self, field):
        if field.data == 0:
            raise ValidationError(_("Bills can't be null"))