Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __json__(self):
return dict(id=self.id,
name=self.name,
description=self.description,
modified=self.modified.strftime('%Y/%m/%d %H:%M'),
archived=self.archived,
schema_is_uptodate=self.schema_is_uptodate,
admin_ids=self.admin_ids,
user_ids=self.user_ids,
)
############################################################
# Containers
############################################################
class AssetContainer(DeclarativeBase):
"""Association class for object containers"""
__tablename__ = 'asset_containers'
# Columns
id = Column(String(40), primary_key=True)
association_type = Column(Unicode(50))
# Properties
@property
def owner(self):
return getattr(self, 'owner_%s' % self.association_type)
@property
def categories(self):
categories = []
for asset in self.assets:
# Association tables
############################################################
# Association table for the many-to-many relationship projects-admins.
projects_admins_table = Table('__projects_admins', metadata,
Column('project_id', Unicode(10), ForeignKey('projects.id',
onupdate="CASCADE", ondelete="CASCADE")),
Column('user_id', Unicode(40), ForeignKey('users.user_id',
onupdate="CASCADE", ondelete="CASCADE")),
)
############################################################
# Project
############################################################
class Project(DeclarativeBase):
"""Project definition."""
__tablename__ = 'projects'
# Columns
id = Column(Unicode(10), primary_key=True)
name = Column(Unicode(40), unique=True)
description = Column(Unicode)
modified = Column(DateTime, default=datetime.now)
archived = Column(Boolean, default=False)
# Relations
admins = relation('User', secondary=projects_admins_table,
backref='projects_as_admin')
# Properties
@property
self.ordering = ordering
self.naming_convention = naming_convention
def __repr__(self):
return '' % (self.id, self.ordering)
def __json__(self):
return dict(id=self.id,
ordering=self.ordering,
naming_convention=self.naming_convention,
status=hasattr(self, 'status') and self.status or None,
name=self.name,
)
class Supervisor(DeclarativeBase):
"""Category supervisor"""
__tablename__ = "supervisors"
__table_args__ = (UniqueConstraint('proj_id', 'category_id', 'user_id'),
{})
# Columns
id = Column(String(40), primary_key=True)
proj_id = Column(Unicode(10), ForeignKey('projects.id'))
category_id = Column(Unicode(40), ForeignKey('categories.id'))
user_id = Column(Unicode(40), ForeignKey('users.user_id'))
# Relations
project = relation('Project', backref=backref('supervisors',
collection_class=mapped_list('category', targetattr='user')))
category = relation('Category', backref=backref('supervisors',
@property
def has_preview(self):
if not self.thumbnail:
return False
return os.path.exists(os.path.join(G.REPOSITORY, self.thumbnail))
# Special methods
def __init__(self, id, association_type):
self.id = id
self.association_type = association_type
def __repr__(self):
return '' % (self.id, self.association_type)
class Scene(DeclarativeBase):
"""
The scene container.
This represents a "film scene" that acts as a container for Shot objects.
"""
__tablename__ = "scenes"
__table_args__ = (UniqueConstraint('proj_id', 'name'),
ForeignKeyConstraint(['id'], ['taggables.id']),
ForeignKeyConstraint(['id'], ['annotables.id']),
{})
# Columns
id = Column(String(40), primary_key=True)
proj_id = Column(Unicode(10), ForeignKey('projects.id'))
name = Column(Unicode(15))
description = Column(UnicodeText)
# This is the association table for the many-to-many relationship between
# groups and members - this is, the memberships. It's required by repoze.what.
users_groups_table = Table('__users_groups', metadata,
Column('user_id', Integer, ForeignKey('users.user_id',
onupdate="CASCADE", ondelete="CASCADE")),
Column('group_id', Integer, ForeignKey('groups.group_id',
onupdate="CASCADE", ondelete="CASCADE"))
)
############################################################
# Auth
############################################################
class Group(DeclarativeBase):
"""
Group definition for :mod:`repoze.what`.
Only the ``group_name`` column is required by :mod:`repoze.what`.
"""
__tablename__ = 'groups'
# Columns
group_id = Column(Unicode(40), primary_key=True)
group_name = Column(Unicode(16), unique=True, nullable=False)
display_name = Column(Unicode(255))
created = Column(DateTime, default=datetime.now)
# Relations
users = relation('User', secondary=users_groups_table,
backref=backref('groups', lazy=False))
self.email_address = email
def __repr__(self):
return '' % (self.user_id, self.display_name)
def __json__(self):
return dict(user_id=self.user_id,
id=self.id,
user_name=self.user_name,
display_name=self.display_name,
domain=self.domain,
project_ids=self.project_ids,
)
class Permission(DeclarativeBase):
"""
Permission definition for :mod:`repoze.what`.
Only the ``permission_name`` column is required by :mod:`repoze.what`.
"""
__tablename__ = 'permissions'
# Columns
permission_id = Column(Unicode(40), primary_key=True)
permission_name = Column(Unicode(16), unique=True, nullable=False)
description = Column(Unicode(255))
# Relations
groups = relation(Group, secondary=groups_permissions_table,
backref=backref('permissions', lazy=False))
# Properties
@property
def annotated(self):
return getattr(self, 'annotated_%s' % self.association_type)
# Special methods
def __init__(self, id, association_type):
self.id = id
self.association_type = association_type
def __repr__(self):
return '' % (self.id, self.association_type)
class Note(DeclarativeBase):
__tablename__ = 'notes'
# Columns
id = Column(String(40), primary_key=True)
annotable_id = Column(String(40), ForeignKey('annotables.id'))
user_id = Column(Unicode(40), ForeignKey('users.user_id'))
text = Column(UnicodeText)
created = Column(DateTime, default=datetime.now)
sticky = Column(Boolean, default=False)
# Relations
user = relation('User', backref=backref('notes',
order_by=(desc('sticky'), desc('created'))))
annotable = relation(Annotable, backref=backref('notes',
order_by=(desc('sticky'), desc('created'))))
############################################################
# Migrate versioning
############################################################
class Migrate(DeclarativeBase):
__tablename__ = 'migrate_version'
# Columns
repository_id = Column(Unicode(250), primary_key=True)
repository_path = Column(UnicodeText)
version = Column(Integer)
############################################################
# Journal
############################################################
class Journal(DeclarativeBase):
__tablename__ = 'journal'
# Columns
id = Column(String(40), primary_key=True)
domain = Column(Unicode(24))
user_id = Column(Unicode(40), ForeignKey('users.user_id'))
text = Column(UnicodeText)
created = Column(DateTime, default=datetime.now)
# Relations
user = relation('User', backref=backref('journal',
order_by=desc('created')))
# Properties
@property
def strftime(self):
description=self.description,
location=self.location,
action=self.action,
frames=self.frames,
handle_in=self.handle_in,
handle_out=self.handle_out,
status=self.status,
categories=self.categories,
thumbnail=self.thumbnail,
has_preview=self.has_preview,
container_type=self.container.association_type,
)
add_container_props(Shot)
class Libgroup(DeclarativeBase):
"""Library group"""
__tablename__ = "libgroups"
__table_args__ = (UniqueConstraint('parent_id', 'name'),
ForeignKeyConstraint(['id'], ['asset_containers.id']),
ForeignKeyConstraint(['id'], ['taggables.id']),
ForeignKeyConstraint(['id'], ['annotables.id']),
{})
# Columns
id = Column(String(40), primary_key=True)
proj_id = Column(Unicode(10), ForeignKey('projects.id'))
parent_id = Column(String(40), ForeignKey('libgroups.id'))
name = Column(Unicode(40))
description = Column(UnicodeText)
# Relations
from sqlalchemy import Table, ForeignKey, Column, UniqueConstraint, DDL
from sqlalchemy import ForeignKeyConstraint, and_, desc
from sqlalchemy.types import Unicode, UnicodeText, Integer, DateTime, Boolean
from sqlalchemy.types import String
from sqlalchemy.orm import relation, synonym, backref
from tg import config
from spam.model import DeclarativeBase, metadata
from spam.model.auth import User
############################################################
# Migrate versioning
############################################################
class Migrate(DeclarativeBase):
__tablename__ = 'migrate_version'
# Columns
repository_id = Column(Unicode(250), primary_key=True)
repository_path = Column(UnicodeText)
version = Column(Integer)
############################################################
# Journal
############################################################
class Journal(DeclarativeBase):
__tablename__ = 'journal'
# Columns
id = Column(String(40), primary_key=True)