当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseInterface.create_connection方法代码示例

本文整理汇总了Python中database.database.DatabaseInterface.create_connection方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseInterface.create_connection方法的具体用法?Python DatabaseInterface.create_connection怎么用?Python DatabaseInterface.create_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在database.database.DatabaseInterface的用法示例。


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

示例1: deactivate_project

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def deactivate_project(requested_by_user: int, project_id: int) -> bool:
        """
        Deactivates an active project

        :param requested_by_user:   ID of the user that requested modification of the user
        :param project_id: ID of the project that should be deactivated

        :return:    Success or failure
        """
        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Start a new revision
            revision_id = None

            if success:
                revision_id = DatabaseInterface.tables().revision.insert_row(
                    connection,
                    datetime.datetime.utcnow(),
                    requested_by_user)

                if revision_id is None:
                    success = False

            # Read project
            project = None

            if success:
                project = ProjectManagementInterface.__read_project_by_id(connection,
                                                                          project_id,
                                                                          revision_id)

                if project is None:
                    success = False
                elif not project["active"]:
                    # Error, project is already inactive
                    success = False

            # Deactivate project
            if success:
                success = DatabaseInterface.tables().project_information.insert_row(
                    connection,
                    project_id,
                    project["short_name"],
                    project["full_name"],
                    project["description"],
                    False,
                    revision_id)

            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise

        return success
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:62,代码来源:project_management.py

示例2: read_project_by_id

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def read_project_by_id(project_id: int, max_revision_id=None) -> Optional[dict]:
        """
        Reads a project (active or inactive) that matches the specified project ID

        :param project_id:      ID of the project
        :param max_revision_id: Maximum revision ID for the search ("None" for latest revision)

        :return:    Project information object

        Returned dictionary contains items:

        - id
        - short_name
        - full_name
        - description
        - active
        - revision_id
        """
        connection = DatabaseInterface.create_connection()

        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)

        # Read a project that matches the specified project ID
        project = None

        if max_revision_id is not None:
            project = ProjectManagementInterface.__read_project_by_id(connection,
                                                                      project_id,
                                                                      max_revision_id)

        return project
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:35,代码来源:project_management.py

示例3: read_tracker_by_id

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def read_tracker_by_id(tracker_id: int, max_revision_id=None) -> Optional[dict]:
        """
        Reads a tracker (active or inactive) that matches the specified tracker ID

        :param tracker_id:      ID of the tracker
        :param max_revision_id: Maximum revision ID for the search ("None" for latest revision)

        :return:    Tracker information object

        Returned dictionary contains items:

        - id
        - project_id
        - short_name
        - full_name
        - description
        - active
        - revision_id
        """
        connection = DatabaseInterface.create_connection()
        
        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)
        
        # Read a tracker that matches the specified tracker ID
        tracker = None
        
        if max_revision_id is not None:
            tracker = TrackerManagementInterface.__read_tracker_by_id(connection,
                                                                      tracker_id,
                                                                      max_revision_id)
        
        return tracker
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:36,代码来源:tracker_management.py

示例4: read_all_project_ids

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def read_all_project_ids(project_selection=ProjectSelection.Active,
                             max_revision_id=None) -> List[int]:
        """
        Reads all project IDs from the database

        :param project_selection:   Search for active, inactive or all project
        :param max_revision_id:     Maximum revision ID for the search ("None" for latest revision)

        :return:    List of project IDs
        """
        connection = DatabaseInterface.create_connection()

        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)

        # Reads all project IDs from the database
        projects = None

        if max_revision_id is not None:
            projects = DatabaseInterface.tables().project_information.read_all_project_ids(
                connection,
                project_selection,
                max_revision_id)

        return projects
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:28,代码来源:project_management.py

示例5: read_all_tracker_field_ids

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def read_all_tracker_field_ids(tracker_id: int,
                                   tracker_field_selection=TrackerFieldSelection.Active,
                                   max_revision_id=None) -> List[int]:
        """
        Reads all tracker field IDs from the database

        :param tracker_id:              ID of the tracker
        :param tracker_field_selection: Search for active, inactive or all tracker
        :param max_revision_id:         Maximum revision ID for the search ("None" for latest
                                        revision)

        :return:    List of tracker field IDs
        """
        connection = DatabaseInterface.create_connection()
        
        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)
        
        # Reads all tracker field IDs from the database
        tracker_fields = None
        
        if max_revision_id is not None:
            tracker_fields = \
                DatabaseInterface.tables().tracker_field_information.read_all_tracker_field_ids(
                    connection,
                    tracker_id,
                    tracker_field_selection,
                    max_revision_id)
        
        return tracker_fields
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:33,代码来源:tracker_field_management.py

示例6: activate_tracker

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def activate_tracker(requested_by_user: int, tracker_id: int) -> bool:
        """
        Activates an inactive tracker

        :param requested_by_user:   ID of the user that requested modification of the user
        :param tracker_id:          ID of the tracker that should be activated

        :return:    Success or failure
        """
        connection = DatabaseInterface.create_connection()
        
        try:
            success = connection.begin_transaction()
            
            # Start a new revision
            revision_id = None
            
            if success:
                revision_id = DatabaseInterface.tables().revision.insert_row(
                    connection,
                    datetime.datetime.utcnow(),
                    requested_by_user)
                
                if revision_id is None:
                    success = False
            
            # Read tracker
            tracker = None
            
            if success:
                tracker = TrackerManagementInterface.__read_tracker_by_id(connection,
                                                                          tracker_id,
                                                                          revision_id)
                
                if tracker is None:
                    success = False
                elif tracker["active"]:
                    # Error, tracker is already active
                    success = False
            
            # Activate tracker
            if success:
                success = DatabaseInterface.tables().tracker_information.insert_row(
                    connection,
                    tracker_id,
                    tracker["short_name"],
                    tracker["full_name"],
                    tracker["description"],
                    True,
                    revision_id)
            
            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise
        
        return success
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:62,代码来源:tracker_management.py

示例7: __read_user_by_display_name

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def __read_user_by_display_name(token: str, display_name: str) -> dict:
        """
        Reads current user's information

        :param token:           Session token which contains the current user's information
        :param display_name:    Display name

        :return:    User information object

        Returned dictionary contains items:

        - id
        - user_name
        - display_name
        - email
        - active
        """
        user = None
        success = False
        error_code = None
        error_message = None

        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Extract session user
            if success:
                session_user = RestrictedResource._read_session_user(connection, token)

                if session_user is None:
                    success = False
                    error_code = 400
                    error_message = "Invalid session token"

            # Read requested user
            if success:
                user = UserManagementInterface.read_user_by_display_name(connection, display_name)

                if user is None:
                    success = False
                    error_code = 400
                    error_message = "Invalid user name"

            connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            abort(500, message="Internal error, please try again")

        # Return user
        if success:
            return jsonify(user)
        else:
            if (error_code is not None) and (error_message is not None):
                abort(error_code, message=error_message)
            else:
                abort(500, message="Internal error")
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:60,代码来源:user.py

示例8: update_user_information

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def update_user_information(user_to_modify: int,
                                user_name: str,
                                display_name: str,
                                email: str,
                                active: bool) -> bool:
        """
        Updates user's information

        :param user_to_modify:  ID of the user that should be modified
        :param user_name:       User's new user name
        :param display_name:    User's new display name
        :param email:           User's new email address
        :param active:          User's new state (active or inactive)

        :return:    Success or failure
        """
        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Check if there is already an existing user with the same user name
            if success:
                user = UserManagementInterface.__read_user_by_user_name(connection, user_name)

                if user is not None:
                    if user["id"] != user_to_modify:
                        success = False

            # Check if there is already an existing user with the same display name
            if success:
                user = UserManagementInterface.__read_user_by_display_name(connection,
                                                                           display_name)

                if user is not None:
                    if user["id"] != user_to_modify:
                        success = False

            # Update user's information
            if success:
                success = DatabaseInterface.tables().user.update_row(connection,
                                                                     user_to_modify,
                                                                     user_name,
                                                                     display_name,
                                                                     email,
                                                                     active)

            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise

        return success
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:58,代码来源:user_management.py

示例9: read_all_user_ids

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def read_all_user_ids(user_selection=UserSelection.Active) -> List[int]:
        """
        Reads all user IDs from the database

        :param user_selection:  Search for active, inactive or all users

        :return:    List of user IDs
        """
        connection = DatabaseInterface.create_connection()
        return DatabaseInterface.tables().user.read_all_ids(connection, user_selection)
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:12,代码来源:user_management.py

示例10: create_tracker

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def create_tracker(requested_by_user: int,
                       project_id: int,
                       short_name: str,
                       full_name: str,
                       description: str) -> Optional[int]:
        """
        Creates a new tracker

        :param requested_by_user:   ID of the user that requested creation of the new tracker
        :param project_id:          ID of the project
        :param short_name:          Tracker's short name
        :param full_name:           Tracker's full name
        :param description:         Tracker's description

        :return:    Tracker ID of the new tracker
        """
        tracker_id = None
        connection = DatabaseInterface.create_connection()
        
        try:
            success = connection.begin_transaction()
            
            # Start a new revision
            revision_id = None
            
            if success:
                revision_id = DatabaseInterface.tables().revision.insert_row(
                    connection,
                    datetime.datetime.utcnow(),
                    requested_by_user)
                
                if revision_id is None:
                    success = False
            
            # Create the tracker
            if success:
                tracker_id = TrackerManagementInterface.__create_tracker(connection,
                                                                         project_id,
                                                                         short_name,
                                                                         full_name,
                                                                         description,
                                                                         revision_id)
                
                if tracker_id is None:
                    success = False
            
            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise
        
        return tracker_id
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:57,代码来源:tracker_management.py

示例11: post

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def post(self):
        """
        Logs out the user
        """
        # Extract session token from the request
        token = self._read_session_token()

        # Log out
        success = False
        error_code = None
        error_message = None

        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Get the session token
            session_token = None

            if success:
                session_token = UserManagementInterface.read_session_token(connection, token)

                if session_token is None:
                    success = False
                    error_code = 400
                    error_message = "Invalid session token"

            # Delete session token
            if success:
                success = UserManagementInterface.delete_session_token(connection, token)

                if not success:
                    error_code = 500
                    error_message = "Failed to log out, please try again"

            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            abort(500, message="Internal error, please try again")

        # Return response
        if success:
            return None
        else:
            if (error_code is not None) and (error_message is not None):
                abort(error_code, message=error_message)
            else:
                abort(500, message="Internal error")
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:54,代码来源:logout.py

示例12: read_tracker_fields_by_display_name

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def read_tracker_fields_by_display_name(display_name: str,
                                            max_revision_id=None) -> List[dict]:
        """
        Reads all active and inactive tracker fields that match the specified display name

        :param display_name:    Tracker field's display name
        :param max_revision_id: Maximum revision ID for the search ("None" for latest revision)

        :return:    Tracker field information of all tracker fields that match the search attribute

        Each dictionary in the returned list contains items:

        - id
        - tracker_id
        - name
        - display_name
        - description
        - field_type
        - required
        - active
        - revision_id
        """
        connection = DatabaseInterface.create_connection()
        
        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)
        
        # Read tracker fields that match the specified display name
        tracker_fields = list()
        
        if max_revision_id is not None:
            tracker_field_information_list = \
                DatabaseInterface.tables().tracker_field_information.read_information(
                    connection,
                    "display_name",
                    display_name,
                    TrackerFieldSelection.All,
                    max_revision_id)
            
            for tracker_field_information in tracker_field_information_list:
                tracker_fields.append(
                    TrackerFieldManagementInterface.__parse_tracker_field_information(
                        tracker_field_information))
        
        return tracker_fields
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:48,代码来源:tracker_field_management.py

示例13: deactivate_user

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def deactivate_user(user_id: int) -> bool:
        """
        Deactivates an active user

        :param user_id: ID of the user that should be deactivated

        :return:    Success or failure
        """
        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Read user
            user = None

            if success:
                user = UserManagementInterface.read_user_by_id(connection, user_id)

                if user is None:
                    success = False
                elif not user["active"]:
                    # Error, user is already inactive
                    success = False

            # Deactivate user
            if success:
                success = DatabaseInterface.tables().user.update_row(connection,
                                                                     user_id,
                                                                     user["user_name"],
                                                                     user["display_name"],
                                                                     user["email"],
                                                                     False)

            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise

        return success
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:45,代码来源:user_management.py

示例14: create_user

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def create_user(user_name: str,
                    display_name: str,
                    email: str,
                    authentication_type: str,
                    authentication_parameters: dict) -> Optional[int]:
        """
        Creates a new user

        :param user_name:                   User's user name
        :param display_name:                User's display name
        :param email:                       Email address of the user
        :param authentication_type:         User's authentication type
        :param authentication_parameters:   User's authentication parameters

        :return:    User ID of the new user
        """
        user_id = None
        connection = DatabaseInterface.create_connection()

        try:
            success = connection.begin_transaction()

            # Create the user
            if success:
                user_id = UserManagementInterface.__create_user(connection,
                                                                user_name,
                                                                display_name,
                                                                email,
                                                                authentication_type,
                                                                authentication_parameters)

                if user_id is None:
                    success = False

            if success:
                connection.commit_transaction()
            else:
                connection.rollback_transaction()
        except:
            connection.rollback_transaction()
            raise

        return user_id
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:45,代码来源:user_management.py

示例15: read_trackers_by_full_name

# 需要导入模块: from database.database import DatabaseInterface [as 别名]
# 或者: from database.database.DatabaseInterface import create_connection [as 别名]
    def read_trackers_by_full_name(full_name: str,
                                   max_revision_id=None) -> List[dict]:
        """
        Reads all active and inactive trackers that match the specified full name

        :param full_name:       Tracker's full name
        :param max_revision_id: Maximum revision ID for the search ("None" for latest revision)

        :return:    Tracker information of all trackers that match the search attribute

        Each dictionary in the returned list contains items:

        - id
        - project_id
        - short_name
        - full_name
        - description
        - active
        - revision_id
        """
        connection = DatabaseInterface.create_connection()
        
        if max_revision_id is None:
            max_revision_id = DatabaseInterface.tables().revision.read_current_revision_id(
                connection)
        
        # Read trackers that match the specified full name
        trackers = list()
        
        if max_revision_id is not None:
            tracker_information_list = \
                DatabaseInterface.tables().tracker_information.read_information(
                    connection,
                    "full_name",
                    full_name,
                    TrackerSelection.All,
                    max_revision_id)
            
            for tracker_information in tracker_information_list:
                trackers.append(TrackerManagementInterface.__parse_tracker_information(
                    tracker_information))
        
        return trackers
开发者ID:djurodrljaca,项目名称:salamander-alm,代码行数:45,代码来源:tracker_management.py


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