class PageData(DeclarativeBase): """Language specific Page data""" __metaclass__ = VersionedMeta __tablename__ = 'pages_data' __table_args__ = (UniqueConstraint('parent_id', 'language_id'), {}) # Columns id = Column(Integer, primary_key=True) parent_id = Column(Integer, ForeignKey('pages.id', onupdate='CASCADE', ondelete='CASCADE')) language_id = Column(Unicode(50), ForeignKey('languages.id', onupdate='CASCADE', ondelete='CASCADE')) _name = Column('name', Unicode(255)) created = Column(DateTime, default=datetime.now) modified = Column(TIMESTAMP, default=datetime.now) text = Column(UnicodeText) # Relations parent = relation('Page', backref=backref('data', order_by='PageData.created', collection_class=mapped_scalar('language_id'))) language = relation('Language', backref=backref('pages_data')) # Properties def _get_name(self): return self._name def _set_name(self, val): if self.parent.language_id == self.language_id: if self.parent.string_id == 'default': self.parent.article.id = make_id(val) else: self.parent.string_id = make_id(val) self._name = val name = synonym('_name', descriptor=property(_get_name, _set_name)) # Special methods def __init__(self, name, lang, text=None): self._name = name self.language_id = lang self.text = text def __repr__(self): return '<PageData: %s (%s) %s>' % (self.parent_id, self.language_id, self.name)
class Page(DeclarativeBase): """Article page""" __tablename__ = 'pages' __table_args__ = [UniqueConstraint(['string_id', 'article_id']), {} ] # Columns id = Column(Integer, primary_key=True) string_id = Column(Unicode(255)) article_id = Column(Unicode(255), ForeignKey('articles.id', onupdate='CASCADE', ondelete='CASCADE')) user_id = Column(Integer, ForeignKey('auth_users.user_id')) _created = Column('created', DateTime) # Relations article = relation('Article', backref=backref('pages', collection_class=mapped_scalar('string_id'))) user = relation('User', backref='pages') # Properties @synonym_for('_created') @property def created(self): return self._created @property def modified(self): return max([d.modified for d in self.data]) # Special methods def __init__(self, name, lang, user, text=None, is_default=False): self.string_id = is_default and u'default' or make_id(name) self.data.append(PageData(name, lang, text)) self.user = user now = datetime.now() self._created = now def __repr__(self): return '<Page: [%s] %s %s>' % (self.article_id, self.id, self.string_id)
class CategoryData(DeclarativeBase): """Language specific Category data""" __tablename__ = 'categories_data' __table_args__ = (UniqueConstraint('parent_id', 'language_id'), {}) # Columns id = Column(Integer, primary_key=True) parent_id = Column(Unicode(50), ForeignKey('categories.id', onupdate='CASCADE', ondelete='CASCADE')) language_id = Column(Unicode(50), ForeignKey('languages.id', onupdate='CASCADE', ondelete='CASCADE')) _name = Column('name', Unicode(255)) description = Column(Unicode(255)) # Relations parent = relation('Category', backref=backref('data', collection_class=mapped_scalar('language_id'))) language = relation('Language', backref=backref('categories_data')) # Properties def _get_name(self): return self._name def _set_name(self, val): if self.parent.language_id == self.language_id: self.parent.id = make_id(val) self._name = val name = synonym('_name', descriptor=property(_get_name, _set_name)) # Special methods def __init__(self, name, lang, description=None): self._name = name self.language_id = lang self.description = description def __repr__(self): return '<CategoryData: %s (%s) %s>' % (self.parent_id, self.language_id, self.name)