Ejemplo n.º 1
0
from safrs import DB as db

from src.models.decorators import login_required, role_policy
from src.models.mixins import RoleMixin, SAFRSMixin, SoftDeleteMixin, TimestampMixin, UpdateMixin

product_type_distributors = db.Table(
    "product_type_distributors",
    db.Model.metadata,
    db.Column("product_type_id", db.Integer,
              db.ForeignKey("product_types.id")),
    db.Column("distributor_id", db.Integer, db.ForeignKey("distributors.id")),
)

product_type_vendors = db.Table(
    "product_type_vendors",
    db.Model.metadata,
    db.Column("product_type_id", db.Integer,
              db.ForeignKey("product_types.id")),
    db.Column("vendor_id", db.Integer, db.ForeignKey("vendors.id")),
)

product_type_attributes = db.Table(
    "product_type_attributes",
    db.Model.metadata,
    db.Column("product_type_id", db.Integer,
              db.ForeignKey("product_types.id")),
    db.Column("product_attribute_id", db.Integer,
              db.ForeignKey("product_attributes.id")),
)

Ejemplo n.º 2
0
from flask import g, request
from safrs import jsonapi_rpc, DB as db, SAFRSBase
from safrs.errors import GenericError
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.orm import validates

from src.exceptions import ValidationError
from src.models.decorators import login_required, role_policy
from src.models.helpers import hash_password
from src.models.mixins import RoleMixin, SAFRSMixin, SearchMixin, UpdateMixin


account_campaigns = db.Table(
    "account_campaigns",
    db.Model.metadata,
    db.Column("account_id", db.Integer, db.ForeignKey("accounts.id")),
    db.Column("campaign_id", db.Integer, db.ForeignKey("campaigns.id")),
)


class Account(SearchMixin, SAFRSMixin, db.Model, RoleMixin, UpdateMixin):
    __tablename__ = "accounts"

    custom_decorators = [role_policy(default="Sales Executive", view="Shopper"), login_required]
    exclude_attrs = ["_password"]

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, nullable=False, unique=True)
    _password = db.Column(db.String)
    email = db.Column(db.String)
    first_name = db.Column(db.String)
Ejemplo n.º 3
0
from safrs import DB as db, SAFRSBase
from sqlalchemy.orm import validates

from src.exceptions import ValidationError
from src.models.decorators import login_required, role_policy
from src.models.mixins import RoleMixin, SAFRSMixin, UpdateMixin

product_variant_attribute_values = db.Table(
    "product_variant_attribute_values",
    db.Model.metadata,
    db.Column("product_variant_id", db.Integer,
              db.ForeignKey("product_variants.id")),
    db.Column("product_attribute_value_id", db.Integer,
              db.ForeignKey("product_attributes_values.id")),
)


class ProductVariant(SAFRSMixin, db.Model, RoleMixin, UpdateMixin):
    __tablename__ = "product_variants"

    custom_decorators = [
        role_policy(default="Sales Executive", view="Shopper"), login_required
    ]

    id = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.String)

    # relationships
    attribute_values = db.relationship("ProductAttributeValue",
                                       product_variant_attribute_values,
                                       backref="product_variants")