web.main.model

Package web :: Package main :: Module model |
[hide private]
[frames] | no frames]

# Source Code for Module web.main.model

     1  from db import Base
     2  from sqlalchemy import Integer, Unicode, ForeignKey, Column, Boolean
     3  from sqlalchemy.orm import relation, backref
     4
     5
     6  metadata = Base.metadata
     7
     8 -class OrganizativeUnit(Base):
     9      __tablename__ = 'organizative_unit'
    10
    11      id = Column(Integer, primary_key=True)
    12      name = Column(Unicode(120), unique=True)
    13      parent_id = Column(Integer, ForeignKey('organizative_unit.id'))
    14      description = Column(Unicode(512))
    15
    16      childs = relation("OrganizativeUnit")
    17      parent = relation("OrganizativeUnit", remote_side=id,
    18               primaryjoin="OrganizativeUnit.id==OrganizativeUnit.parent_id")
    19
    20 -    def __str__(self):
    21          return self.name
    22
    23      @classmethod
    24 -    def fields(self):
    25          return ('name', 'parent', 'description')
    26
    27 -    def __repr__(self):
    28          return "<OrganizativeUnit %s>" % (self.name)
    29
    30      #def get_menu(self):
    31      #    if menu:
    32      #        return menu
    33      #    elif self.parent:
    34      #        return self.parent.get_menu()
    35      #    else:
    36      #        return None
    37
    38 -class Computer(Base):
    39      __tablename__ = 'computer'
    40
    41      id = Column(Integer, primary_key=True)
    42      name = Column(Unicode(120), unique=True)
    43      mac = Column(Unicode(12), unique=True)
    44      ip = Column(Unicode(32), unique=True)
    45      repository = Column(Boolean)
    46
    47      ou_id = Column(Integer, ForeignKey('organizative_unit.id'))
    48      ou = relation(OrganizativeUnit, backref=backref('computers',
    49          cascade='all',
    50          passive_deletes=False))
    51
    52      description = Column(Unicode(512))
    53
    54      @classmethod
    55 -    def fields(self):
    56          return ('name', 'mac', 'ip', 'ou', 'description')
    57
    58 -    def __str__(self):
    59          return self.name
    60
    61 -    def __repr__(self):
    62          type_computer = 'Computer' if not self.repository else 'Repository'
    63          return "<%s %s %s %s>" % (type_computer, self.name, self.mac, self.ip)
    64
    65      #def get_menu(self):
    66      #    if menu:
    67      #        return menu
    68      #    else:
    69      #        return self.parent.get_menu()
    70