def _create_problem(self, title, pmodid):
        cur = self.db.cursor()
        sqlstr = ('INSERT INTO "PROBLEM" ("title", "pmodid", "accessid") '
                  'VALUES (%s, %s, %s) RETURNING "proid";')
        sqlarr = (title, pmodid, 0)
        cur.execute(sqlstr, sqlarr)

        proid = None
        for data in cur:
            proid = data[0]

        if proid == None:
            return None

        user_idenid = TOJAuth.get_current_iden()['idenid']
        with TOJAuth.change_current_iden(self._idendesc):
            accessid = TOJAuth.instance.create_access(user_idenid)

        sqlstr = ('UPDATE "PROBLEM" SET "accessid" = %s WHERE "proid" = %s;')
        sqlarr = (accessid, proid)
        cur.execute(sqlstr, sqlarr)

        TOJAuth.instance.set_access_list(accessid,
                                         TOJAuth.ROLEID_PROBLEM_ADMIN_GROUP,
                                         TOJAuth.ACCESS_ALL)

        pmodname = self.get_pmodname_by_pmodid(pmodid)
        pmod = mod.load_pmod(pmodname)

        pmod.create_problem_data(proid)

        return proid
    def _create_problem(self, title, pmodid):
        cur = self.db.cursor()
        sqlstr = ('INSERT INTO "PROBLEM" ("title", "pmodid", "accessid") '
                  'VALUES (%s, %s, %s) RETURNING "proid";')
        sqlarr = (title, pmodid, 0)
        cur.execute(sqlstr, sqlarr)

        proid = None
        for data in cur:
            proid = data[0]

        if proid == None:
            return None

        user_idenid = TOJAuth.get_current_iden()['idenid']
        with TOJAuth.change_current_iden(self._idendesc):
            accessid = TOJAuth.instance.create_access(user_idenid)

        sqlstr = ('UPDATE "PROBLEM" SET "accessid" = %s WHERE "proid" = %s;')
        sqlarr = (accessid, proid)
        cur.execute(sqlstr, sqlarr)

        TOJAuth.instance.set_access_list(
            accessid, TOJAuth.ROLEID_PROBLEM_ADMIN_GROUP, 
            TOJAuth.ACCESS_ALL
        )

        pmodname = self.get_pmodname_by_pmodid(pmodid)
        pmod = mod.load_pmod(pmodname)
        
        pmod.create_problem_data(proid)

        return proid
    def load_problem(self, proid):
        if proid in self._pmod_list:
            return self._pmod_list[proid]

        proinfo = self.get_problem_info_by_proid(proid)
        pmodname = proinfo['pmodname']
        pmod = mod.load_pmod(pmodname)
        self._pmod_list[proid] = pmod(self._idendesc, self.get_link, proid)

        return self._pmod_list[proid]
    def load_problem(self, proid):
        if proid in self._pmod_list:
            return self._pmod_list[proid]

        proinfo = self.get_problem_info_by_proid(proid)
        pmodname = proinfo['pmodname']
        pmod = mod.load_pmod(pmodname)
        self._pmod_list[proid] = pmod(self._idendesc, self.get_link, proid)

        return self._pmod_list[proid]
    def _delete_problem(self, proid):
        accessid = self.get_accessid_by_proid(proid)
        TOJAuth.check_access_func(accessid, TOJAuth.ACCESS_DELETE)

        proinfo = self.get_problem_info_by_proid(proid)
        pmodname = proinfo['pmodname']
        pmod = mod.load_pmod(pmodname)

        with TOJAuth.change_current_iden(self._idendesc):
            self.unload_problem(proid)

        pmod.delete_problem_data(proid)

        TOJAuth.instance.del_access(accessid)

        cur = self.db.cursor()
        sqlstr = ('DELETE FROM "PROBLEM" WHERE "proid" = %s;')
        sqlarr = (proid, )
        cur.execute(sqlstr, sqlarr)
    def _delete_problem(self, proid):
        accessid = self.get_accessid_by_proid(proid)
        TOJAuth.check_access_func(accessid, TOJAuth.ACCESS_DELETE)

        proinfo = self.get_problem_info_by_proid(proid)
        pmodname = proinfo['pmodname']
        pmod = mod.load_pmod(pmodname)

        with TOJAuth.change_current_iden(self._idendesc):
            self.unload_problem(proid)

        pmod.delete_problem_data(proid)
        
        TOJAuth.instance.del_access(accessid)
        
        cur = self.db.cursor()
        sqlstr = ('DELETE FROM "PROBLEM" WHERE "proid" = %s;')
        sqlarr = (proid, )
        cur.execute(sqlstr, sqlarr)