コード例 #1
0
    def validate_form(self, form):
        """
            Validation personnalisée du form
        """
        # Essai de récupérer en BD la vue sql déclarée
        # Delete n'a pas d'attribut view_name
        view_name = getattr(form, 'view_name', '')
        schema_name = getattr(form, 'schema_name', '')
        geometry_field = getattr(form, 'geometry_field', None)
        geometry_srid = getattr(form, 'geometry_srid', None)
        if (is_form_submitted() and view_name and schema_name):
            try:
                if geometry_field.data and geometry_srid.data is None:
                    raise KeyError(
                        "Field Geometry SRID is mandatory with Geometry field"
                    )

                query = GenericQueryGeo(
                    DB, view_name.data, schema_name.data,
                    geometry_field=geometry_field.data, filters=[]
                )
                query.return_query()

            except Exception as exp:
                flash(exp, category='error')
                return False

        return super(ExportView, self).validate_form(form)
コード例 #2
0
    def index(self):
        # 加载该界面的一些常用数据
        form = EarlyWarningForm()

        warn = EarlyWarning(current_app.redis_cache)
        warn.get_form(form)
        warn.get_value()
        warn.out_put()
        if is_form_submitted():
            form = EarlyWarningForm(formdata=get_form_data())
            if form.validate():
                warn.get_form(form)
                warnings = warn.set_warning()
                warn.out_put()
                current_app.predicts_cfg = warnings
                flash('配置设置成功。', 'success')
            else:
                flash('配置设置失败。', 'error')

        # 获取后台支持的文档类别
        resp = proxy.get('/v1/doc-type/')
        support_doctypes = []
        if resp.status_code == 200 and resp.json()['items'] is not None:
            support_doctypes = [item['id'] for item in resp.json()['items']]
        return self.render(self._template,
                           form=form,
                           support_doctypes=support_doctypes)
コード例 #3
0
    def create_view(self):
        """customize the create view"""

        return_url = '/'

        form = self.create_form()
        if not hasattr(form,
                       '_validated_ruleset') or not form._validated_ruleset:
            self._validate_form_instance(ruleset=self._form_create_rules,
                                         form=form)

        if self.validate_form(form):
            model = self.create_model(form)

            if model:
                # flash('Software was successfully submitted.', 'success')
                return redirect(
                    url_for('submit_software.success', software_id=model.id))
        elif is_form_submitted():
            flash('Some fields are missing', 'error')

        form_opts = FormOpts(widget_args=self.form_widget_args,
                             form_rules=self._form_create_rules)

        return self.render(
            'admin/custom_create.html',
            # model=model,
            form=form,
            form_opts=form_opts,
            return_url=return_url)
コード例 #4
0
    def create_form(self, obj=None):
        if not is_form_submitted():
            current_config = offers_repository.get_current_offer_validation_config(
            )
            if current_config:
                form = OfferValidationConfigForm()
                form.specs.data = yaml.dump(current_config.specs,
                                            indent=4,
                                            allow_unicode=True)
                return form

        return OfferValidationConfigForm(get_form_data())
コード例 #5
0
    def validate_form(self, form):
        """
        Additional server side validation for camera config. Calculate max distance between the GCPS coordinates.

        :param form:
        :return:
        """
        if is_form_submitted():
            prevent_submit = False
            # Get list of all model attributes.
            mapper = inspect(CameraConfig)
            for column in mapper.attrs:
                # Check if model attribute is present in this form.
                if column.key != "time_end" and column.key != "crs" and hasattr(
                        form, column.key) and getattr(form,
                                                      column.key) is not None:
                    # Check if data is set for this form field.
                    if getattr(form, column.key).data is None:
                        getattr(form, column.key).errors = ['Required']
                        prevent_submit = True

            # Check for max distance between ground control points.
            if hasattr(form, "gcps_dst_0_x") and getattr(
                    form, "gcps_dst_0_x") is not None and not prevent_submit:
                gcps = []
                for i in range(4):
                    if hasattr(form, "gcps_dst_{}_x".format(i)) and hasattr(
                            form, "gcps_dst_{}_y".format(i)):
                        gcps.append([
                            float(
                                getattr(form, "gcps_dst_{}_x".format(i)).data),
                            float(
                                getattr(form, "gcps_dst_{}_y".format(i)).data)
                        ])

                for i in range(len(gcps)):
                    for j in range(i + 1, len(gcps)):
                        distance = sqrt(
                            pow(gcps[i][0] - gcps[j][0], 2) +
                            pow(gcps[i][1] - gcps[j][1], 2))
                        if distance > 25:
                            flash(
                                "Distance between ground control points {} and {} is {:.1f} meters."
                                .format(i + 1, j + 1, distance), "error")
                            return False

            if prevent_submit:
                return False

        return super(CameraConfigView, self).validate_form(form)
コード例 #6
0
ファイル: app.py プロジェクト: hakten/academy
 def index(self):
     form = PyNoteDelete()
     if is_form_submitted():
         pynote = Pynote.query.filter_by(username=form.username.data, server_name=form.pynote_name.data).first()
         if pynote:
             try:
                 delete_pynote(form.username.data)
                 message = f'PyNote for {pynote.username} has been deleted.'
             except:
                 message = f'Deleting was not success for user {pynote.username}'
             return self.render('admin/delete_pynote.html', message=message, form=form)
         else:
             message = f'PyNote for {form.username.data} not found.'
             return self.render('admin/delete_pynote.html', message=message, form=form)
     return self.render('admin/delete_pynote.html', form=form)
コード例 #7
0
    def validate_form(self, form):
        if is_form_submitted() and "email" in form.data:
            _id = request.values.get('id')
            users = self.model.query.filter_by(email=form.email.data).all()

            # Ignore user with the same email if its the user being edited
            if _id and users:
                users = list(filter(lambda u: (u.id != int(_id)), users))

            if users:
                flash("Please use a different email address.",
                      category="error")
                return False

        return super(AdminModelView, self).validate_form(form)
コード例 #8
0
ファイル: check_warning.py プロジェクト: GSIL-Monitor/wxk
 def index(self):
     # 加载该界面的一些常用数据
     form = CheckWarningForm()
     warn = CheckWarning(current_app.redis_cache)
     warn.get_form(form)
     warn.get_value()
     warn.out_put()
     if is_form_submitted():
         form = CheckWarningForm(formdata=get_form_data())
         try:
             if form.validate():
                 warn.get_form(form)
                 warnings = warn.set_warning()
                 warn.out_put()
                 current_app.predicts_cfg = warnings
                 flash('配置设置成功。', 'success')
             else:
                 flash('配置设置失败!请检查您的输入数据类型是否为整数。', 'error')
         except ValueError as ex:
             flash('Failed. %s' % ex.message, 'error')
     return self.render(self._template, form=form, support_doctypes=None)
コード例 #9
0
ファイル: admin.py プロジェクト: nyirit/scoap3-next
 def validate_form(self, form):
     """Override base validation as the validation is done at a later step."""
     return is_form_submitted()