def __init__()

in api/plugins/tasks.py [0:0]


    def __init__(self, session, catid = None):
        """ Loads a category from the registry or inits a new one """
        self._data = {}
        self.session = session
        self.conn = session.DB.sqlite.open('nodecats.db')
        
        # category variables
        self.id = None
        self.name = None
        self.description = None
        self.settings = {}
        self.tasks = []
        
        # Load existing category?
        if catid:
            doc = None
            nc = self.conn.cursor()
            # Load by Cat ID?
            if re.match(r"^[0-9]+$", str(catid)):
                self.id = int(catid)
                nc.execute("SELECT * FROM `nodecats` WHERE `id` = ? LIMIT 1", (catid,))
                doc = nc.fetchone()
            if doc:
                self.id = doc['id']
                self.name = doc['name']
                self.description = doc['description']
                self.settings = json.loads(doc['settings'])
                
                # Load tasks in category
                taskcon = session.DB.sqlite.open('nodetasks.db')
                cur = taskcon.cursor()
                cur.execute("SELECT * FROM `nodetasks` WHERE `category` = ?", (self.id, ))
                for row in cur.fetchall():
                    t = task(session, taskrow = row)
                    self.tasks.append(t)
                taskcon.close()
            else:
                raise Exception("No such category found in registry")