• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python database.Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skarphedcore.database.Database的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: assign_to

    def assign_to(self,user):
        """
        Assigns this role to a user
        """
        session_user = Session.get_current_session_user()

        db = Database()
        
        #check if sessionuser has role
        
        has_role = session_user.has_role(self)

        stmnt = "SELECT COUNT(URI_RIG_ID) AS CNT FROM USERRIGHTS WHERE URI_RIG_ID IN \
            (SELECT RRI_RIG_ID FROM ROLERIGHTS WHERE RRI_ROL_ID = ? ) ;"
        cur = db.query(stmnt,(self._id,))
        res = cur.fetchone()[0]

        has_all_permissions_of_role = res == len(self.get_permissions())

        if not has_role and not has_all_permissions_of_role:
            raise PermissionException(PermissionException.get_msg(7))

        for role in user.get_grantable_roles():
            if role["name"] == self._name:
                stmnt = "UPDATE OR INSERT INTO USERROLES (URO_USR_ID, URO_ROL_ID) \
                    VALUES (?,?) MATCHING (URO_USR_ID, URO_ROL_ID) ;";
                db.query(stmnt, (user.get_id(),self._id),commit=True)
                PokeManager.add_activity(ActivityType.USER)
                return
        raise PermissionException(PermissionException.get_msg(8))
开发者ID:skarphed,项目名称:skarphed,代码行数:30,代码来源:permissions.py


示例2: generate

    def generate(cls):
        """
        Generates an Activity Report. This report contains,
        how many activities have happened since the last poke
        further it contains the activity types.
        """
        session  = Session.get_current_session()

        db = Database()
        stmnt = "SELECT ATV_TYPE, MAX(ATV_ID) AS LATEST_ID, COUNT(ATV_ID) AS AMOUNT FROM ACTIVITIES WHERE ATV_SES_ID != ? OR ATV_SES_ID IS NULL AND ATV_ID >= \
                COALESCE((SELECT SPO_ATV_ID FROM SESSIONPOKE WHERE SPO_SES_ID = ?),0) GROUP BY ATV_TYPE;"
        cur = db.query(stmnt, (session.get_id(), session.get_id()))

        activity_report = ActivityReport()

        res = cur.fetchallmap()
        for row in res:
            activity = Activity()
            activity.set_id(row["LATEST_ID"])
            activity.set_activity_type(row["ATV_TYPE"])

            activity_report._activities.append(activity)

            if activity_report._latest_id < row["LATEST_ID"]:
                activity_report._latest_id = row["LATEST_ID"]

            activity_report._amount += row["AMOUNT"]
        
        return activity_report
开发者ID:skarphed,项目名称:skarphed,代码行数:29,代码来源:poke.py


示例3: create_role

    def create_role(cls, data=None):
        if data is None:
            raise PermissionException(PermissionException.get_msg(10))
        if data["name"] is None:
            raise PermissionException(PermissionException.get_msg(11))

        db = Database()

        stmnt = "SELECT ROL_ID FROM ROLES WHERE ROL_NAME = ? ;"
        cur = db.query(stmnt,(data["name"],))
        res = cur.fetchonemap()
        if res is not None:
            raise PermissionException(PermissionException.get_msg(13, data["name"]))
        
        role_id = db.get_seq_next("ROL_GEN")
        role = Role()
        role.set_id(role_id)
        role.set_name(data["name"])
        role.store()

        if data.has_key("rights"):
            for permission in data["rights"]:
                if permission["granted"]:
                    role.add_permission(permission["name"])
                else:
                    role.remove_permission(permission["name"])
            role.store()

        return role
开发者ID:skarphed,项目名称:skarphed,代码行数:29,代码来源:permissions.py


示例4: get_menu_item_by_id

    def get_menu_item_by_id(cls, menu_item_id):
        """
        This function looks for a MenuItem with the given ID in the database
        and returns it
        If the MenuItem does not exist this returns null
        """
        db = Database()
        stmnt = "SELECT MNI_NAME, MNI_MNU_ID, MNI_MNI_ID, MNI_ATL_ID, MNI_ORDER \
                 FROM MENUITEMS WHERE MNI_ID = ? ;"
        cur = db.query(stmnt,(menu_item_id,))
        row = cur.fetchonemap()
        if row is not None:
            menu_item = MenuItem()
            menu_item.set_id(menu_item_id)
            menu_item.set_name(row["MNI_NAME"],True)
            menu_item.set_order(row["MNI_ORDER"])
            if row["MNI_MNU_ID"] is not None:
                menu_item.set_menu_id(row["MNI_MNU_ID"],True)
            if row["MNI_MNI_ID"] is not None:
                menu_item.set_parent_menu_item_id(row["MNI_MNI_ID"],True)
            if row["MNI_ATL_ID"] is not None:
                menu_item.set_action_list_id(row["MNI_ATL_ID"])

            return menu_item
        return None
开发者ID:skarphed,项目名称:skarphed,代码行数:25,代码来源:action.py


示例5: get_action_by_id

    def get_action_by_id(cls, action_id):
        """
        This function looks for an Action with the given ID in the database
        and returns it
        If the action does not exist this returns null 
        """
        db = Database()
        stmnt = "SELECT ACT_NAME, ACT_ATL_ID, ACT_VIE_ID, \
                     ACT_SPA_ID, ACT_WGT_ID, ACT_URL, ACT_ORDER \
                 FROM ACTIONS WHERE ACT_ID = ?;"
        cur = db.query(stmnt, (action_id,))
        row = cur.fetchonemap()
        if row is not None:
            action = Action()
            if row["ACT_VIE_ID"] is not None:
                action.set_view_id(row["ACT_VIE_ID"],True)
            if row["ACT_URL"] is not None:
                action.set_url(row["ACT_URL"], True)
            if row["ACT_WGT_ID"] is not None and row["ACT_SPA_ID"] is not None:
                action.set_widget_space_constellation(row["ACT_WGT_ID"], row["ACT_SPA_ID"], True)
            action.set_id(action_id)
            action.set_name(row["ACT_NAME"],True)
            action.set_action_list_id(row["ACT_ATL_ID"])
            action.set_order(row["ACT_ORDER"])

            return action

        return None
开发者ID:skarphed,项目名称:skarphed,代码行数:28,代码来源:action.py


示例6: check_permission

    def check_permission(cls, permission, user):
        """
        checks whether a user has a specific permission
        """
        if user.__class__.__name__ == "User":
            user_id = user.get_id()
        elif type(user) != int:
            raise PermissionException(PermissionException.get_msg(9))

        db = Database()
        stmnt = "select 1 as RESULT from RDB$DATABASE  where CAST( ? AS VARCHAR(64)) in(select rig_name \
                from USERROLES \
                left join ROLES \
                  on rol_id = uro_rol_id \
                left join ROLERIGHTS \
                  on rri_rol_id = rol_id \
                left join RIGHTS \
                  on rig_id = rri_rig_id \
                where uro_usr_id = ? \
                union \
                select rig_name \
                from USERRIGHTS \
                left join RIGHTS \
                  on rig_id = uri_rig_id \
                where uri_usr_id = ?) ; " \
        
        cur = db.query(stmnt,(permission,user_id,user_id))

        res = cur.fetchone()
        if res is None:
            return False
        res = res[0]
        return res == 1
开发者ID:skarphed,项目名称:skarphed,代码行数:33,代码来源:permissions.py


示例7: delete

 def delete(self):
     """
     deletes this session
     """
     db = Database()
     stmnt = "DELETE FROM SESSIONS WHERE SES_ID = ? ;"
     db.query(stmnt,(self._id,),commit=True)
开发者ID:skarphed,项目名称:skarphed,代码行数:7,代码来源:session.py


示例8: get_session

    def get_session(cls,cookies):
        """
        returns the session if it's not expired or nonexistant
        """
        cookie = SimpleCookie(cookies)
        session_id = cookie['session_id'].value
        
        db = Database()
        stmnt = "SELECT SES_USR_ID, SES_EXPIRES FROM SESSIONS WHERE SES_ID = ? ;"

        cur = db.query(stmnt,(session_id,))
        row = cur.fetchonemap()

        session=None

        if row is not None:
            user = User.get_user_by_id(row["SES_USR_ID"])
            session = Session(user)
            session._id = session_id
            expiration = row["SES_EXPIRES"]
            if expiration < datetime.now():
                raise SessionException(SessionException.get_msg(0))    
            session._expiration = row["SES_EXPIRES"]
        else:
            raise SessionException(SessionException.get_msg(2))
        return session
开发者ID:skarphed,项目名称:skarphed,代码行数:26,代码来源:session.py


示例9: uninstall_module

    def uninstall_module(cls,module, hard=False):
        """
        uninstall a module
        the flag "hard" actually deletes the files of this module in modpath
        module can be module or module meta
        """
        if module.__class__.__name__ != "Module":
            nr = cls._get_module_id_from_name(module_meta["name"])
            module = cls.get_module(nr)

        Action.delete_actions_with_module(module)
        View.delete_mappings_with_module(module)
        CSSManager().delete_definitions_with_module(module)

        db = Database()
        db.remove_tables_for_module(module)
        Permission.remove_permissions_for_module(module)

        if hard:
            modpath = Configuration().get_entry('global.modpath')
            version = module.get_version()
            shutil.rmtree(modpath+"/"+module.get_name()+"/v"+version[0]+"_"+version[1]+"_"+version[2])

        cls._unregister_module(module)
        PokeManager.add_activity(ActivityType.MODULE)
开发者ID:skarphed,项目名称:skarphed,代码行数:25,代码来源:module.py


示例10: delete

 def delete(self):
     """
     Deletes the ActionList from the DB
     """
     db = Database()
     stmnt = "DELETE FROM ACTIONLISTS WHERE ATL_ID = ? ;"
     db.query(stmnt, (self.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
开发者ID:skarphed,项目名称:skarphed,代码行数:8,代码来源:action.py


示例11: delete

 def delete(self):
     """
     deletes this role from the database
     """
     db = Database()
     stmnt = "DELETE FROM ROLES WHERE ROL_ID = ? ;"
     db.query(stmnt,(self._id,),commit=True)
     PokeManager.add_activity(ActivityType.ROLE)
开发者ID:skarphed,项目名称:skarphed,代码行数:8,代码来源:permissions.py


示例12: store

 def store(self):
     """
     currently only one repository can be owned by one skarphed instance
     """
     db = Database()
     stmnt = "UPDATE OR INSERT INTO REPOSITORIES (REP_ID, REP_NAME, REP_IP, REP_PORT, REP_LASTUPDATE, REP_PUBLICKEY) VALUES (1,?,?,?,?,?) MATCHING (REP_ID) ;"
     db.query(stmnt,(self._name, self._ip, self._port, self._lastupdate, self.get_public_key()),commit=True)
     PokeManager.add_activity(ActivityType.REPOSITORY)
开发者ID:skarphed,项目名称:skarphed,代码行数:8,代码来源:module.py


示例13: remove_permission

 def remove_permission(cls, permission, module=""):
     """
     removes a permission from the database
     """
     db = Database()
     stmnt = "DELETE FROM RIGHTS WHERE RIG_NAME = ? ;"
     db.query(stmnt, (permission,),commit=True)
     PokeManager.add_activity(ActivityType.PERMISSION)
开发者ID:skarphed,项目名称:skarphed,代码行数:8,代码来源:permissions.py


示例14: remove_permissions_for_module

 def remove_permissions_for_module(cls,module):
     """
     removes the permissions of a module
     """
     module_name = module.get_name()
     db = Database()
     stmnt = "DELETE FROM RIGHTS WHERE RIG_NAME LIKE ? ;"
     db.query(stmnt, (module_name+"%",),commit=True)
开发者ID:skarphed,项目名称:skarphed,代码行数:8,代码来源:permissions.py


示例15: cleanup_css_sessiontable

 def cleanup_css_sessiontable(cls):
     """
     Cleans up old css filenames
     """
     db = Database()
     stmnt = "DELETE FROM CSSSESSION WHERE CSE_OUTDATED = 1 ;"
     db.query(stmnt, commit=True)
     return
开发者ID:skarphed,项目名称:skarphed,代码行数:8,代码来源:css.py


示例16: get_default_view

 def get_default_view(cls):
     db = Database()
     stmnt = "SELECT VIE_ID FROM VIEWS WHERE VIE_DEFAULT = 1 ;"
     cur = db.query(stmnt)
     row = cur.fetchonemap()
     if row is not None:
         return cls.get_from_id(row["VIE_ID"])
     else:
         raise ViewException(ViewException.get_msg(3))
开发者ID:skarphed,项目名称:skarphed,代码行数:9,代码来源:view.py


示例17: get_repository

 def get_repository():
     """
     returns this instance's repository
     """
     db = Database()
     stmnt = "select rep_id, rep_name, rep_ip, rep_port, rep_lastupdate from repositories where rep_id = 1;"
     cur = db.query(stmnt)
     row = cur.fetchonemap()
     return Repository(row["REP_ID"],row["REP_NAME"],row["REP_IP"],row["REP_PORT"],row["REP_LASTUPDATE"])
开发者ID:skarphed,项目名称:skarphed,代码行数:9,代码来源:module.py


示例18: delete_actions_with_widget

 def delete_actions_with_widget(cls, widget):
     """
     Deletes all actions that contain this widget
     """
     db = Database()
     stmnt = "DELETE FROM ACTIONS WHERE ACT_WGT_ID = ? ;"
     db.query(stmnt,(widget.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return
开发者ID:skarphed,项目名称:skarphed,代码行数:9,代码来源:action.py


示例19: delete_actions_with_module

 def delete_actions_with_module(cls, module):
     """
     Deletes all actions that contain this widget
     """
     db = Database()
     stmnt = "DELETE FROM ACTIONS WHERE ACT_WGT_ID IN (SELECT WGT_ID FROM WIDGETS WHERE WGT_MOD_ID = ?) ;"
     db.query(stmnt,(module.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return
开发者ID:skarphed,项目名称:skarphed,代码行数:9,代码来源:action.py


示例20: set_name

 def set_name(self,name,ignore_db = True):
     """
     Sets the Name of the action
     """
     self._name = unicode(name)
     if not ignore_db:
         db = Database()
         stmnt = "UPDATE ACTIONS SET ACT_NAME = ? WHERE ACT_ID = ? ;"
         db.query(stmnt, (self._name, self.get_id()),commit=True)
开发者ID:skarphed,项目名称:skarphed,代码行数:9,代码来源:action.py



注:本文中的skarphedcore.database.Database类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python skbio.read函数代码示例发布时间:2022-05-27
下一篇:
Python lng._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap