MongoEngine flask extension with WTF model forms support

Overview

Flask-MongoEngine

Info: MongoEngine for Flask web applications.
Repository: https://github.com/MongoEngine/flask-mongoengine
https://travis-ci.org/MongoEngine/flask-mongoengine.svg?branch=master https://coveralls.io/repos/github/MongoEngine/flask-mongoengine/badge.svg?branch=master

About

Flask-MongoEngine is a Flask extension that provides integration with MongoEngine. It handles connection management for your app. You can also use WTForms as model forms for your models.

Documentation

You can find the documentation at https://flask-mongoengine.readthedocs.io

Installation

You can install this package using pypi: pip install flask-mongoengine

Tests

To run the test suite, ensure you are running a local copy of Flask-MongoEngine and simply run: pytest.

To run the test suite on every supported versions of Python, PyPy and MongoEngine you can use tox. Ensure tox and each supported Python, PyPy versions are installed in your environment:

# Install tox
$ pip install tox
# Run the test suites
$ tox

To run a single or selected test suits, use pytest -k option.

Contributing

We welcome contributions! see the Contribution guidelines

Community

License

Flask-MongoEngine is distributed under MIT license, see LICENSE for more details.

Comments
  • Next Milestone Questions & Call for Maintainers!

    Next Milestone Questions & Call for Maintainers!

    @anemitz & @thomasst do you guys have any plans for the next milestone / release of flask-mongoengine?

    Unfortunately, I dont have the time available at the minute to fix the issues and push a release. If you are in the same boat, I'm happy to try and draft in more maintainers!

    Any potential maintainers - please post here if you want to help further flask-mongoengine - I'm happy to mentor as well!

    opened by rozza 50
  • Can't install flask-mongoengine in my virtual environment

    Can't install flask-mongoengine in my virtual environment

    pip install flask-mongoengine Collecting flask-mongoengine Using cached flask-mongoengine-0.9.5.tar.gz (111 kB) ERROR: Command errored out with exit status 1: command: 'c:\users\keerthivasan\desktop\pybox\venv\scripts\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\keerthivasan\AppData\Local

    \Temp\pip-install-su4c26f2\flask-mongoengine\setup.py'"'"'; file='"'"'C:\User s\keerthivasan\AppData\Local\Temp\pip-install-su4c26f2\flask-mongoengine\setup. py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'" '\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg _info --egg-base 'C:\Users\keerthivasan\AppData\Local\Temp\pip-pip-egg-info-xw613uem' cwd: C:\Users\keerthivasan\AppData\Local\Temp\pip-install-su4c26f2\flask-mong oengine\

    im trying to install flask-mongoengine but can't for some reasons. Help me out

    opened by keerthivasan-g 18
  • add mongomock if app.config['TESTING']

    add mongomock if app.config['TESTING']

    i would love to be able to have a mongomock connection if app.config['TESTING'] is true this would allow easier testing of the flask application (otherwise an in-memory mongo like the one implemented in ming would be great)

    type: enhancement 
    opened by ocean1 18
  • Using mongodb:// style uri's no longer work

    Using mongodb:// style uri's no longer work

    This line is the culprit. Was noticed before the release of 0.8 :(

    I get a failure: pymongo.errors.ServerSelectionTimeoutError: r2d2_local:27017: [Errno -2] Name or service not known

    r2d2_local is the name of my database, not my host.

    type: bug 
    opened by agani 16
  • Document and fix connection code

    Document and fix connection code

    Reverting/ fixing changes from https://github.com/MongoEngine/flask-mongoengine/pull/231. Relevant criticism: https://github.com/MongoEngine/flask-mongoengine/pull/231#issuecomment-255568259.

    The main goal of this PR is to fix a buggy connection code introduced in v0.8. It also makes the code cleaner and easier to understand through a better separation of responsibilities and a better documentation.

    This is unfortunately dropping support for mongomock, but many things were broken about it to begin with. We should revisit adding it in the future, though personally I don't see a point for it... In the age of Travis/CircleCI/etc., it's so easy to run a real MongoDB in your tests.

    Things to test manually:

    • [x] Connecting to multiple mongos in a sharded cluster
    • [x] Connecting to a replica set
    • [x] Connecting to a server that requires authentication
    • [x] All of the above via a MongoDB URI

    Fixes #266 #283 #282 #259 #258 #254 #250 #247 #267

    opened by wojcikstefan 12
  • model_form Forms return '' instead of None for empty fields.

    model_form Forms return '' instead of None for empty fields.

    The email field validates '' differently than None. '' is an invalid email, None is a valid input. model_form based Forms return the wrong data.

    from flask import Flask
    from flask.ext.mongoengine import MongoEngine
    import unittest
    from flask.ext.mongoengine.wtf import model_form
    from werkzeug.datastructures import MultiDict
    
    app = Flask(__name__)
    
    app.config.update(
        DEBUG = True,
        TESTING = True,
        MONGODB_HOST = 'localhost',
        MONGODB_PORT = '27017',
        MONGODB_DB = 'mongorest_example_app',
    )
    
    db = MongoEngine(app)
    
    class User(db.Document):
        email = db.EmailField(required=False)
        name = db.StringField()
    
    class FieldTestCase(unittest.TestCase):
        def setUp(self):
            self.app = app.test_client()
    
        def test_emptyemail(self):
            with app.test_request_context('/?name=Peter'):
                TestForm = model_form(User)
                data = MultiDict({'name':'John Doe'})
                form = TestForm(data,csrf_enabled=False)
                assert form.validate()
                assert form.data['email'] == None
    # form.data['email'] is '' instaed of None
    
    opened by lucasvo 12
  • while assigning replicaSet parameter, the replicaSet is gone. This is because of the below code...

    while assigning replicaSet parameter, the replicaSet is gone. This is because of the below code...

    In master branch, flask_mongoengine/connection.py, line 265:

    if conn_setting.pop('replicaset', None):
        resolved['replicaSet'] = conn_setting.pop('replicaset', None)
    

    what is f***ing going on lol

    Because dict.pop() will return and also remove specific key value pair from dict, so we cannot do dict.pop() twice. Actually this code should be:

    replica_set = conn_setting.pop('replicaset', None)
    if replica_set:
        resolved['replicaSet'] = replica_set
    
    type: bug 
    opened by fieliapm 11
  • Model form generator now accepts wtf custom 'validators' and 'filters' on model field definition.

    Model form generator now accepts wtf custom 'validators' and 'filters' on model field definition.

    Added a wrapper sub-class WtfBaseField to allow additional WTForm field parameters and settings needed by flask-mongoengine, without necessarily going through to the core mongoengine BaseField.

    • flask_mongoengine/__init__.py has patching to redirect wtf mongoengine Fields of base BaseField to use WtfBaseField
    • wtf/orm.py now has 'validators' and 'filters' allowed on behalf wtf model field generator.

    Example:

     class Contact(db.Document)
        telephone = db.StringField(
            required=True,
            validators=[
              validators.InputRequired(message=u'Missing telephone.'),
            ],
            max_length=50
        )
    
    opened by losintikfos 11
  • Connect parameter

    Connect parameter

    This PR allows to use MONGODB_CONNECT parameter and document both the existing MONGO_SETTINGS['connect'] and the new MONGODB_CONNECT parameters.

    I had to read #255 to discover this possibility which isn't documented and this solve a common issue.

    Context: this feature seems to appear in #280 but there was issues and PRs before. ex: #255, #266, #126

    opened by noirbizarre 10
  • Code quality improvements

    Code quality improvements

    This is a follow-up after #270. I tightened flake8's code checking, added flake8-import-order and fixed existing imports (see https://www.python.org/dev/peps/pep-0008/#imports for details), and added some minor style tweaks.

    @lafrech let me know what you think :)

    opened by wojcikstefan 10
  • Allow RadioField

    Allow RadioField

    Hi! I would like to use a StringField with choices as, instead of a SelectField or MultiSelectField, RadioField For that I modify the orm.py adding 2 lines of code Instead of:

    if field.choices:
                kwargs['choices'] = field.choices
    
                if ftype in self.converters:
                    kwargs["coerce"] = self.coerce(ftype)
                if kwargs.pop('multiple', False):
                    return f.SelectMultipleField(**kwargs)
                return f.SelectField(**kwargs)
    

    I have

    if field.choices:
                kwargs['choices'] = field.choices
    
                if ftype in self.converters:
                    kwargs["coerce"] = self.coerce(ftype)
                if kwargs.pop('multiple', False):
                    return f.SelectMultipleField(**kwargs)
                if kwargs.pop('radio', False):
                    return f.RadioField(**kwargs)
                return f.SelectField(**kwargs)
    

    Notice this 2 new lines:

                if kwargs.pop('radio', False):
                    return f.RadioField(**kwargs)
    

    I would prefer to make a pull request but I wasn't able to run the test (if you could point me to the test help I would apreciate it)

    In the other hand, I would prefer that choices will be treated in the converter to allow subclassing better but this change will be ok for me

    What do you think?

    Thanks!

    opened by Garito 10
  • Regarding new release

    Regarding new release

    Is new release planned any time soon? I can see that release tag for 1.0.0 was 2020.

    I can see that quite a lot of work is merged into master, but would avoid using it for production since it might not be stable enough.

    opened by rimvislt 1
  • docs: Fix a few typos

    docs: Fix a few typos

    There are small typos in:

    • CONTRIBUTING.md
    • docs/forms.md

    Fixes:

    • Should read significant rather than signigicant.
    • Should read responsibility rather than responsobility.
    • Should read hardcoded rather than hardcodded.
    • Should read extract rather than exctract.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 0
  • New JSONProvider use of super() not quite right

    New JSONProvider use of super() not quite right

    I am implementing similar logic in Flask-Security - so stole some code :-)

    The code:

    class MongoEngineJSONProvider(superclass):
            """A JSON Provider update for Flask 2.2.0+"""
    
            @staticmethod
            def default(obj):
                """Extend JSONProvider default static method, with Mongo objects."""
                if isinstance(
                    obj,
                    (BaseDocument, QuerySet, CommandCursor, DBRef, ObjectId),
                ):
                    return _convert_mongo_objects(obj)
                return super().default(obj)
    

    I don't think is quite right - using super() for static methods doesn't work - you need to do something like: return super(MongoEngineJSONProvider, MongoEngineJSONProvider).default(obj)

    type: bug 
    opened by jwag956 1
  • Migration to 2.0.0 documentation

    Migration to 2.0.0 documentation

    Explain:

    • [ ] New installation behavior
    • [ ] Recommended approach to config configuration
    • [ ] New restriction to passing arguments on model field definition
    • [ ] ORM module deprecation
    topic: documentation 
    opened by insspb 1
Releases(v1.0.0)
  • v1.0.0(Nov 21, 2020)

    Changes

    • Use fldt.$ to avoid double jQuery.noConflict(true) (#313) @martinhanzik
    • Run Travis builds in a container-based environment (#301) @wojcikstefan
    • Fix test and mongomock (#304) @touilleMan
    • Connect parameter (#321) @noirbizarre

    Breaking Changes

    • Update install requirements to last flask dependencies (#390) @insspb
    • Pymongo support < 3.6.0 dropped (#372) @insspb
    • Drop python versions from python 2.7 to 3.5 (#359) @insspb
    • Code reformatting, cleanup and formatting automation (#368) @insspb

    Added

    • Restored changelogs for versions 0.9.2-0.9.5 (#370) @insspb
    • Python 3.9 support added (#415) @insspb
    • Github workflows for labels verification and releases notes (#391) @insspb
    • Github Actions CI/CD tests for project (#394) @insspb
    • Added label_modifier option on ReferenceField conversion (#348) @sebbekarlsson
    • Add custom message option for get_or_404 function (#361) @insspb
    • Add DateField support #405 @qisoster (#416) @insspb
    • Add Codeclimate and codecov to Github CI/CD (#396) @insspb

    Changed

    • Travis updated to use focal ubuntu images (#419) @insspb
    • Сlarify new URI style setting proccesing regarding db. (#329) @Irisha
    • Update setup.py: Remove setup_requirements (#380) @9nix00
    • Update installation documentation (#378) @onlinejudge95
    • Tests refactoring. Moving to pytest engine (#397) @insspb
    • Replace general Exception raising with more detailed type (#398) @insspb
    • Remove six dependency (Drop Python 2.7 compatibility) (#393) @insspb
    • Changed: Imports order, drop imports for python 2.7 (#374) @insspb
    • Allow keep config in MongoEngine object until init_app (#401) @insspb

    Fixed

    • Pass 'places' to 'precision' in wtfForms DecimalField convertation (#343) @PeterKharchenko
    • ListField documentation extended with min_entries info (#353) @molitoris
    • Fixed: docstrings typo in flask_mongoengine/operation_tracker.py (#383) @timgates42
    • Fix formdata default value on ModelForm <-> FlaskForm inheritance. (#387) @sdayu

    This release is made by wonderful contributors:

    @9nix00, @Irisha, @PeterKharchenko, @alysivji, @insspb, @itsnauman, @martinhanzik, @molitoris, @noirbizarre, @onlinejudge95, @qisoster, @sdayu, @sebbekarlsson, @timgates42, @touilleMan and @wojcikstefan

    Source code(tar.gz)
    Source code(zip)
  • v0.9.2(Feb 16, 2017)

  • v0.9.1(Feb 16, 2017)

    • Fixed setup.py for various platforms (#298).
    • Added Flask-WTF v0.14 support (#294).
    • MongoEngine instance now holds a reference to a particular Flask app it was initialized with (#261).
    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Dec 12, 2016)

  • v0.8.2(Dec 11, 2016)

  • 0.8.1(Nov 30, 2016)

  • 0.8(Aug 11, 2016)

    • Dropped MongoEngine 0.7 support
    • Added MongoEngine 0.10 support
    • Added PyMongo 3 support
    • Added Python3 support up to 3.5
    • Allowed empying value list in SelectMultipleField
    • Fixed paginator issues
    • Use InputRequired validator to allow 0 in required field
    • Made help_text Field attribute optional
    • Added "radio" form_arg to convert field into RadioField
    • Added "textarea" form_arg to force conversion into TextAreaField
    • Added field parameters (validators, filters...)
    • Fixed 'False' connection settings ignored
    • Fixed bug to allow multiple instances of extension
    • Added MongoEngineSessionInterface support for PyMongo's tz_aware option
    • Support arbitrary primary key fields (not "id")
    • Configurable httponly flag for MongoEngineSessionInterface
    • Various bugfixes, code cleanup and documentation improvements
    • Move from deprecated flask.ext.* to flask_* syntax in imports
    • Added independent connection handler for FlaskMongoEngine
    • All MongoEngine connection calls are proxied via FlaskMongoEngine connection handler
    • Added backward compatibility for settings key names
    • Added support for MongoMock and temporary test DB
    • Fixed issue with multiple DB support
    • Various other bugfixes
    Source code(tar.gz)
    Source code(zip)
  • 0.7.5(Jan 9, 2016)

    • Changes to resolve MongoEngine deprecated help_text and safe attribute issues.
    • Minor PyPy3 compatibility issue with operation tracker resolved.
    • SESSION_TTL setting is accepted via app config to set and override session timeout default.
    • Provided RadioField component via model form.
    • Other enhancements
    Source code(tar.gz)
    Source code(zip)
Owner
MongoEngine
MongoEngine
A web application made with Flask that works with a weather service API to get the current weather from all over the world.

Weather App A web application made with Flask that works with a weather service API to get the current weather from all over the world. Uses data from

Christian Jairo Sarmiento 19 Dec 02, 2022
Flask extension for Pusher

Flask-Pusher Flask extension for Pusher. It is a thin wrapper around the official client, binding Flask app to Pusher client. Installation Install Fla

Iuri de Silvio 9 May 29, 2021
flask-reactize is a boostrap to serve any React JS application via a Python back-end, using Flask as web framework.

flask-reactize Purpose Developing a ReactJS application requires to use nodejs as back end server. What if you want to consume external APIs: how are

Julien Chomarat 4 Jan 11, 2022
REST API with Flask and SQLAlchemy. I would rather not use it anymore.

Flask REST API Python 3.9.7 The Flask experience, without data persistence :D First, to install all dependencies: python -m pip install -r requirement

Luis Quiñones Requelme 1 Dec 15, 2021
An easy way to build your flask skeleton.

Flider What is Flider Flider is a lightweight framework that saves you time by creating a MVC compliant file structure and includes basic commonly use

Trevor Engen 8 Nov 17, 2022
flask-apispec MIT flask-apispec (🥉24 · ⭐ 520) - Build and document REST APIs with Flask and apispec. MIT

flask-apispec flask-apispec is a lightweight tool for building REST APIs in Flask. flask-apispec uses webargs for request parsing, marshmallow for res

Joshua Carp 617 Dec 30, 2022
Regex Converter for Flask URL Routes

Flask-Reggie Enable Regex Routes within Flask Installation pip install flask-reggie Configuration To enable regex routes within your application from

Rhys Elsmore 48 Mar 07, 2022
Flask + marshmallow for beautiful APIs

Flask-Marshmallow Flask + marshmallow for beautiful APIs Flask-Marshmallow is a thin integration layer for Flask (a Python web framework) and marshmal

marshmallow-code 770 Jan 05, 2023
A flask template with Bootstrap 4, asset bundling+minification with webpack, starter templates, and registration/authentication. For use with cookiecutter.

cookiecutter-flask A Flask template for cookiecutter. (Supports Python ≥ 3.6) See this repo for an example project generated from the most recent vers

4.3k Dec 29, 2022
A Flask extension that enables or disables features based on configuration.

Flask FeatureFlags This is a Flask extension that adds feature flagging to your applications. This lets you turn parts of your site on or off based on

Rachel Greenfield 131 Sep 26, 2022
Glauth management ui created with python/flask

glauth-ui Glauth-UI is a small flask web app i created to manage the minimal glauth ldap server. I created this as i wanted to use glauth for authenti

Nils Thiele 67 Nov 29, 2022
Library books management program, built with Flask, Python

Library books management program, With many features and good User Interface. built with Flask, Python. (Include Screenshots) and documentation on how to run it! Thank you :)

Thierry Mugisha 1 May 03, 2022
Curso Desenvolvimento avançado Python com Flask e REST API

Curso Desenvolvimento avançado Python com Flask e REST API Curso da Digital Innovation One Professor: Rafael Galleani Conteudo do curso Introdução ao

Elizeu Barbosa Abreu 1 Nov 14, 2021
A basic CRUD application built in flask using postgres as database

flask-postgres-CRUD A basic CRUD application built in flask using postgres as database Taks list Dockerfile Initial docker-compose - It is working Dat

Pablo Emídio S.S 9 Sep 25, 2022
:rocket: Generate a Postman collection from your Flask application

flask2postman A tool that creates a Postman collection from a Flask application. Install $ pip install flask2postman Example Let's say that you have a

Numberly 137 Nov 08, 2022
A template for Flask APIs.

FlaskAPITempate A template for a Flask API. Why tho? I just wanted an easy way to create a Flask API. How to setup First, use the template. You can do

TechStudent10 1 Dec 28, 2021
PatientDB is a flask app to store patient information.

PatientDB PatientDB on Heroku "PatientDB is a simple web app that stores patient information, able to edit the information, and able to query the data

rbb 2 Jan 31, 2022
A Flask application for Subdomain Enumeration

subdomainer-flask A Flask application for Subdomain Enumeration steps to be done git clone https://github.com/gokulapap/subdomainer-flask pip3 install

GOKUL A.P 7 Sep 22, 2022
Flask Apps - Open-Source And Paid | AppSeed

Flask Apps Open-Source web apps built with automation tools, HTML parsing and boilerplated code in Flask - - Provided by AppSeed App Generator. What i

App Generator 120 Oct 04, 2022
5 Flask Projects To Get Started

5 Flask Projects Projects Made By Using Flask Projects List Rock Paper Scissor Game - A Simple Game Weather App - A OpenWeatherMap Scraper Task List -

Root_Arch 59 Dec 18, 2022