5.1.2.1. Database Models¶
Contains documentation for all database model classes
5.1.2.1.1. Projects¶
Contains model classes related to managing projects on the Omicron server
-
class
database.models.projects.Project(project_name, description, date_created=datetime.datetime(2016, 2, 22, 2, 44, 10, 672115), owner=None)[source]¶ Models a project for a given user. The project constructor requires the following
Variables: - project_name (str) – The name of the project
- description (str) – A description of the project
- date_created (datetime.datetime) – The date at which the project was created, defaults to the current datetime
- owner (User) – The user who owns this project
-
__init__(project_name, description, date_created=datetime.datetime(2016, 2, 22, 2, 44, 10, 672115), owner=None)¶ Instantiates the variables described above
-
date_created_isoformat¶ Returns the project date created as an ISO 8601 - compliant string :return: The date string :rtype: str
-
get¶ Returns a dictionary representing a summary of the project. :return: A summary of the project :rtype: dict
5.1.2.1.2. Users¶
Contains all model classes relevant to management of users
-
class
database.models.users.Administrator(username, password, email, date_created=datetime.datetime(2016, 2, 22, 2, 44, 10, 676934))[source]¶ Represents a “superuser” type. The administrator will be able to oversee all projects, revoke anyone’s token, and approve new users into the system, when user approval is complete.
-
class
database.models.users.Token(token_string, expiration_date=None, owner=None)[source]¶ Contains methods for manipulating user tokens.
-
class
database.models.users.User(username, password, email, date_created=datetime.datetime(2016, 2, 22, 2, 44, 10, 676934))[source]¶ Base class for a User.
-
classmethod
from_session(username, session)[source]¶ Provides an alternate “constructor” by using the supplied session and returning the user matching the given username. The method also asserts that a user was returned by the query. If it did not happen, something horrible has happened.
Parameters: - username (str) – The username of the user to get
- session (ContextManagedSession) – The session to use for retrieving the user
Returns: The user to be retrieved
-
generate_auth_token(expiration=600, session=ContextManagedSession(bind=Engine(sqlite:////home/docs/checkouts/readthedocs.org/user_builds/omicron-server/checkouts/latest/test_db.sqlite3), expire_on_commit=True))[source]¶ Generates a token for the user. The user’s token is a UUID 1, randomly generated in this function. A
Tokenis created with this randomly-generated UUID, the UUID token is hashed, and stored in the database.Warning
The string representation of the generated token is returned only once, and is not recoverable from the data stored in the database. The returned token is also a proxy for the user’s password, so treat it as such.
Parameters: - expiration (int) – The lifetime of the token in seconds.
- session (ContextManagedSession) – The database session with
which this method will interact, in order to produce a token. By
default, this is a
ContextManagedSessionthat will point toconf.DATABASE_ENGINE, but for the purposes of unit testing, it can be repointed.
Returns: A tuple containing the newly-created authentication token, and the expiration date of the new token. The expiration date is an object of type
DatetimeReturn type: tuple(str, Datetime)
-
static
hash_password(password)[source]¶ Hash the user’s password :param str password: The password to hash :return:
-
classmethod