class SharedShareholder( PartyRelationship ): """Relation from a shared organization to a shareholder""" using_options( tablename = 'party_relationship_shares', inheritance = 'multi' ) established_from = ManyToOne( 'Organization', required = True, ondelete = 'cascade', onupdate = 'cascade' ) established_to = ManyToOne( 'Party', required = True, ondelete = 'cascade', onupdate = 'cascade' ) shares = Field( Integer() ) class Admin( PartyRelationship.Admin ): verbose_name = _('Shareholder structure') verbose_name_plural = _('Shareholder structures') list_display = ['established_from', 'established_to', 'shares',] list_search = ['established_from.full_name', 'established_to.full_name'] field_attributes = {'established_from':{'name':_('Organization')}, 'established_to':{'name':_('Shareholder')}} class ShareholderAdmin( Admin ): verbose_name = _('Shareholder') list_display = ['established_to', 'shares', 'from_date', 'thru_date'] form_display = ['established_to', 'shares', 'from_date', 'thru_date', 'comment'] form_size = (500, 300) class SharedAdmin( Admin ): verbose_name = _('Shares') verbose_name_plural = _('Shares') list_display = ['established_from', 'shares', 'from_date', 'thru_date'] form_display = ['established_from', 'shares', 'from_date', 'thru_date', 'comment'] form_size = (500, 300)
class Release(Entity): """Logically groups all files that belong to a certain release, such as parts of a movie, subtitles.""" identifier = Field(String(100), index=True) movie = ManyToOne('Movie') status = ManyToOne('Status') quality = ManyToOne('Quality') files = ManyToMany('File', cascade='all, delete-orphan', single_parent=True) info = OneToMany('ReleaseInfo', cascade='all, delete-orphan') def to_dict(self, deep={}, exclude=[]): orig_dict = super(Release, self).to_dict(deep=deep, exclude=exclude) new_info = {} for info in orig_dict.get('info', []): value = info['value'] try: value = int(info['value']) except: pass new_info[info['identifier']] = value orig_dict['info'] = new_info return orig_dict
class DirectedDirector( PartyRelationship ): """Relation from a directed organization to a director""" using_options( tablename = 'party_relationship_dir', inheritance = 'multi' ) established_from = ManyToOne( 'Organization', required = True, ondelete = 'cascade', onupdate = 'cascade' ) established_to = ManyToOne( 'Party', required = True, ondelete = 'cascade', onupdate = 'cascade' ) title = Field( Unicode( 256 ) ) represented_by = OneToMany( 'RepresentedRepresentor', inverse = 'established_to' ) class Admin( PartyRelationship.Admin ): verbose_name = _('Direction structure') verbose_name_plural = _('Direction structures') list_display = ['established_from', 'established_to', 'title', 'represented_by'] list_search = ['established_from.full_name', 'established_to.full_name'] field_attributes = {'established_from':{'name':_('Organization')}, 'established_to':{'name':_('Director')}} class DirectorAdmin( Admin ): verbose_name = _('Director') list_display = ['established_to', 'title', 'from_date', 'thru_date'] form_display = ['established_to', 'title', 'from_date', 'thru_date', 'represented_by', 'comment'] class DirectedAdmin( Admin ): verbose_name = _('Directed organization') list_display = ['established_from', 'title', 'from_date', 'thru_date'] form_display = ['established_from', 'title', 'from_date', 'thru_date', 'represented_by', 'comment']
class Release(Entity): """Logically groups all files that belong to a certain release, such as parts of a movie, subtitles.""" last_edit = Field(Integer, default = lambda: int(time.time()), index = True) identifier = Field(String(100), index = True) movie = ManyToOne('Movie') status = ManyToOne('Status') quality = ManyToOne('Quality') files = ManyToMany('File') info = OneToMany('ReleaseInfo', cascade = 'all, delete-orphan') def to_dict(self, deep = None, exclude = None): if not exclude: exclude = [] if not deep: deep = {} orig_dict = super(Release, self).to_dict(deep = deep, exclude = exclude) new_info = {} for info in orig_dict.get('info', []): value = info['value'] try: value = int(info['value']) except: pass new_info[info['identifier']] = value orig_dict['info'] = new_info return orig_dict
class Release(Entity): """Logically groups all files that belong to a certain release, such as parts of a movie, subtitles.""" movie = ManyToOne('Movie') status = ManyToOne('Status') quality = ManyToOne('Quality') files = ManyToMany('File') history = OneToMany('History')
class ProfileType(Entity): """""" using_options(order_by='order') order = Field(Integer) finish = Field(Boolean) wait_for = Field(Integer) quality = ManyToOne('Quality') profile = ManyToOne('Profile')
class ProfileType(Entity): """""" using_options(order_by = 'order') order = Field(Integer, default = 0, index = True) finish = Field(Boolean, default = True) wait_for = Field(Integer, default = 0) quality = ManyToOne('Quality') profile = ManyToOne('Profile')
class Movie(Entity): """Movie Resource a movie could have multiple releases The files belonging to the movie object are global for the whole movie such as trailers, nfo, thumbnails""" last_edit = Field(Integer) library = ManyToOne('Library') status = ManyToOne('Status') profile = ManyToOne('Profile') releases = OneToMany('Release') files = ManyToMany('File')
class Release(Entity): """Logically groups all files that belong to a certain release, such as parts of a movie, subtitles.""" identifier = Field(String(100)) movie = ManyToOne('Movie') status = ManyToOne('Status') quality = ManyToOne('Quality') files = ManyToMany('File') history = OneToMany('History') info = OneToMany('ReleaseInfo')
class RepresentedRepresentor( Entity ): """Relation from a representing party to the person representing the party""" using_options( tablename = 'party_representor' ) from_date = Field( Date(), default = datetime.date.today, required = True, index = True ) thru_date = Field( Date(), default = end_of_times, required = True, index = True ) comment = Field( camelot.types.RichText() ) established_from = ManyToOne( 'Person', required = True, ondelete = 'cascade', onupdate = 'cascade' ) established_to = ManyToOne( 'DirectedDirector', required = True, ondelete = 'cascade', onupdate = 'cascade' ) class Admin( EntityAdmin ): verbose_name = _('Represented by') list_display = ['established_from', 'from_date', 'thru_date'] form_display = ['established_from', 'from_date', 'thru_date', 'comment'] field_attributes = {'established_from':{'name':_( 'Name' )}}
class Movie(Entity): """Movie Resource a movie could have multiple releases The files belonging to the movie object are global for the whole movie such as trailers, nfo, thumbnails""" last_edit = Field(Integer, default = lambda: int(time.time()), index = True) type = 'movie' # Compat tv branch library = ManyToOne('Library', cascade = 'delete, delete-orphan', single_parent = True) status = ManyToOne('Status') profile = ManyToOne('Profile') category = ManyToOne('Category') releases = OneToMany('Release', cascade = 'all, delete-orphan') files = ManyToMany('File', cascade = 'all, delete-orphan', single_parent = True)
class PartyContactMechanism( Entity ): using_options( tablename = 'party_contact_mechanism' ) def __new__(cls, *args, **kwargs): party_contact_mechanism = super(PartyContactMechanism, cls).__new__(cls, *args, **kwargs) setattr(party_contact_mechanism, '_contact_mechanism_mechanism', None) return party_contact_mechanism party = ManyToOne( 'Party', required = True, ondelete = 'cascade', onupdate = 'cascade' ) contact_mechanism = ManyToOne( 'ContactMechanism', required = True, ondelete = 'cascade', onupdate = 'cascade' ) from_date = Field( Date(), default = datetime.date.today, required = True, index = True ) thru_date = Field( Date(), default = end_of_times, index = True ) comment = Field( Unicode( 256 ) ) def _get_contact_mechanism_mechanism(self): if self._contact_mechanism_mechanism != None: return self._contact_mechanism_mechanism return self.mechanism def _set_contact_mechanism_mechanism(self, mechanism): self._contact_mechanism_mechanism = mechanism if mechanism != None: if self.contact_mechanism: self.contact_mechanism.mechanism = mechanism else: self.contact_mechanism = ContactMechanism( mechanism=mechanism ) # # A property to get and set the mechanism attribute of the # related contact mechanism object # contact_mechanism_mechanism = property( _get_contact_mechanism_mechanism, _set_contact_mechanism_mechanism ) @ColumnProperty def mechanism( self ): return sql.select( [ContactMechanism.mechanism], whereclause = (ContactMechanism.id==self.contact_mechanism_id)) @ColumnProperty def party_name( self ): return sql.select( [Party.full_name], whereclause = (Party.id==self.party_id)) def __unicode__( self ): return unicode( self.contact_mechanism ) Admin = PartyContactMechanismAdmin
class ReleaseInfo(Entity): """Properties that can be bound to a file for off-line usage""" identifier = Field(String(50), index = True) value = Field(Unicode(255), nullable = False) release = ManyToOne('Release')
class RenameHistory(Entity): """Remembers from where to where files have been moved.""" old = Field(Unicode(255)) new = Field(Unicode(255)) file = ManyToOne('File')
class LibraryInfo(Entity): """""" identifier = Field(String(50)) value = Field(Unicode(255), nullable=False) library = ManyToOne('Library')
class ContactMechanism( Entity ): using_options( tablename = 'contact_mechanism' ) mechanism = Field( camelot.types.VirtualAddress( 256 ), required = True ) party_address = ManyToOne( 'PartyAddress', ondelete = 'set null', onupdate = 'cascade' ) party_contact_mechanisms = OneToMany( 'PartyContactMechanism' ) def __unicode__( self ): if self.mechanism: return u'%s : %s' % ( self.mechanism[0], self.mechanism[1] ) class Admin( EntityAdmin ): form_size = ( 700, 150 ) verbose_name = _('Contact mechanism') list_display = ['mechanism'] form_display = Form( ['mechanism', 'party_address'] ) field_attributes = {'mechanism':{'minimal_column_width':25}} def get_depending_objects(self, contact_mechanism ): for party_contact_mechanism in contact_mechanism.party_contact_mechanisms: if party_contact_mechanism not in PartyContactMechanism.query.session.new: party_contact_mechanism.expire( ['mechanism'] ) yield party_contact_mechanism party = party_contact_mechanism.party if party and party not in Party.query.session.new: party.expire(['email', 'phone']) yield party
class FileProperty(Entity): """Properties that can be bound to a file for off-line usage""" identifier = Field(String(20), index = True) value = Field(Unicode(255), nullable = False) file = ManyToOne('File')
class Language(Entity): """""" identifier = Field(String(20), index = True) label = Field(Unicode) titles = ManyToOne('LibraryTitle')
class Type3Status( Entity, ): """ Status Pattern .. attribute:: status_datetime For statuses that occur at a specific point in time .. attribute:: status_from_date For statuses that require a date range .. attribute:: from_date When a status was enacted or set """ using_options(tablename=t3_status_name.lower(), metadata=metadata, collection=collection) __metaclass__ = Type3StatusMeta status_datetime = Field(Date, required=False) status_from_date = Field(Date, required=False) status_thru_date = Field(Date, required=False) from_date = Field(Date, required=True, default=datetime.date.today) thru_date = Field(Date, required=True, default=end_of_times) status_for = ManyToOne( statusable_entity, #required = True, ondelete='cascade', onupdate='cascade') if not enumeration: classified_by = ManyToOne(t3_status_type_name, required=True, ondelete='cascade', onupdate='cascade') else: classified_by = Field(Enumeration(enumeration), required=True, index=True) class Admin(EntityAdmin): verbose_name = statusable_entity + ' Status' verbose_name_plural = statusable_entity + ' Statuses' list_display = [ 'status_from_date', 'status_thru_date', 'classified_by' ] verbose_name = statusable_entity + ' Status' if verbose_entity_name is not None: verbose_name = verbose_entity_name + ' Status' def __unicode__(self): return u'Status'
class LibraryTitle(Entity): """""" title = Field(Unicode) default = Field(Boolean) language = OneToMany('Language') libraries = ManyToOne('Library')
class History(Entity): """History of actions that are connected to a certain release, such as, renamed to, downloaded, deleted, download subtitles etc""" added = Field(Integer) message = Field(UnicodeText()) type = Field(Unicode(50)) release = ManyToOne('Release')
class Media(Entity): """Media Resource could have multiple releases The files belonging to the media object are global for the whole media such as trailers, nfo, thumbnails""" type = Field(String(10), default="movie", index=True) last_edit = Field(Integer, default=lambda: int(time.time()), index=True) library = ManyToOne('Library', cascade='delete, delete-orphan', single_parent=True) status = ManyToOne('Status') profile = ManyToOne('Profile') category = ManyToOne('Category') releases = OneToMany('Release', cascade='all, delete-orphan') files = ManyToMany('File', cascade='all, delete-orphan', single_parent=True)
class LibraryTitle(Entity): """""" using_options(order_by='-default') title = Field(Unicode) default = Field(Boolean) language = OneToMany('Language') libraries = ManyToOne('Library')
class SupplierCustomer( PartyRelationship ): """Relation from supplier to customer""" using_options( tablename = 'party_relationship_suppl', inheritance = 'multi' ) established_from = ManyToOne( 'Party', required = True, ondelete = 'cascade', onupdate = 'cascade' ) established_to = ManyToOne( 'Party', required = True, ondelete = 'cascade', onupdate = 'cascade' ) class Admin( PartyRelationship.Admin ): verbose_name = _('Supplier - Customer') list_display = ['established_from', 'established_to', 'from_date', 'thru_date'] class CustomerAdmin( EntityAdmin ): verbose_name = _('Customer') list_display = ['established_to', ] form_display = ['established_to', 'comment', 'from_date', 'thru_date'] field_attributes = {'established_to':{'name':_( 'Name' )}} class SupplierAdmin( EntityAdmin ): verbose_name = _('Supplier') list_display = ['established_from', ] form_display = ['established_from', 'comment', 'from_date', 'thru_date'] field_attributes = {'established_from':{'name':_( 'Name' )}}
class File(Entity): """File that belongs to a release.""" path = Field(Unicode(255), nullable=False, unique=True) part = Field(Integer, default=1) type = ManyToOne('FileType') properties = OneToMany('FileProperty') history = OneToMany('RenameHistory') movie = ManyToMany('Movie') release = ManyToMany('Release') library = ManyToMany('Library')
class EmployerEmployee( PartyRelationship ): """Relation from employer to employee""" using_options( tablename = 'party_relationship_empl', inheritance = 'multi' ) established_from = ManyToOne( 'Organization', required = True, ondelete = 'cascade', onupdate = 'cascade' ) # the employer established_to = ManyToOne( 'Person', required = True, ondelete = 'cascade', onupdate = 'cascade' ) # the employee @ColumnProperty def first_name( self ): return sql.select( [Person.first_name], Person.party_id == self.established_to_party_id ) @ColumnProperty def last_name( self ): return sql.select( [Person.last_name], Person.party_id == self.established_to_party_id ) @ColumnProperty def social_security_number( self ): return sql.select( [Person.social_security_number], Person.party_id == self.established_to_party_id ) def __unicode__( self ): return u'%s %s %s' % ( unicode( self.established_to ), _('Employed by'),unicode( self.established_from ) ) class Admin( PartyRelationship.Admin ): verbose_name = _('Employment relation') verbose_name_plural = _('Employment relations') list_filter = ['established_from.name'] list_search = ['established_from.name', 'established_to.first_name', 'established_to.last_name'] class EmployeeAdmin( EntityAdmin ): verbose_name = _('Employee') list_display = ['established_to', 'from_date', 'thru_date'] form_display = ['established_to', 'comment', 'from_date', 'thru_date'] field_attributes = {'established_to':{'name':_( 'Name' )}} class EmployerAdmin( EntityAdmin ): verbose_name = _('Employer') list_display = ['established_from', 'from_date', 'thru_date'] form_display = ['established_from', 'comment', 'from_date', 'thru_date'] field_attributes = {'established_from':{'name':_( 'Name' )}}
class Library(Entity): """""" year = Field(Integer) identifier = Field(String(20), index = True) plot = Field(UnicodeText) tagline = Field(UnicodeText(255)) info = Field(JsonType) status = ManyToOne('Status') movies = OneToMany('Movie', cascade = 'all, delete-orphan') titles = OneToMany('LibraryTitle', cascade = 'all, delete-orphan') files = ManyToMany('File', cascade = 'all, delete-orphan', single_parent = True)
class Library(Entity): """""" year = Field(Integer) identifier = Field(String(20)) rating = Field(Float) plot = Field(UnicodeText) tagline = Field(UnicodeText(255)) status = ManyToOne('Status') movie = OneToMany('Movie') titles = OneToMany('LibraryTitle') files = ManyToMany('File')
class Library(Entity): """""" using_options(inheritance='multi') # For Movies, CPS uses three: omdbapi (no prio !?), tmdb (prio 2) and couchpotatoapi (prio 1) type = Field(String(10), default="movie", index=True) primary_provider = Field(String(10), default="imdb", index=True) year = Field(Integer) identifier = Field(String(40), index=True) plot = Field(UnicodeText) tagline = Field(UnicodeText(255)) info = Field(JsonType) status = ManyToOne('Status') media = OneToMany('Media', cascade='all, delete-orphan') titles = OneToMany('LibraryTitle', cascade='all, delete-orphan') files = ManyToMany('File', cascade='all, delete-orphan', single_parent=True) parent = ManyToOne('Library') children = OneToMany('Library')
class Library(Entity): """""" year = Field(Integer) identifier = Field(String(20)) rating = Field(Float) plot = Field(UnicodeText) tagline = Field(UnicodeText(255)) status = ManyToOne('Status') movies = OneToMany('Movie') titles = OneToMany('LibraryTitle') files = ManyToMany('File') info = OneToMany('LibraryInfo') def title(self): return self.titles[0]['title']