section.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # This program is free software; you can redistribute it and/or modify
  2. # it under the terms of the GNU General Public License as published by
  3. # the Free Software Foundation; either version 2 of the License, or
  4. # (at your option) any later version.
  5. # This program is distributed in the hope that it will be useful,
  6. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. # GNU General Public License for more details.
  9. # You should have received a copy of the GNU General Public License
  10. # along with this program; if not, write to the Free Software
  11. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  12. ################################################################################
  13. from sqlalchemy import Column, Integer, Text
  14. from sqlalchemy.schema import Index
  15. from .base import BaseTimestamp
  16. class Section(BaseTimestamp):
  17. __tablename__ = 'section'
  18. section_id = Column('id', Integer, primary_key=True)
  19. section = Column(Text, nullable=False)
  20. # indexes where not created as constraints, need to do as well
  21. __table_args__ = (Index('section_section_key', 'section', unique=True), )
  22. def __init__(self, section=None):
  23. self.section = section
  24. def __str__(self):
  25. return self.section
  26. def __repr__(self):
  27. return '<{} {}>'.format(
  28. self.__class__.__name__,
  29. self.section,
  30. )
  31. def __eq__(self, val):
  32. if isinstance(val, str):
  33. return (self.section == val)
  34. # This signals to use the normal comparison operator
  35. return NotImplemented
  36. def __ne__(self, val):
  37. if isinstance(val, str):
  38. return (self.section != val)
  39. # This signals to use the normal comparison operator
  40. return NotImplemented