Skip to content

Commit

Permalink
Replaces "flask.ext." with "flask_".
Browse files Browse the repository at this point in the history
Flask version 0.11 deprecates imports from `flask.ext.*` in favor import
from "flask_*" for Flask extensions. This commit changes references to,
among others, `flask.ext.restless` to `flask_restless`.
  • Loading branch information
jfinkels committed Jun 5, 2016
1 parent ec4cd2c commit 518b758
Show file tree
Hide file tree
Showing 28 changed files with 115 additions and 125 deletions.
2 changes: 1 addition & 1 deletion docs/api.rst
@@ -1,7 +1,7 @@
API
===

.. module:: flask.ext.restless
.. module:: flask_restless

This part of the documentation documents all the public classes and functions
in Flask-Restless.
Expand Down
12 changes: 4 additions & 8 deletions docs/basicusage.rst
@@ -1,7 +1,3 @@
.. currentmodule:: flask.ext.restless

.. _basicusage:

Creating API endpoints
======================

Expand All @@ -10,15 +6,15 @@ SQLAlchemy or Flask-SQLALchemy. The basic setup in either case is nearly the
same.

If you have defined your models with Flask-SQLAlchemy, first, create your
:class:`~flask.Flask` object, :class:`~flask.ext.sqlalchemy.SQLAlchemy` object,
:class:`~flask.Flask` object, :class:`~flask_sqlalchemy.SQLAlchemy` object,
and model classes as usual but with one additional restriction: each model must
have a primary key column named ``id`` of type :class:`sqlalchemy.Integer` or
type :class:`sqlalchemy.Unicode`.

.. sourcecode:: python

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
Expand Down Expand Up @@ -67,9 +63,9 @@ If you are using pure SQLAlchemy::
Base.metadata.create_all()

Second, instantiate an :class:`APIManager` object with the
:class:`~flask.Flask` and :class:`~flask.ext.sqlalchemy.SQLAlchemy` objects::
:class:`~flask.Flask` and :class:`~flask_sqlalchemy.SQLAlchemy` objects::

from flask.ext.restless import APIManager
from flask_restless import APIManager

manager = APIManager(app, flask_sqlalchemy_db=db)

Expand Down
2 changes: 0 additions & 2 deletions docs/changelog.rst
@@ -1,3 +1 @@
.. currentmodule:: flask.ext.restless

.. include:: ../CHANGES
4 changes: 2 additions & 2 deletions docs/creating.rst
Expand Up @@ -7,8 +7,8 @@ For the purposes of concreteness in this section, suppose we have executed the
following code on the server::

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.restless import APIManager
from flask_sqlalchemy import SQLAlchemy
from flask_restless import APIManager

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
Expand Down
6 changes: 2 additions & 4 deletions docs/deleting.rst
@@ -1,14 +1,12 @@
.. _deleting:

Deleting resources
==================

For the purposes of concreteness in this section, suppose we have executed the
following code on the server::

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.restless import APIManager
from flask_sqlalchemy import SQLAlchemy
from flask_restless import APIManager

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
Expand Down
4 changes: 2 additions & 2 deletions docs/fetching.rst
Expand Up @@ -21,8 +21,8 @@ For the purposes of concreteness in this section, suppose we have executed the
following code on the server::

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.restless import APIManager
from flask_sqlalchemy import SQLAlchemy
from flask_restless import APIManager

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
Expand Down
12 changes: 6 additions & 6 deletions docs/processors.rst
Expand Up @@ -201,9 +201,9 @@ This may be used, for example, if all :http:method:`post` requests require
authentication::

from flask import Flask
from flask.ext.restless import APIManager
from flask.ext.restless import ProcessingException
from flask.ext.login import current_user
from flask_restless import APIManager
from flask_restless import ProcessingException
from flask_login import current_user
from mymodels import User
from mymodels import session

Expand Down Expand Up @@ -251,9 +251,9 @@ Requiring authentication for some methods
If you want certain HTTP methods to require authentication, use preprocessors::

from flask import Flask
from flask.ext.restless import APIManager
from flask.ext.restless import ProcessingException
from flask.ext.login import current_user
from flask_restless import APIManager
from flask_restless import ProcessingException
from flask_login import current_user
from mymodels import User

def auth_func(*args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion docs/requestformat.rst
Expand Up @@ -163,7 +163,7 @@ sent from the server to the client) using the
:meth:`flask.Blueprint.after_request` method::

from flask import Flask
from flask.ext.restless import APIManager
from flask_restless import APIManager

def add_cors_headers(response):
response.headers['Access-Control-Allow-Origin'] = 'example.com'
Expand Down
24 changes: 12 additions & 12 deletions docs/serialization.rst
Expand Up @@ -18,19 +18,19 @@ resource objects that satisfy the JSON API specification, your client will
receive non-compliant responses!

Your serializer classes must be a subclass of
:class:`~flask.ext.restless.Serializer` and can override the
:meth:`~flask.ext.restless.Serializer.serialize` and
:meth:`~flask.ext.restless.Serializer.serialize_many` methods to provide custom
:class:`~flask_restless.Serializer` and can override the
:meth:`~flask_restless.Serializer.serialize` and
:meth:`~flask_restless.Serializer.serialize_many` methods to provide custom
serialization (however, we recommend overriding the
:class:`~flask.ext.restless.DefaultSerializer` class, as it provides some
:class:`~flask_restless.DefaultSerializer` class, as it provides some
useful behavior in its constructor). These methods take an instance or
instances as input and return a dictionary representing a JSON API
document. Each also accepts an ``only`` keyword argument, indicating the sparse
fieldsets requested by the client. When implementing your custom serializer,
you may wish to override the :class:`flask.ext.restless.DefaultSerializer`
you may wish to override the :class:`flask_restless.DefaultSerializer`
class::

from flask.ext.restless import DefaultSerializer
from flask_restless import DefaultSerializer

class MySerializer(DefaultSerializer):

Expand All @@ -57,13 +57,13 @@ and ``'type'`` must always appear, regardless of whether they appear in
object.

Flask-Restless also provides functional access to the default serialization,
via the :func:`~flask.ext.restless.simple_serialize` and
:func:`~flask.ext.restless.simple_serialize_many` functions, which return the
via the :func:`~flask_restless.simple_serialize` and
:func:`~flask_restless.simple_serialize_many` functions, which return the
result of the built-in default serialization.

For deserialization, define your custom deserialization class like this::

from flask.ext.restless import DefaultDeserializer
from flask_restless import DefaultDeserializer

class MyDeserializer(DefaultDeserializer):

Expand All @@ -76,14 +76,14 @@ objects. The function must return an instance of the model that has the
requested fields. If you override the constructor, it must take two positional
arguments, `session` and `model`.

Your code can raise a :exc:`~flask.ext.restless.SerializationException` when
Your code can raise a :exc:`~flask_restless.SerializationException` when
overriding the :meth:`DefaultSerializer.serialize` method, and similarly a
:exc:`~flask.ext.restless.DeserializationException` in the
:exc:`~flask_restless.DeserializationException` in the
:meth:`DefaultDeserializer.deserialize` method; Flask-Restless will
automatically catch those exceptions and format a `JSON API error response`_.
If you wish to collect multiple exceptions (for example, if several fields of a
resource provided to the :meth:`deserialize` method fail validation) you can
raise a :exc:`~flask.ext.restless.MultipleExceptions` exception, providing a
raise a :exc:`~flask_restless.MultipleExceptions` exception, providing a
list of other serialization or deserialization exceptions at instantiation
time.

Expand Down
6 changes: 2 additions & 4 deletions docs/updating.rst
@@ -1,14 +1,12 @@
.. _updating:

Updating resources
==================

For the purposes of concreteness in this section, suppose we have executed the
following code on the server::

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.restless import APIManager
from flask_sqlalchemy import SQLAlchemy
from flask_restless import APIManager

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
Expand Down
4 changes: 2 additions & 2 deletions docs/updatingrelationships.rst
Expand Up @@ -7,8 +7,8 @@ For the purposes of concreteness in this section, suppose we have executed the
following code on the server::

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.restless import APIManager
from flask_sqlalchemy import SQLAlchemy
from flask_restless import APIManager

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
Expand Down
4 changes: 2 additions & 2 deletions examples/clients/jquery/__main__.py
Expand Up @@ -39,8 +39,8 @@
import os.path

from flask import Flask, render_template
from flask.ext.restless import APIManager
from flask.ext.sqlalchemy import SQLAlchemy
from flask_restless import APIManager
from flask_sqlalchemy import SQLAlchemy


# Step 0: the database in this example is at './test.sqlite'.
Expand Down
10 changes: 5 additions & 5 deletions examples/quickstart.py
@@ -1,17 +1,17 @@
import flask
import flask.ext.sqlalchemy
import flask.ext.restless
import flask_sqlalchemy
import flask_restless

# Create the Flask application and the Flask-SQLAlchemy object.
app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = flask.ext.sqlalchemy.SQLAlchemy(app)
db = flask_sqlalchemy.SQLAlchemy(app)

# Create your Flask-SQLALchemy models as usual but with the following
# restriction: they must have an __init__ method that accepts keyword
# arguments for all columns (the constructor in
# flask.ext.sqlalchemy.SQLAlchemy.Model supplies such a method, so you
# flask_sqlalchemy.SQLAlchemy.Model supplies such a method, so you
# don't need to declare a new one).
class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
Expand All @@ -31,7 +31,7 @@ class Article(db.Model):
db.create_all()

# Create the Flask-Restless API manager.
manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)
manager = flask_restless.APIManager(app, flask_sqlalchemy_db=db)

# Create API endpoints, which will be available at /api/<tablename> by
# default. Allowed HTTP methods can be specified as well.
Expand Down
8 changes: 4 additions & 4 deletions examples/server_configurations/authentication/__main__.py
Expand Up @@ -41,10 +41,10 @@
import os.path

from flask import Flask, render_template, redirect, url_for
from flask.ext.login import current_user, login_user, LoginManager, UserMixin
from flask.ext.restless import APIManager, ProcessingException, NO_CHANGE
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.wtf import PasswordField, SubmitField, TextField, Form
from flask_login import current_user, login_user, LoginManager, UserMixin
from flask_restless import APIManager, ProcessingException, NO_CHANGE
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import PasswordField, SubmitField, TextField, Form

# Step 0: the database in this example is at './test.sqlite'.
DATABASE = os.path.join(os.path.dirname(os.path.abspath(__file__)),
Expand Down
8 changes: 4 additions & 4 deletions examples/server_configurations/custom_serialization.py
Expand Up @@ -50,10 +50,10 @@
"""
from flask import Flask
from flask.ext.restless import APIManager
from flask.ext.restless import DefaultSerializer
from flask.ext.restless import DefaultDeserializer
from flask.ext.sqlalchemy import SQLAlchemy
from flask_restless import APIManager
from flask_restless import DefaultSerializer
from flask_restless import DefaultDeserializer
from flask_sqlalchemy import SQLAlchemy
from marshmallow import post_load
from marshmallow_jsonapi import fields
from marshmallow_jsonapi import Schema
Expand Down
10 changes: 5 additions & 5 deletions examples/server_configurations/separate_endpoints.py
Expand Up @@ -14,21 +14,21 @@
"""
import flask
import flask.ext.sqlalchemy
import flask.ext.restless
import flask_sqlalchemy
import flask_restless

# Create the Flask application and the Flask-SQLAlchemy object.
app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = flask.ext.sqlalchemy.SQLAlchemy(app)
db = flask_sqlalchemy.SQLAlchemy(app)

# Create your Flask-SQLALchemy models as usual but with the following two
# (reasonable) restrictions:
# 1. They must have a primary key column of type sqlalchemy.Integer or
# type sqlalchemy.Unicode.
# 2. They must have an __init__ method which accepts keyword arguments for
# all columns (the constructor in flask.ext.sqlalchemy.SQLAlchemy.Model
# all columns (the constructor in flask_sqlalchemy.SQLAlchemy.Model
# supplies such a method, so you don't need to declare a new one).
class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
Expand All @@ -50,7 +50,7 @@ class Computer(db.Model):
db.create_all()

# Create the Flask-Restless API manager.
manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)
manager = flask_restless.APIManager(app, flask_sqlalchemy_db=db)

# Create API endpoints, each at a different URL and with different allowed HTTP
# methods, but which all affect the Person model.
Expand Down
2 changes: 1 addition & 1 deletion flask_restless/__init__.py
Expand Up @@ -21,7 +21,7 @@

# The following names are available as part of the public API for
# Flask-Restless. End users of this package can import these names by doing
# ``from flask.ext.restless import APIManager``, for example.
# ``from flask_restless import APIManager``, for example.
from .helpers import collection_name
from .helpers import model_for
from .helpers import serializer_for
Expand Down
14 changes: 7 additions & 7 deletions flask_restless/manager.py
Expand Up @@ -99,7 +99,7 @@ class APIManager(object):
`session` is the :class:`~sqlalchemy.orm.session.Session` object in
which changes to the database will be made.
`flask_sqlalchemy_db` is the :class:`~flask.ext.sqlalchemy.SQLAlchemy`
`flask_sqlalchemy_db` is the :class:`~flask_sqlalchemy.SQLAlchemy`
object with which `app` has been registered and which contains the
database models for which API endpoints will be created.
Expand All @@ -108,7 +108,7 @@ class APIManager(object):
For example, to use this class with models defined in pure SQLAlchemy::
from flask import Flask
from flask.ext.restless import APIManager
from flask_restless import APIManager
from sqlalchemy import create_engine
from sqlalchemy.orm.session import sessionmaker
Expand All @@ -121,8 +121,8 @@ class APIManager(object):
and with models defined with Flask-SQLAlchemy::
from flask import Flask
from flask.ext.restless import APIManager
from flask.ext.sqlalchemy import SQLAlchemy
from flask_restless import APIManager
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLALchemy(app)
Expand Down Expand Up @@ -337,7 +337,7 @@ def init_app(self, app):
To use this method with pure SQLAlchemy, for example::
from flask import Flask
from flask.ext.restless import APIManager
from flask_restless import APIManager
from sqlalchemy import create_engine
from sqlalchemy.orm.session import sessionmaker
Expand All @@ -361,8 +361,8 @@ def init_app(self, app):
and with models defined with Flask-SQLAlchemy::
from flask import Flask
from flask.ext.restless import APIManager
from flask.ext.sqlalchemy import SQLAlchemy
from flask_restless import APIManager
from flask_sqlalchemy import SQLAlchemy
db = SQLALchemy(app)
Expand Down

0 comments on commit 518b758

Please sign in to comment.