예제 #1
0
class CategoryForm(Form):
    id = TextField(validators=[required(message=u'必填')])
    obj = TextField(u'分组', [required(message=u'必填')])
    name = TextField(u'名称', [required(message=u'必填')])
    alias = TextField(u'显示名', [required(message=u'必填')])
    is_valid = SelectField(u'有效性', [required(message=u'必填')],
                           choices=[(u'0', u'无效'), (u'1', u'有效')])
예제 #2
0
파일: forms.py 프로젝트: yordanomp/xiaoli
class PerfFilterForm(Form):
    keyword = TextField()
    sampletime = SelectField(u'时间', choices=DATES, default='today')
    intervals = SelectMultipleField(u'时段',
                                    choices=pull_intervals('__None'),
                                    default=['__None'])
    vendors = QuerySelectMultipleFieldFix(u'厂商',
                                          query_factory=lambda: Vendor.query,
                                          get_label='alias',
                                          allow_blank=True,
                                          blank_text=u'全部厂商')
    models = QuerySelectMultipleFieldFix(u'型号',
                                         query_factory=lambda: Model.query,
                                         get_label='alias')

    def refresh_choices(self, args):
        self.intervals.choices = pull_intervals(args.get('sampletime'))
        self.models.query_factory = model_choices(args.get('vendors'))

    def filter(self, model):
        query = model.query
        # 'today' ...
        sampletime = self.sampletime.data
        # [] or ['__None'] or ['1', '2'] or ['__None', '1', '2'] ...
        intervals = self.intervals.data
        # the same as intervals
        vendor_ids = [v.id
                      for v in self.vendors.data] if self.vendors.data else []
        # the same as intervals
        model_ids = [m.id for m in self.models.data]
        category_ids = [c.id for c in self.categories.data] if \
                       hasattr(self, 'categories') and self.categories.data else []

        # print '========================================'
        # print 'self.sampletime.data::', sampletime
        # print 'self.intervals.data::', intervals
        # print 'self.vendors.data::', vendor_ids
        # print 'self.models.data::', model_ids
        # print 'self.categories.data::', category_ids
        # print '========================================'
        # Filter Datetime
        query = sampletime_filter(model, query, sampletime, intervals)

        # Filter Category
        if category_ids and '__None' not in category_ids:
            query = query.filter(
                model.node.has(Node.category_id.in_(category_ids)))

        # Filter Model
        # *Except*: (vendor_ids is empty has '__None') AND (model_ids is empty OR has '__None')
        if (vendor_ids and '__None' not in vendor_ids) or \
           (model_ids and '__None' not in model_ids):
            if not model_ids or '__None' in model_ids:
                query = query.filter(
                    model.node.has(Node.vendor_id.in_(vendor_ids)))
                # model_ids = [m.id for m in Model.query.filter(Model.vendor_id.in_(vendor_ids))]
            else:
                query = query.filter(
                    model.node.has(Node.model_id.in_(model_ids)))
        return query
예제 #3
0
class PermissionForm(Form):
    endpoint = TextField(u'Endpoint')
    module_text = TextField(u'模块显示名')
    name = TextField(u'子模块显示名')
    operation = TextField(u'操作名')
    default_permission = SelectField(u'有效性', [required(message=u'必填')],
                                     choices=[(u'0', u'无权限'), (u'1', u'有权限')])
    next = HiddenField()
예제 #4
0
class MiboidForm(Form):
    mib = TextField(u'mib', [required(message=u'必填')])
    grp = TextField(u'分组', [required(message=u'必填')])
    name = TextField(u'名称', [required(message=u'必填')])
    alias = TextField(u'显示名', [required(message=u'必填')])
    oid = TextField(u'oid')
    is_valid = SelectField(u'有效性', [required(message=u'必填')],
                           choices=[(u'0', u'无效'), (u'1', u'有效')])
    remark = TextAreaField(u'备注')
예제 #5
0
class NoteForm(Form):
    name = TextField('Name', validators=[Required()])
    text = TextAreaField('Note', validators=[Required()])
    pad = SelectField('Pad', choices=[], coerce=int)

    # @TODO use wtforms.ext.sqlalchemy.fields.QuerySelectField?
    def __init__(self, user=None, **kwargs):
        super(NoteForm, self).__init__(**kwargs)
        self.pad.choices = [(0, '---------')] + [
            (p.id, p.name) for p in Pad.query.filter_by(user=user)
        ]
예제 #6
0
파일: forms.py 프로젝트: yordanomp/xiaoli
class AlarmKnowledgeForm(Form):
    class_id = SelectFieldPro(
        u'告警类型',
        validators=[required(message=u'必填')],
        choices=lambda: [('', u'Choice')] + [(unicode(r.id), r.alias)
                                             for r in AlarmClass.query])
    probability = SelectField(u'发生几率',
                              validators=[required(message=u'必填')],
                              choices=[(unicode(1), u'极少发生'),
                                       (unicode(2), u'偶尔发生'),
                                       (unicode(3), u'频繁发生')])
    probable_cause = TextAreaField(u'可能原因')
    resolvent = TextAreaField(u'解决方案')
예제 #7
0
class ModelForm(Form):
    category = QuerySelectField(
        u'类别',
        get_label=u'alias',
        query_factory=lambda: Category.query.filter_by(obj='node'))
    name = TextField(u'名称', [required(message=u'必填')])
    alias = TextField(u'显示名', [required(message=u'必填')])
    sysoid = TextField(u'Sysoid')
    vendor = QuerySelectField(u'厂商',
                              get_label=u'alias',
                              query_factory=lambda: Vendor.query)
    is_valid = SelectField(u'有效性', [required(message=u'必填')],
                           choices=[(u'0', u'无效'), (u'1', u'有效')])
    remark = TextAreaField(u'备注')
예제 #8
0
파일: forms.py 프로젝트: mabhub/ihatemoney
class BillForm(Form):
    date = DateField(_("Date"), validators=[Required()], default=datetime.now)
    what = TextField(_("What?"), validators=[Required()])
    payer = SelectField(_("Payer"), validators=[Required()], coerce=int)
    amount = CommaDecimalField(_("Amount paid"), validators=[Required()])
    payed_for = SelectMultipleField(_("For whom?"),
                                    validators=[Required()],
                                    widget=select_multi_checkbox,
                                    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"))
예제 #9
0
class VendorForm(Form):
    name = TextField(u'名称', [required(message=u'必填')])
    alias = TextField(u'显示名', [required(message=u'必填')])
    url = TextField(u'厂商主页')
    is_valid = SelectField(u'有效性', [required(message=u'必填')],
                           choices=[(u'0', u'无效'), (u'1', u'有效')])