6
0

Label.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from contextlib import closing
  2. class Label:
  3. """
  4. database class for labels
  5. """
  6. def __init__(self, database, row):
  7. self.database = database
  8. self.identifier = row[0]
  9. self.project_id = row[1]
  10. self.created = row[2]
  11. self.reference = row[3]
  12. self.name = row[4]
  13. def project(self):
  14. """
  15. get the project this label is associated with
  16. :return: project
  17. """
  18. return self.database.project(self.project_id)
  19. def set_name(self, name: str):
  20. """
  21. set this labels name
  22. :param name: new name
  23. :return:
  24. """
  25. with closing(self.database.con.cursor()) as cursor:
  26. cursor.execute('UPDATE labels SET name = ? WHERE id = ?', (name, self.identifier))
  27. self.name = name
  28. def remove(self):
  29. """
  30. remove this label from the database
  31. :return:
  32. """
  33. with closing(self.database.con.cursor()) as cursor:
  34. cursor.execute('DELETE FROM labels WHERE id = ?', [self.identifier])