示例#1
0
import re
import secrets
from datetime import datetime
from flask_login import UserMixin
from sqlalchemy.orm import validates
from werkzeug.security import check_password_hash
from validate_email import validate_email

from mosp.bootstrap import db

association_table_organization = db.Table(
    "association_users_organizations",
    db.metadata,
    db.Column("user_id", db.Integer, db.ForeignKey("user.id")),
    db.Column("organization_id", db.Integer, db.ForeignKey("organization.id")),
)


class User(db.Model, UserMixin):
    """
    Represent a user.
    """

    id = db.Column(db.Integer, primary_key=True)
    login = db.Column(db.String(30), unique=True, nullable=False)
    pwdhash = db.Column(db.String(), nullable=False)
    email = db.Column(db.String(256), nullable=False)
    created_at = db.Column(db.DateTime(), default=datetime.utcnow)
    last_seen = db.Column(db.DateTime(), default=datetime.utcnow)
    apikey = db.Column(db.String(100), default=secrets.token_urlsafe(64))
示例#2
0
from datetime import datetime
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy import event

from mosp.bootstrap import db

association_table_license = db.Table(
    "association_schemas_licenses",
    db.metadata,
    db.Column("schema_id", db.Integer, db.ForeignKey("schema.id")),
    db.Column("license_id", db.Integer, db.ForeignKey("license.id")),
)


class Schema(db.Model):
    """Represent a JSON schema."""

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100))
    description = db.Column(db.String(500))
    last_updated = db.Column(db.DateTime(), default=datetime.utcnow)
    json_schema = db.Column(JSONB, default={})

    # relationship
    objects = db.relationship("JsonObject",
                              backref="schema",
                              lazy="dynamic",
                              cascade="all,delete-orphan")
    licenses = db.relationship("License",
                               secondary=lambda: association_table_license,
                               backref="schemas")
示例#3
0
from datetime import datetime
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy import event

from mosp.bootstrap import db

association_table_license = db.Table(
    "association_jsonobjects_licenses",
    db.metadata,
    db.Column("json_object_id", db.Integer, db.ForeignKey("json_object.id")),
    db.Column("license_id", db.Integer, db.ForeignKey("license.id")),
)

association_table_jsonobject = db.Table(
    "association_jsonobject_jsonobject",
    db.metadata,
    db.Column("jsonobject_refers_to_id", db.Integer,
              db.ForeignKey("json_object.id")),
    db.Column("jsonobject_referred_to_by_id", db.Integer,
              db.ForeignKey("json_object.id")),
)


class JsonObject(db.Model):
    """Represent a JSON object.
    """

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text(), nullable=False)
    description = db.Column(db.Text(), nullable=False)
    last_updated = db.Column(db.DateTime(), default=datetime.utcnow())