How to use the flask.request.form function in Flask

To help you get started, we’ve selected a few Flask examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bluecatlabs / gateway-workflows / Certified / Host Record / update_host_record_example / update_host_record_example_page.py View on Github external
def update_host_record_example_update_host_record_example_page_form():
    """
    Processes the final form after the user has input all the required data.

    :return:
    """
    # pylint: disable=broad-except
    form = GenericFormTemplate()
    # Remove this line if your workflow does not need to select a configuration
    form.configuration.choices = util.get_configurations(default_val=True)
    ip4_address = []
    if form.validate_on_submit():
        try:
            # Retrieve form attributes and declare variables
            configuration = g.user.get_api().get_entity_by_id(form.configuration.data)
            view = configuration.get_view(request.form['view'])

            # Retrieve ip4 addresses removing spaces and put into list
            ip4_addresses = form.ip4_address.data.replace(' ', '')
            ip4_addresses = ip4_addresses.split(',')

            # Retrieve host record
            host_record = view.get_host_record(request.form['host_record'] + '.' + request.form['parent_zone'])

            # Retrieve original IP4 Addresses
            original_ip4 = host_record.get_property('addresses')

            for ip in ip4_addresses:
                if util.safe_str(configuration.get_ip4_address(ip).get_type()) == 'None' or ip in original_ip4:
                    ip4_address.append(ip)
                else:
                    g.user.logger.info('Form data was not valid.')
github guaosi / flask-movie / app / admin / tag.py View on Github external
def tag_edit(id):
    tag=Tag.query.get_or_404(id)
    form=TagForm(request.form)
    if request.method=='POST' and form.validate():
        with db.auto_commit():
            tag.name=form.name.data
            db.session.add(tag)
            Oplog('修改标签:' + tag.name + ',id:' + str(tag.id))
            flash('标签修改成功~','ok')
            return redirect(url_for('admin.tag_edit'),id=id)
    return render_template('admin/tag_edit.html',form=form,tag=tag,id=id)
github hoelsner / network-config-generator / app / views / template_value_set_views.py View on Github external
:return:
    """
    parent_config_template = ConfigTemplate.query.filter(ConfigTemplate.id == config_template_id).first_or_404()
    template_value_set = TemplateValueSet.query.filter(TemplateValueSet.id == template_value_set_id).first_or_404()

    form = TemplateValueSetForm(request.form, template_value_set)

    if form.validate_on_submit():
        try:
            template_value_set.hostname = form.hostname.data
            template_value_set.config_template = parent_config_template
            template_value_set.copy_variables_from_config_template()

            # update variable data
            for key in template_value_set.get_template_value_names():
                template_value_set.update_variable_value(var_name=key, value=request.form["edit_" + key])

            # hostname is always the same as the name of the template value set
            template_value_set.update_variable_value(var_name="hostname", value=template_value_set.hostname)

            db.session.add(template_value_set)
            db.session.commit()

            flash("Template Value Set successful saved", "success")
            return redirect(url_for(
                "view_config_template",
                project_id=parent_config_template.project.id,
                config_template_id=parent_config_template.id
            ))

        except IntegrityError as ex:
            if "UNIQUE constraint failed" in str(ex):
github caelum / restfulie-python / client / acceptance / fake_server.py View on Github external
def set_content():
    env.content = request.form.get('content')
    return ""
github CMGS / titan / views / account / setting.py View on Github external
def post(self):
        user = g.current_user
        password = request.form.get('password', None)
        display = request.form.get('display', None)
        city = request.form.get('city', '')
        title = request.form.get('title', '')

        attrs = {}

        if display != user.display:
            status = check_display(display)
            if not status:
                return self.render_template(error=code.ACCOUNT_USERNAME_INVAILD)
            attrs['display'] = display

        if password:
            status = check_password(password)
            if not status:
                return self.render_template(error=code.ACCOUNT_PASSWORD_INVAILD)
            attrs['password'] = password

        attrs['city'] = city
github byceps / byceps / byceps / blueprints / board / views_topic.py View on Github external
def topic_create(category_id):
    """Create a topic in the category."""
    category = h.get_category_or_404(category_id)

    form = TopicCreateForm(request.form)
    if not form.validate():
        return topic_create_form(category.id, form)

    creator = g.current_user
    title = form.title.data.strip()
    body = form.body.data.strip()

    topic, event = board_topic_command_service.create_topic(
        category.id, creator.id, title, body
    )
    topic_url = h.build_external_url_for_topic(topic.id)

    flash_success(f'Das Thema "{topic.title}" wurde hinzugefügt.')

    event = dataclasses.replace(event, url=topic_url)
    signals.topic_created.send(None, event=event)
github BlackLight / platypush / platypush / backend / http / app / utils.py View on Github external
if 'X-Session-Token' in request.headers:
        user_session_token = request.headers['X-Session-Token']
    elif 'session_token' in request.args:
        user_session_token = request.args.get('session_token')
    elif 'session_token' in request.cookies:
        user_session_token = request.cookies.get('session_token')

    if user_session_token:
        user, session = user_manager.authenticate_user_session(user_session_token)
    else:
        return False

    if user is None:
        return False

    return session.csrf_token is None or request.form.get('csrf_token') == session.csrf_token
github inspirehep / inspire-next / inspire / modules / workflows / actions / hep_approval.py View on Github external
value = request.form.get("value", "")

        # Audit logging
        results = bwo.get_tasks_results()
        prediction_results = results.get("arxiv_guessing", {})
        log_prediction_action(
            action="resolve",
            prediction_results=prediction_results,
            object_id=bwo.id,
            user_id=current_user.get_id(),
            source="holdingpen",
            user_action=value,
        )

        upload_pdf = request.form.get("pdf_submission", False)

        bwo.remove_action()
        extra_data = bwo.get_extra_data()
        extra_data["approved"] = value in ('accept', 'accept_core')
        extra_data["core"] = value == "accept_core"
        extra_data["reason"] = request.form.get("text", "")
        extra_data["pdf_upload"] = True if upload_pdf == "true" else False
        bwo.set_extra_data(extra_data)
        bwo.save(version=ObjectVersion.WAITING)
        bwo.continue_workflow(delayed=True)

        if extra_data["approved"]:
            return {
                "message": "Suggestion has been accepted!",
                "category": "success",
            }
github yampelo / beagle / beagle / web / api / views.py View on Github external
def _setup_params(form: dict, schema: dict, is_external: bool) -> dict:
    logger.debug("Setting up parameters")

    params: Dict[str, Any] = {}

    if is_external:
        # External parameters are in the form
        params = {}
        for param in schema["params"]:
            if param["name"] in request.form:
                params[param["name"]] = request.form[param["name"]]

        logger.info(f"ExternalDataSource params received {params}")

    else:
        for param in schema["params"]:
            # Save the files, keep track of which parameter they represent
            if param["name"] in request.files:
                params[param["name"]] = tempfile.NamedTemporaryFile()
                request.files[param["name"]].save(params[param["name"]].name)
                params[param["name"]].seek(0)

        logger.info(f"Saved uploaded files {params}")

    logger.debug("Set up parameters")