from contextlib import closing class Label: """ database class for labels """ def __init__(self, database, row): self.database = database self.identifier = row[0] self.project_id = row[1] self.created = row[2] self.reference = row[3] self.name = row[4] def project(self): """ get the project this label is associated with :return: project """ return self.database.project(self.project_id) def set_name(self, name: str): """ set this labels name :param name: new name :return: """ with closing(self.database.con.cursor()) as cursor: cursor.execute('UPDATE labels SET name = ? WHERE id = ?', (name, self.identifier)) self.name = name def remove(self): """ remove this label from the database :return: """ with closing(self.database.con.cursor()) as cursor: cursor.execute('DELETE FROM labels WHERE id = ?', [self.identifier])