summaryrefslogblamecommitdiffstats
path: root/item.py
blob: c39bd568123007d975dcb3178f9b66f78454aa92 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                       
           
                               
 


                     
                                                                                                                                    

                                
                         

                                  
                                      
                                          
                                      
                                  
                          
                         
                       
            


                                     






                                      
                         


                         




                                    







                            


                               
 


                             


                           


                       







                                                                 






                                                                         
# -*- coding: utf-8 -*-
import time
from priority import Priorities

class item:
    readOnly = ['id']
    
    def __init__(self, title=None, created=None, priority=None, description=None, completed=None, removed=None, due=None, row=None):
        self.__dict__['id'] = -1

        if title != None:
            self.title = title
            self.created = created
            self.setPriority(priority)
            self.description = description
            self.completed = completed
            self.removed = removed
            self.due = due
        elif row != None:
            id = row[0]
            
            row.__delitem__(0)
            apply(self.__init__, row)
            self.__dict__['id'] = id
        else:
            self.title = ''
            self.created = time.time()
            self.priority = ''
            self.description = ''
            self.completed = 0
            self.removed = 0
            self.due = -1

    def setId(self, id):
        if self.id == -1:
            self.__dict__['id'] = id

    def getId(self):
        return self.id
    
    def getTitle(self):
        return self.title

    def getCreatedAt(self):
        return self.created

    def getPriority(self):
        return self.priority
    
    def getDescription(self):
        return self.description

    def getCompleted(self):
        return self.completed

    def getRemoved(self):
        return self.removed

    def getDue(self):
        return self.due

    def setPriority(self, id=None, name=None):
        if id is not None:
            self.priority = Priorities().getPriority(id = id)
        elif name is not None:
            self.priority = Priorities().getPriority(name = name)
        else:
            self.priority = None
                
    def __setattr__(self, name, value):
        if name not in item.readOnly:
            if name not in self.__dict__ or self.__dict__[name] != value:
                self.__dict__[name] = value
            
                if 'observer' in self.__dict__:
                    self.observer.notifyChange(self)