示例#1
0
class BaseEditForm(BaseForm):
    """Edit form with all missing fields except `content`"""

    # content_type = fields.PassiveStringField(
    #     'Type',
    #     render_kw=READ_ONLY
    # )
    # content_format = fields.PassiveStringField(
    #     'Format',
    #     render_kw=READ_ONLY
    # )

    tags = fields.Select2TagsField('Tags',
                                   save_as_list=True,
                                   render_kw=get_tags_kw)
    date = fields.DateTimeField('Date', [validators.required()],
                                default=dt.datetime.now)
    modified = fields.HiddenField('Modified')
    slug = fields.StringField('Slug')
    language = fields.SmartSelect2Field(
        'Language',
        choices=lambda: [(lng, lng)
                         for lng in app.config.get('BABEL_LANGUAGES', ['en'])],
        default=get_default_language)
    # translations = fields.HiddenField('Translations')
    # todo: ^ create action 'add translation'
    published = fields.BooleanField('Status',
                                    render_kw={
                                        'data-toggle': "toggle",
                                        'data-on': "Published",
                                        'data-off': "Draft",
                                        "data-onstyle": 'success'
                                    })
    comments = fields.BooleanField('Comments',
                                   default=True,
                                   render_kw={
                                       'data-toggle': "toggle",
                                       'data-on': "Enabled",
                                       'data-off': "Disabled",
                                       "data-onstyle": 'success'
                                   })

    # to be used only for Block type
    block_items = InlineFieldList(InlineFormField(BlockItemForm),
                                  label='Items')

    custom_vars = InlineFieldList(InlineFormField(CustomVariablesForm),
                                  label='Custom Variables')
示例#2
0
class BlockItemForm(Form):
    item = fields.Select2TagsField(
        'Item', [
            validators.required(),
            validators.CallableValidator(validate_block_item)
        ],
        save_as_list=False,
        render_kw=get_block_item_kw,
        description=('Enter absolute URL `http://..` or `/foo/bar.html` '
                     'or select existing content.'))
    name = fields.StringField('Name', description='optional')
    order = fields.IntegerField('Order', default=0)
    item_type = fields.SmartSelect2Field(
        'Type', [validators.required()],
        default='link',
        choices=lambda: [
            item
            for item in app.config.get('BLOCK_ITEM_TYPES', [('link', 'Link')])
        ])

    custom_vars = InlineFieldList(InlineFormField(CustomVariablesForm),
                                  label='Custom Variables')

    index_id = fields.HiddenField('index_id')
    category_id = fields.HiddenField('category_id')
    tag_id = fields.HiddenField('tag_id')
    author_id = fields.HiddenField('author_id')
    url_id = fields.HiddenField('url_id')
    content_type = fields.HiddenField('content_type', default='block_item')
示例#3
0
文件: form.py 项目: skshetry/app
    def conv_List(self, model, field, kwargs):
        if field.field is None:
            raise ValueError('ListField "%s" must have field specified for model %s' % (field.name, model))

        if isinstance(field.field, ReferenceField):
            loader = getattr(self.view, '_form_ajax_refs', {}).get(field.name)
            if loader:
                return AjaxSelectMultipleField(loader, **kwargs)

            kwargs['widget'] = form.Select2Widget(multiple=True)
            kwargs.setdefault('validators', []).append(validators.Optional())

            # TODO: Support AJAX multi-select
            doc_type = field.field.document_type
            return mongo_fields.ModelSelectMultipleField(model=doc_type, **kwargs)

        # Create converter
        view = self._get_subdocument_config(field.name)
        converter = self.clone_converter(view)

        if field.field.choices:
            kwargs['multiple'] = True
            return converter.convert(model, field.field, kwargs)

        unbound_field = converter.convert(model, field.field, {})
        return InlineFieldList(unbound_field, min_entries=0, **kwargs)
示例#4
0
class UserForm(form.Form):
    name = fields.StringField('Name')
    email = fields.StringField('Email')
    password = fields.StringField('Password')
    # Inner form
    inner = InlineFormField(InnerForm)
    # Form list
    form_list = InlineFieldList(InlineFormField(InnerForm))
示例#5
0
class SentMailForm(Form):
    
    ids = fields.HiddenField()
    
    is_origin = fields.BooleanField(label=u"Expéditeur et destinataires originaux")
    
    sender = fields.StringField(label=u"Expéditeur")
    
    rcpts = InlineFieldList(StringField(u"Destinaires"))
示例#6
0
class UserForm(form.Form):
    name = fields.StringField('Name')

    password = fields.StringField('Password')

    count = fields.StringField('Count')
    lasttime = fields.StringField('Lasttime')

    isadmin = fields.StringField('is admin ?')
    # Form list
    form_list = InlineFieldList(InlineFormField(InnerForm))
示例#7
0
class SPOForm(form.Form):
    obj = fields.StringField('obj')

    prop = fields.StringField('prop')

    sub = fields.StringField('sub')
    time = fields.StringField('updata_time')
    type = fields.StringField("type")

    # Form list
    form_list = InlineFieldList(InlineFormField(InnerForm))
示例#8
0
def get_form_field(schema):
    if isinstance(schema, S.Unicode):
        return f.TextField()
    elif isinstance(schema, S.DateTime):
        return DateTimeField()
    elif isinstance(schema, manager.ClassManager):
        frm = get_form(schema._cls)
        return InlineFormField(frm)
    elif isinstance(schema, S.Array):
        inner = get_form_field(schema.validator)
        return InlineFieldList(inner)
示例#9
0
class PersonForm(form.Form):
    do_what = fields.StringField('职务')

    managername = fields.StringField('姓名')

    birthday = fields.StringField('出生年月')
    sex = fields.StringField('性别')
    code = fields.StringField("代码")
    edu = fields.StringField("学历")

    # Form list
    form_list = InlineFieldList(InlineFormField(InnerForm))
class InnerFormDays(form.Form):
    """списки со временем напоминаний"""
    понедельник = InlineFieldList(fields.StringField(), 'понедельник')
    вторник = InlineFieldList(fields.StringField(), 'вторник')
    среда = InlineFieldList(fields.StringField(), 'среда')
    четверг = InlineFieldList(fields.StringField(), 'четверг')
    пятница = InlineFieldList(fields.StringField(), 'пятница')
    суббота = InlineFieldList(fields.StringField(), 'суббота')
示例#11
0
class CompanyForm(form.Form):
    adress = fields.StringField('公司注册地址')

    stockname = fields.StringField('证券简称')

    company_name = fields.StringField('公司名称')
    manager = fields.StringField('总经理')

    id = fields.StringField('注册号')
    place = fields.StringField('首次注册登记地点')
    faren = fields.StringField('法人代表')
    email = fields.StringField("公司注册地址邮箱")
    code = fields.StringField("代码")
    # Form list
    form_list = InlineFieldList(InlineFormField(InnerForm))
class InnerFormDays(form.Form):
    day = fields.StringField()
    lessons = InlineFieldList(
        InlineFormField(InnerFormLessons))  #InlineFormField(InnerFormLessons)
示例#13
0
class PlaceForm(form.Form):
    name = fields.TextField('Name')
    address = fields.TextField('Address')
    location = PointField('Coordinates')

    events = InlineFieldList(InlineFormField(EventsForm))
class ScheduleForm(form.Form):
    group = fields.SelectField('Группа', widget=Select2Widget())
    schedule = InlineFieldList(InlineFormField(InnerFormDays), 'Расписание')
示例#15
0
class IdentityView(ModelView):
    column_list = [
        'issuer',
        'name',
        'status',
    ]
    list_template = 'admin/identity_list.html'
    column_formatters = {
        'status': macro('render_status'),
    }

    form_excluded_columns = [
        'name',
        'issues',
        'pairs',
    ]

    form_extra_fields = {
        'subj_cn':
        fields.StringField('CN',
                           description='Common Name',
                           validators=required),
        'subj_c':
        fields.StringField('C', description='Country'),
        'subj_o':
        fields.StringField('O', description='Organization'),
        'subj_ou':
        fields.StringField('OU', description='Organizational Unit'),
        'subj_dnq':
        fields.StringField('', description='Distinguished name qualifier'),
        'subj_st':
        fields.StringField('ST', description='State or province name'),
        'subj_sn':
        fields.StringField('', description='Serial number'),
        'cert_validate_since':
        fields.DateTimeField('Valid since',
                             description='Not valid before',
                             validators=required,
                             default=default_since),
        'cert_validate_till':
        fields.DateTimeField('Valid till',
                             description='Not valid after',
                             validators=required,
                             default=default_till),
        'cert_ca_path_length':
        fields.IntegerField('CA path length', default=0),
        'san_ips':
        InlineFieldList(fields.StringField('IP', [validators.IPAddress()]),
                        'IP',
                        description='IP address'),
        'san_dns_names':
        InlineFieldList(fields.StringField('DNS'),
                        'DNS',
                        description='DNS names'),
        'ku_web_server_auth':
        fields.BooleanField('Web server auth',
                            description='TLS Web Server Authentication'),
        'ku_web_client_auth':
        fields.BooleanField('Web client auth',
                            description='TLS Web Client Authentication'),
        'key_size':
        fields.IntegerField('Size', default=2048),
        'key_public_exponent':
        fields.IntegerField('Public exponent', default=65537),
    }

    form_rules = [
        rules.Field('issuer'),
        rules.FieldSet([
            'cert_validate_since',
            'cert_validate_till',
            'cert_ca_path_length',
        ], 'Certificate settings'),
        rules.FieldSet([
            'subj_cn',
            'subj_c',
            'subj_o',
            'subj_ou',
            'subj_dnq',
            'subj_st',
            'subj_sn',
        ], 'Subject'),
        rules.FieldSet([
            'san_ips',
            'san_dns_names',
        ], 'Subject Alternative Names'),
        rules.FieldSet([
            'ku_web_server_auth',
            'ku_web_client_auth',
        ], 'Key Usage'),
        rules.FieldSet([
            'key_size',
            'key_public_exponent',
        ], 'Key Settings'),
    ]

    def create_model(self, *args, **kwargs):
        with self.session.no_autoflush:
            return super().create_model(*args, **kwargs)

    def on_model_change(self, form, model, is_created):
        data = x509.CertInfo(form.data)

        if data.issuer:
            pair = models.Pair(
                *x509.issue_certificate(data, data.issuer.pair.as_tuple))
        else:
            pair = models.Pair(*x509.issue_certificate(data))

        model.pair = pair
        model.name = data.subj_cn

    @expose('/reissue/', methods=['POST'])
    def reissue_view(self):
        model = self.get_one(request.values.get('id'))
        info = x509.load_certificate_info(model.pair.as_tuple, reissue=True)

        if model.issuer:
            pair = models.Pair(
                *x509.issue_certificate(info, model.issuer.pair.as_tuple))
        else:
            pair = models.Pair(*x509.issue_certificate(info))

        model.pair = pair

        self.session.commit()
        return_url = get_redirect_target() or self.get_url('.index_view')
        flash('The identity certificate was successfully reissued', 'success')
        return redirect(return_url)

    def edit_form(self, obj=None):
        if obj:
            info = x509.load_certificate_info(obj.pair.as_tuple, reissue=True)
            for k, v in info.as_dict().items():
                if not hasattr(obj, k):
                    setattr(obj, k, v)
        return super().edit_form(obj)

    @expose('/details/')
    def details_view(self):
        model = self.get_one(request.values.get('id'))
        return_url = get_redirect_target() or self.get_url('.index_view')
        return redirect(
            self.get_url('pair.details_view', id=model.pair.id,
                         url=return_url))

    @expose('/import/', methods=['GET', 'POST'])
    def import_view(self):
        return_url = get_redirect_target() or self.get_url('.index_view')
        form = ImportForm(get_form_data())

        if self.validate_form(form):
            pair_tuple = form.data['cert'].encode(
                'ascii'), form.data['key'].encode('ascii')
            info = x509.load_certificate_info(pair_tuple)

            if not x509.does_keys_match(pair_tuple):
                flash('Failed to import identity: keys does not match.',
                      'error')
                return redirect(return_url)

            identity = models.Identity()
            identity.name = info.subj_cn

            if not info.self_signed:

                def find_issuer():
                    for issuer in models.Identity.query.filter_by(
                            name=info.issuer_cn):
                        cert_chain = issuer.get_cert_chain()
                        try:
                            x509.verify_certificate_chain(
                                pair_tuple[0], cert_chain)
                        except x509.InvalidCertificate:
                            pass
                        else:
                            return issuer

                identity.issuer = find_issuer()
                if not identity.issuer:
                    flash(
                        'Failed to import identity: issuer identity not found.',
                        'error')
                    return redirect(return_url)

            self.session.add(identity)
            pair = models.Pair(*pair_tuple)
            pair.identity = identity
            self.session.add(pair)

            try:
                self.session.commit()
            except IntegrityError:
                flash(
                    'Failed to import identity: identity with same name already exists.',
                    'error')
                return redirect(return_url)

            flash('Identity was successfully imported.', 'success')
            return redirect(self.get_save_return_url(identity,
                                                     is_created=True))

        return self.render('admin/identity_import.html',
                           form=form,
                           return_url=return_url)
示例#16
0
class CurriculumForm(form.Form):
    name = fields.StringField('curriculum')
    school = fields.SelectField('School', widget=Select2Widget())

    # Form list
    Course = InlineFieldList(InlineFormField(CourseForm))
class UserForm(Form):
    access_token = StringField('access_token')
    mail = StringField('mail', default="")
    tg_login = StringField('tg_login', default="")
    auth_methods_submitted = InlineFieldList(StringField("auth_method"))
    role = StringField("role", default="")
示例#18
0
class SchoolForm(form.Form):
    name = fields.StringField('name')

    # Form list
    Branch = InlineFieldList(InlineFormField(BranchForm))