예제 #1
0
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']
예제 #2
0
class Notification(Entity):
    using_options(order_by = 'added')

    added = Field(Integer, default = lambda: int(time.time()))
    read = Field(Boolean, default = False)
    message = Field(Unicode(255))
    data = Field(JsonType)
예제 #3
0
class Organization( Party ):
    """An organization represents any internal or external organization.  Organizations can include
    businesses and groups of individuals"""
    using_options( tablename = 'organization', inheritance = 'multi' )
    name = Field( Unicode( 50 ), required = True, index = True )
    logo = Field( camelot.types.Image( upload_to = 'organization-logo' ), deferred = True )
    tax_id = Field( Unicode( 20 ) )
    directors = OneToMany( 'DirectedDirector', inverse = 'established_from', cascade='all, delete, delete-orphan' )
    employees = OneToMany( 'EmployerEmployee', inverse = 'established_from', cascade='all, delete, delete-orphan' )
    suppliers = OneToMany( 'SupplierCustomer', inverse = 'established_to', cascade='all, delete, delete-orphan' )
    customers = OneToMany( 'SupplierCustomer', inverse = 'established_from', cascade='all, delete, delete-orphan' )
    shareholders = OneToMany( 'SharedShareholder', inverse = 'established_from', cascade='all, delete, delete-orphan' )

    def __unicode__( self ):
        return self.name or ''

    @property
    def number_of_shares_issued( self ):
        return sum( ( shareholder.shares for shareholder in self.shareholders ), 0 )

    class Admin( Party.Admin ):
        verbose_name = _( 'Organization' )
        verbose_name_plural = _( 'Organizations' )
        list_display = ['name', 'tax_id', 'contact_mechanisms_email', 'contact_mechanisms_phone']
        form_display = TabForm( [( _('Basic'), Form( ['name', 'tax_id', 'addresses', 'contact_mechanisms'] ) ),
                                ( _('Employment'), Form( ['employees'] ) ),
                                ( _('Customers'), Form( ['customers'] ) ),
                                ( _('Suppliers'), Form( ['suppliers'] ) ),
                                ( _('Corporate'), Form( ['directors', 'shareholders', 'shares'] ) ),
                                ( _('Branding'), Form( ['logo'] ) ),
                                ( _('Status'), Form( ['status'] ) ),
                                ] )
예제 #4
0
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
예제 #5
0
class GeographicalData(Entity):
    id = Field(Integer,primary_key=True)
    google_place_id = Field(String(255))
    lat = Field(String(20))
    lon = Field(String(20))
    using_options(tablename="GeoData")
    using_table_options(mysql_engine="InnoDB")
예제 #6
0
class SeasonLibrary(Library, DictMixin):
    using_options(inheritance='multi')

    season_number = Field(Integer, index=True)
    last_updated = Field(Integer, index=True)

    def getEpisodes(self):
        data = OrderedDict()
        for c in self.children:
            data[c.episode_number] = c
        return data

    # Read access episode by number: library[1][4] for season 1, episode 4
    data = {}

    def __getitem__(self, key):
        if not self.data:
            self.setData()
        if key in self.data:
            return self.data[key]
        if hasattr(self.__class__, "__missing__"):
            return self.__class__.__missing__(self, key)
        raise KeyError(key)

    def get(self, key, failobj=None):
        if key not in self:
            return failobj
        return self[key]

    def keys(self):
        return self.data.keys()

    def setData(self):
        for c in self.children:
            self.data[c.episode_number] = c
예제 #7
0
class Comment(Entity):
    id = Field(Integer,primary_key=True)
    content = Field(Text)
    user_id = Field(Integer)
    post_id = Field(Integer)
    using_options(tablename="Comment")
    using_table_options(mysql_engine="InnoDB")
예제 #8
0
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)
예제 #9
0
class Translation(Entity):
    using_options(tablename='translation')
    language = Field(camelot.types.Language, index=True)
    source = Field(Unicode(500), index=True)
    # value needs to be indexed as well, because when starting up we
    # want to load only the translations that have a value specified
    value = Field(Unicode(500), index=True)
    cid = Field(INT(), default=0, index=True)
    uid = Field(INT(), default=0, index=True)

    # cache, to prevent too much of the same sql queries
    _cache = dict()

    class Admin(EntityAdmin):
        verbose_name_plural = _('Translations')
        form_size = (700, 150)
        section = 'configuration'
        list_display = ['source', 'language', 'value', 'uid']
        list_filter = ['language']
        list_actions = [ExportAsPO()]
        field_attributes = {'language': {'default': default_language}}

    @classmethod
    def translate(cls, source, language):
        """Translate source to language, return None if no translation is found"""
        if source:
            key = (source, language)
            if key in cls._cache:
                return cls._cache[key]
            translation = cls.query.filter_by(
                source=unicode(source),
                language=language).filter(Translation.uid != 0).first()
            if translation:
                cls._cache[key] = translation.value
                return translation.value
            return None
        return ''

    @classmethod
    def translate_or_register(cls, source, language):
        """Translate source to language, if no translation is found, register the
        source as to be translated and return the source"""
        if source:
            source = unicode(source)
            translation = cls.translate(source, language)
            if not translation:
                if not cls.query.filter_by(source=source,
                                           language=language).first():
                    if (source, language) not in cls._cache:
                        from elixir import session
                        registered_translation = Translation(source=source,
                                                             language=language)
                        cls._cache[(source, language)] = source
                        session.flush([registered_translation])
                        logger.debug('registed %s with id %s' %
                                     (source, registered_translation.id))
                return source
            return translation
        return ''
예제 #10
0
class ForgotPassword(Entity):
    id = Field(Integer,primary_key=True)
    uuid = Field(String(255))
    timestamp = Field(DateTime)
    user_id = Field(Integer)
    used = Field(Boolean)
    using_options(tablename="ForgotPassword")
    using_table_options(mysql_engine="InnoDB")        
예제 #11
0
class Synchronized( Entity ):
    using_options( tablename = 'synchronized' )
    database = Field( Unicode( 30 ), index = True )
    tablename = Field( Unicode( 30 ), index = True )
    primary_key = Field( Integer(), index = True )
    last_update = Field( DateTime(), index = True,
                          default = datetime.datetime.now,
                           onupdate = datetime.datetime.now )
예제 #12
0
class AuthenticationMechanism( Entity ):
    using_options( tablename = 'authentication_mechanism' )
    last_login = Field( DateTime() )
    is_active = Field( Boolean, default = True, index = True )

    class Admin( EntityAdmin ):
        verbose_name = _('Authentication mechanism')
        list_display = ['last_login', 'is_active']
예제 #13
0
class PartyAddressRoleType( Entity ):
    using_options( tablename = 'party_address_role_type' )
    code = Field( Unicode( 10 ) )
    description = Field( Unicode( 40 ) )

    class Admin( EntityAdmin ):
        verbose_name = _('Address role type')
        list_display = ['code', 'description']
예제 #14
0
class LibraryTitle(Entity):
    """"""
    using_options(order_by='-default')

    title = Field(Unicode)
    default = Field(Boolean)

    language = OneToMany('Language')
    libraries = ManyToOne('Library')
예제 #15
0
class Message(Entity):
    id = Field(Integer,primary_key=True)
    title = Field(String(255))
    content = Field(Text)
    timestamp = Field(DateTime)
    from_user_id = Field(Integer)
    to_user_id = Field(Integer)
    using_options(tablename="Message")
    using_table_options(mysql_engine="InnoDB")        
예제 #16
0
class ShowLibrary(Library, DictMixin):
    using_options(inheritance='multi')

    last_updated = Field(Integer, index=True)
    show_status = Field(String(10), index=True)

    # XXX: Maybe we should convert this to seconds?
    # airs_time u'21:00'
    airs_time = Field(Unicode, index=True)

    # airs_dayofweek = Field(Integer, index = True)
    #    u'Monday':    1,
    #    u'Tuesday':   2,
    #    u'Wednesday': 4,
    #    u'Thursday':  8,
    #    u'Friday':    16,
    #    u'Saturday':  32,
    #    u'Sunday':    64,
    #    u'Daily':     127,
    airs_dayofweek = Field(Integer, index=True)

    def getSeasons(self):
        data = OrderedDict()
        for c in self.children:
            data[c.season_number] = c
        return data

    def getEpisodes(self, season_number):
        data = OrderedDict()
        for c in self.children[season_number].children:
            data[c.episode_number] = c
        return data

    # Read access to season by number: library[1] for season 1
    data = {}

    def __getitem__(self, key):
        if not self.data:
            self.setData()
        if key in self.data:
            return self.data[key]
        if hasattr(self.__class__, "__missing__"):
            return self.__class__.__missing__(self, key)
        raise KeyError(key)

    def get(self, key, failobj=None):
        if key not in self:
            return failobj
        return self[key]

    def keys(self):
        return self.data.keys()

    def setData(self):
        for c in self.children:
            self.data[c.season_number] = c
예제 #17
0
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')
예제 #18
0
class ProfileType(Entity):
    """"""
    using_options(order_by='order')

    order = Field(Integer)
    finish = Field(Boolean)
    wait_for = Field(Integer)

    quality = ManyToOne('Quality')
    profile = ManyToOne('Profile')
예제 #19
0
class Admin(Entity):
    id = Field(Integer, primary_key=True)
    first_name = Field(String(20))
    last_name = Field(String(20))
    password = Field(String(255))
    email = Field(String(50))
    phone_number = Field(String(20))
    role = Field(Integer)
    using_options(tablename="admin")
    using_table_options(mysql_engine="InnoDB")
예제 #20
0
class Create( Memento ):
    """Marks the creation of an object"""
    using_options( inheritance = 'multi', tablename = 'memento_create', )

    @property
    def description( self ):
        return 'Create'

    class Admin( Memento.Admin ):
        verbose_name = _('Create')
        verbose_name_plural = _('Creates')
예제 #21
0
class User(Entity):
    id = Field(Integer,primary_key=True)
    first_name = Field(String(255))
    last_name = Field(String(255))
    password = Field(String(255))
    email = Field(String(255))
    phone_number = Field(String(10))
    community_id = Field(Integer)
    verified =  Field(Boolean, default='0',server_default='0')
    using_options(tablename="User")
    using_table_options(mysql_engine="InnoDB")
예제 #22
0
class PartyRelationship( Entity ):
    using_options( tablename = 'party_relationship' )
    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() )
    is_synchronized( 'synchronized', lazy = True )

    class Admin( EntityAdmin ):
        verbose_name = _('Relationship')
        verbose_name_plural = _('Relationships')
        list_display = ['established_from', 'established_to', 'from_date', 'thru_date']
예제 #23
0
class Profile(Entity):
    """"""
    using_options(order_by='order')

    label = Field(Unicode(50))
    order = Field(Integer)
    core = Field(Boolean)
    hide = Field(Boolean)

    movie = OneToMany('Movie')
    types = OneToMany('ProfileType', cascade='all, delete-orphan')
예제 #24
0
class Category(Entity):
    """"""
    using_options(order_by = 'order')

    label = Field(Unicode(50))
    order = Field(Integer, default = 0, index = True)
    required = Field(Unicode(255))
    preferred = Field(Unicode(255))
    ignored = Field(Unicode(255))
    destination = Field(Unicode(255))

    movie = OneToMany('Movie')
예제 #25
0
class InterPost(Entity):
    id = Field(Integer,primary_key=True)
    title = Field(String(255))
    content = Field(Text)
    timestamp = Field(DateTime)
    user_id = Field(Integer)
    community_id = Field(Integer)
    category = Field(String(20))
    admin_approved = Field(Boolean,default='0',server_default='0')
    file_id =  Field(Integer)
    using_options(tablename="InterPost")
    using_table_options(mysql_engine="InnoDB")
예제 #26
0
class IntraPost(Entity):
    id = Field(Integer,primary_key=True)
    title = Field(String(255))
    content = Field(Text)
    category = Field(String(20))
    timestamp = Field(DateTime)
    user_id = Field(Integer)
    community_id = Field(Integer)
    post_type = Field(Integer)
    file_id = Field(Integer)
    using_options(tablename="IntraPost")
    using_table_options(mysql_engine="InnoDB")
예제 #27
0
class GeographicBoundary( Entity ):
    """The base class for Country and City"""
    using_options( tablename = 'geographic_boundary' )
    code = Field( Unicode( 10 ) )
    name = Field( Unicode( 40 ), required = True )

    @ColumnProperty
    def full_name( self ):
        return self.code + ' ' + self.name

    def __unicode__( self ):
        return u'%s %s' % ( self.code, self.name )
예제 #28
0
class BeforeDelete( Memento ):
    """The state of the object before it is deleted"""
    using_options( inheritance = 'multi', tablename = 'memento_delete', )
    previous_attributes = Field( PickleType() )

    @property
    def description( self ):
        return 'Delete'

    class Admin( Memento.Admin ):
        verbose_name = _('Delete')
        verbose_name_plural = _('Deletes')
예제 #29
0
class Person( Party ):
    """Person represents natural persons
    """
    using_options( tablename = 'person', inheritance = 'multi' )
    first_name = Field( Unicode( 40 ), required = True )
    last_name = Field( Unicode( 40 ), required = True )
# end short person definition
    middle_name = Field( Unicode( 40 ) )
    personal_title = Field( Unicode( 10 ) )
    suffix = Field( Unicode( 3 ) )
    sex = Field( Unicode( 1 ), default = u'M' )
    birthdate = Field( Date() )
    martial_status = Field( Unicode( 1 ) )
    social_security_number = Field( Unicode( 12 ) )
    passport_number = Field( Unicode( 20 ) )
    passport_expiry_date = Field( Date() )
    is_staff = Field( Boolean, default = False, index = True )
    is_superuser = Field( Boolean, default = False, index = True )
    picture = Field( camelot.types.Image( upload_to = 'person-pictures' ), deferred = True )
    comment = Field( camelot.types.RichText() )
    employers = OneToMany( 'EmployerEmployee', inverse = 'established_to', cascade='all, delete, delete-orphan' )

    @property
    def note(self):
        for person in self.__class__.query.filter_by(first_name=self.first_name, last_name=self.last_name):
            if person != self:
                return _('A person with the same name allready exists')

    @property
    def name( self ):
        # we don't use full name in here, because for new objects, full name will be None, since
        # it needs to be fetched from the db first
        return u'%s %s' % ( self.first_name, self.last_name )

    def __unicode__( self ):
        return self.name or ''

    class Admin( Party.Admin ):
        verbose_name = _( 'Person' )
        verbose_name_plural = _( 'Persons' )
        list_display = ['first_name', 'last_name', 'contact_mechanisms_email', 'contact_mechanisms_phone']
        form_display = TabForm( [( _('Basic'), Form( [HBoxForm( [Form( [WidgetOnlyForm('note'), 'first_name', 'last_name', 'sex'] ),
                                                          Form( ['picture', ] ),
                                                         ] ),
                                                         'contact_mechanisms', 'comment', ], scrollbars = False ) ),
                                ( _('Official'), Form( ['birthdate', 'social_security_number', 'passport_number',
                                                        'passport_expiry_date', 'addresses', ], scrollbars = False ) ),
                                ( _('Work'), Form( ['employers', 'directed_organizations', 'shares'], scrollbars = False ) ),
                                ( _('Status'), Form( ['status'] ) ),
                                ] )
        field_attributes = dict( Party.Admin.field_attributes )
        field_attributes['note'] = {'delegate':delegates.NoteDelegate}
예제 #30
0
class Quality(Entity):
    """Quality name of a release, DVD, 720p, DVD-Rip etc"""
    using_options(order_by = 'order')

    identifier = Field(String(20), unique = True)
    label = Field(Unicode(20))
    order = Field(Integer, default = 0, index = True)

    size_min = Field(Integer)
    size_max = Field(Integer)

    releases = OneToMany('Release')
    profile_types = OneToMany('ProfileType')