OpenQuizz
Une application de gestion des contenus pédagogiques
|
Public Member Functions | |
def | __init__ (self, app=None, uri=None, *args, **kwargs) |
def | init_app (self, app, uri=None, *args, **kwargs) |
def | send_file (self, filename, base="fs", version=-1, cache_for=31536000) |
def | save_file (self, filename, fileobj, base="fs", content_type=None, **kwargs) |
Data Fields | |
cx | |
db | |
Manages MongoDB connections for your Flask app. PyMongo objects provide access to the MongoDB server via the :attr:`db` and :attr:`cx` attributes. You must either pass the :class:`~flask.Flask` app to the constructor, or call :meth:`init_app`. PyMongo accepts a MongoDB URI via the ``MONGO_URI`` Flask configuration variable, or as an argument to the constructor or ``init_app``. See :meth:`init_app` for more detail.
def __init__ | ( | self, | |
app = None , |
|||
uri = None , |
|||
* | args, | ||
** | kwargs | ||
) |
def init_app | ( | self, | |
app, | |||
uri = None , |
|||
* | args, | ||
** | kwargs | ||
) |
Initialize this :class:`PyMongo` for use. Configure a :class:`~pymongo.mongo_client.MongoClient` in the following scenarios: 1. If ``uri`` is not ``None``, pass the ``uri`` and any positional or keyword arguments to :class:`~pymongo.mongo_client.MongoClient` 2. If ``uri`` is ``None``, and a Flask config variable named ``MONGO_URI`` exists, use that as the ``uri`` as above. The caller is responsible for ensuring that additional positional and keyword arguments result in a valid call. .. versionchanged:: 2.2 The ``uri`` is no longer required to contain a database name. If it does not, then the :attr:`db` attribute will be ``None``. .. versionchanged:: 2.0 Flask-PyMongo no longer accepts many of the configuration variables it did in previous versions. You must now use a MongoDB URI to configure Flask-PyMongo.
def save_file | ( | self, | |
filename, | |||
fileobj, | |||
base = "fs" , |
|||
content_type = None , |
|||
** | kwargs | ||
) |
Save a file-like object to GridFS using the given filename. .. code-block:: python @app.route("/uploads/<path:filename>", methods=["POST"]) def save_upload(filename): mongo.save_file(filename, request.files["file"]) return redirect(url_for("get_upload", filename=filename)) :param str filename: the filename of the file to return :param file fileobj: the file-like object to save :param str base: base the base name of the GridFS collections to use :param str content_type: the MIME content-type of the file. If ``None``, the content-type is guessed from the filename using :func:`~mimetypes.guess_type` :param kwargs: extra attributes to be stored in the file's document, passed directly to :meth:`gridfs.GridFS.put`
def send_file | ( | self, | |
filename, | |||
base = "fs" , |
|||
version = -1 , |
|||
cache_for = 31536000 |
|||
) |
Respond with a file from GridFS. Returns an instance of the :attr:`~flask.Flask.response_class` containing the named file, and implement conditional GET semantics (using :meth:`~werkzeug.wrappers.ETagResponseMixin.make_conditional`). .. code-block:: python @app.route("/uploads/<path:filename>") def get_upload(filename): return mongo.send_file(filename) :param str filename: the filename of the file to return :param str base: the base name of the GridFS collections to use :param bool version: if positive, return the Nth revision of the file identified by filename; if negative, return the Nth most recent revision. If no such version exists, return with HTTP status 404. :param int cache_for: number of seconds that browsers should be instructed to cache responses
cx |
db |