section.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(
  35. "comparison with a `str` is deprecated",
  36. DeprecationWarning,
  37. stacklevel=2,
  38. )
  39. return self.section == val
  40. # This signals to use the normal comparison operator
  41. return NotImplemented
  42. def __ne__(self, val):
  43. if isinstance(val, str):
  44. warnings.warn(
  45. "comparison with a `str` is deprecated",
  46. DeprecationWarning,
  47. stacklevel=2,
  48. )
  49. return self.section != val
  50. # This signals to use the normal comparison operator
  51. return NotImplemented
  52. __hash__ = BaseTimestamp.__hash__