This documentation is for Flask-Diamond 0.5.1.
Bases: flask_sqlalchemy.Model, flask_security.core.UserMixin, flask_diamond.mixins.crud.CRUDMixin, flask_diamond.mixins.marshmallow.MarshmallowMixin
boolean – whether the user account is active
update a User account so that it includes a new Role
Parameters: | role_name (string) – the name of the Role to add |
---|
datetime – when the user account was confirmed
datetime – the time of the current login, if any
string – the IP address of the current login
string – email address
integer – primary key
datetime – the time of the most recent login
string – the IP address of the previous login
integer – the number of times this account been accessed
password – the users’s password
Create a new user account.
Parameters: |
|
---|
Bases: flask_sqlalchemy.Model, flask_security.core.RoleMixin, flask_diamond.mixins.crud.CRUDMixin, flask_diamond.mixins.marshmallow.MarshmallowMixin
For the purpose of access controls, Roles can be used to create collections of users and give them permissions as a group.
string – a sentence describing the role
integer – primary key
string – what the role is called
Convenience functions for CRUD operations.
Adapted from flask-kit.
Create a new object.
Parameters: |
|
---|---|
Returns: | the object that was created |
Delete this object.
Parameters: | commit (boolean) – whether to commit the change immediately to the database |
---|---|
Returns: | whether the delete was successful |
Find an object in the database with certain properties.
Parameters: | kwargs (dict) – the values of the object to find |
---|---|
Returns: | the object that was found, or else None |
Find an object or, if it does not exist, create it.
Parameters: | kwargs (dict) – the values of the object to find or create |
---|---|
Returns: | the object that was created |
Retrieve an object of this class from the database.
Parameters: | id (integer) – the id of the object to be retrieved |
---|---|
Returns: | the object that was retrieved |
create objects of Model class from an array of python objects
create a Model object from a file_handle pointing to a JSON file
Initialize Security for application.
Parameters: | kwargs (dict) – parameters that will be passed through to Flask-Security |
---|---|
Returns: | None |
A number of common User account operations are provided by Flask- Security. This function is responsible for associating User models in the database with the Security object.
In case you need to override a Flask-Security form (as is the case with implementing CAPTCHA) then you must use super() from within your application and provide any arguments destined for Flask-Security.
>>> result = self.super("accounts", user=User, role=Role,
>>> confirm_register_form=ExtendedRegisterForm)
Initialize the Administrative GUI.
Parameters: | index_view (AdminIndexView) – the View that will act as the index page of the admin GUI. |
---|---|
Returns: | None |
The administration GUI is substantially derived from Flask-Admin. When this function is called, it will instantiate blueprints so the application serves the admin GUI via the URL http://localhost/admin.
Typically, you will want to call this function even if you override it. The following example illustrates using super() to invoke this administration() function from within your own application.
>>> admin = super(MyApp, self).administration(
>>> index_view=MyApp.modelviews.RedirectView(name="Home")
>>> )
Initialize blueprints.
Returns: | None |
---|
By default, this function does nothing. Your application needs to overload this function in order to implement your View functionality. More information about blueprints can be found in the Flask documentation.
Initialize database
Returns: | None |
---|
Flask-Diamond assumes you are modelling your solution using an Entity- Relationship framework, and that the application will use a relational database (e.g. MySQL, Postgres, or SQlite3) for model persistence. Thus, SQLAlchemy and Flask- SQLalchemy are used for database operations.
Typically, this just works as long as SQLALCHEMY_DATABASE_URI is set correctly in the application configuration.
Initialize the DebugToolbar
Returns: | None |
---|
The DebugToolbar is a handy utility for debugging your application during development.
This function obeys the DEBUG_TOOLBAR configuration setting. Only if this value is explicitly set to True will the Debug Toolbarr run.
Initialize email facilities.
Returns: | None |
---|
Flask-Mail is a useful tool for creating and sending emails from within a Flask application. There are a number of configuration settings beginning with MAIL_ that permit control over the SMTP credentials used to send email.
Initialize handlers for HTTP error events
Returns: | None |
---|
Flask is able to respond to HTTP error codes with custom behaviours. By default, it will redirect error 403 (forbidden) to the login page.
request handlers
Returns: | None |
---|
Flask handles requests for URLs by scanning the URL path. Typically, any serious functionality will be collected into Views. However, this function is a chance to define a few simple utility URLs.
If in your application you want to disable the default handlers in Flask-Diamond, you can override them like this.
>>> def request_handlers(self):
>>> pass
Initialize REST API.
Returns: | None |
---|
By default, this function does nothing. Your application needs to overload this function in order to implement your REST API. More information about REST can be found in the documentation.
api_map is an optional function that can be responsible for setting up the API. This is usually accomplished with a series of add_resource() invocations. api_map must take one parameter, which is the Flask-Restful object managed by Flask-Diamond.
You will end up writing something like this in your application:
planet = Planet.find(name=name) if planet:
return(planet.dump())
Initialize Flask signal handlers
Returns: | None |
---|
Flask provides a number of signals corresponding to things that happen during the operation of the application, which can also be thought of as events. It is possible to create signal handlers that will respond to these events with some behaviour.
Initialize web assets.
Returns: | None |
---|
webassets make it simpler to process and bundle CSS and Javascript assets. This can be baked into a Flask application using Flask-Assets