section.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. import warnings
  14. from sqlalchemy import Column, Integer, Text
  15. from sqlalchemy.schema import Index
  16. from .base import BaseTimestamp
  17. class Section(BaseTimestamp):
  18. __tablename__ = 'section'
  19. section_id = Column('id', Integer, primary_key=True)
  20. section = Column(Text, nullable=False)
  21. # indexes where not created as constraints, need to do as well
  22. __table_args__ = (Index('section_section_key', 'section', unique=True), )
  23. def __init__(self, section=None):
  24. self.section = section
  25. def __str__(self):
  26. return self.section
  27. def __repr__(self):
  28. return '<{} {}>'.format(
  29. self.__class__.__name__,
  30. self.section,
  31. )
  32. def __eq__(self, val):
  33. if isinstance(val, str):
  34. warnings.warn("comparison with a `str` is deprecated", DeprecationWarning, stacklevel=2)
  35. return (self.section == val)
  36. # This signals to use the normal comparison operator
  37. return NotImplemented
  38. def __ne__(self, val):
  39. if isinstance(val, str):
  40. warnings.warn("comparison with a `str` is deprecated", DeprecationWarning, stacklevel=2)
  41. return (self.section != val)
  42. # This signals to use the normal comparison operator
  43. return NotImplemented
  44. __hash__ = BaseTimestamp.__hash__