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


Python Membership.createMembership方法代码示例

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


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

示例1: main

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import createMembership [as 别名]

#.........这里部分代码省略.........
                        datasource_PK1 = datasource_session.datasource_PK1

                term_session.execute(COMMAND, datasource_PK1, authorized_session.getToken())
            else:
                #term_session.getTerms(authorized_session.getToken())
                term_session.createTerm(datasource_PK1, authorized_session.getToken())
                term_session.getTerm(authorized_session.getToken())
                term_session.updateTerm(datasource_PK1, authorized_session.getToken())

        if COURSE or ALL:
            course_session = Course(target_url, authorized_session.getToken())
            #process course command
            print("\n[main] Run course command: " + ('ALL' if ALL else COMMAND) + '...')
            if 'course' in COMMAND:
                if (('delete' in COMMAND) or ('read' in COMMAND)):
                    print ("[main] Deleting or getting does not require a datasource.")
                else:
                    print("[main] datasource_PK1:  not known... searching...")
                    datasource_session = DataSource(target_url, authorized_session.getToken())
                    datasource_session.getDataSource(authorized_session.getToken())
                    datasource_PK1 = datasource_session.datasource_PK1
                    print("[main] datasource_PK1: " + datasource_PK1)
                    if (datasource_PK1 is None):
                        print ("[main] data source not found, creating for demo...")
                        datasource_session.createDataSource(authorized_session.getToken())
                        datasource_PK1 = datasource_session.datasource_PK1
                course_session.execute(COMMAND, datasource_PK1, authorized_session.getToken())
            else:
                #course_session.getCourses(authorized_session.getToken())
                course_session.createCourse(datasource_PK1, authorized_session.getToken())
                course_session.getCourse(authorized_session.getToken())
                course_session.updateCourse(datasource_PK1, authorized_session.getToken())

        if USER or ALL:
            user_session = User(target_url, authorized_session.getToken())
            #process user command
            print("\n[main] Run user command: " + ('ALL' if ALL else COMMAND) + '...')
            if 'user' in COMMAND:
                if (('delete' in COMMAND) or ('read' in COMMAND)):
                    print ("[main] Deleting or getting does not require a datasource.")
                else:
                    print("[main] datasource_PK1:  not known... searching...")
                    datasource_session = DataSource(target_url, authorized_session.getToken())
                    datasource_session.getDataSource(authorized_session.getToken())
                    datasource_PK1 = datasource_session.datasource_PK1
                    print("[main] datasource_PK1: " + datasource_PK1)
                    if (datasource_PK1 is None):
                        print ("[main] data source not found, creating for demo...")
                    datasource_session.createDataSource(authorized_session.getToken())
                    datasource_PK1 = datasource_session.datasource_PK1
                    user_session.execute(COMMAND, datasource_PK1, authorized_session.getToken())
            else:
                #user_session.getUsers(authorized_session.getToken())
                user_session.createUser(datasource_PK1, authorized_session.getToken())
                user_session.getUser(authorized_session.getToken())
                user_session.updateUser(datasource_PK1, authorized_session.getToken())

        if MEMBERSHIP or ALL:
            membership_session = Membership(target_url, authorized_session.getToken())

            #process membership command
            print("\n[main] Run membership command: " + ('ALL' if ALL else COMMAND) + '...')
            if 'membership' in COMMAND:
                if (('delete' in COMMAND) or ('read' in COMMAND)):
                    print ("[main] Deleting or getting does not require a datasource.")
                else:
                    print("[main] datasource_PK1:  not known... searching...")
                    datasource_session = DataSource(target_url, authorized_session.getToken())
                    datasource_session.getDataSource(authorized_session.getToken())
                    datasource_PK1 = datasource_session.datasource_PK1
                    print("[main] datasource_PK1: " + datasource_PK1)
                    if (datasource_PK1 is None):
                        print ("[main] data source not found, creating for demo...")
                        datasource_session.createDataSource(authorized_session.getToken())
                        datasource_PK1 = datasource_session.datasource_PK1
                membership_session.execute(COMMAND, datasource_PK1, authorized_session.getToken())
            else:
                #membership_session.getMemberships(authorized_session.getToken())
                membership_session.createMembership(datasource_PK1, authorized_session.getToken())
                membership_session.getMembership(authorized_session.getToken())
                membership_session.updateMembership(datasource_PK1, authorized_session.getToken())
                membership_session.readUserMemberships(authorized_session.getToken())
    #clean up if not using individual commands
    if ALL:
        print('\n[main] Completing Demo and deleting created objects...')
        print ("[main] Deleting membership")
        membership_session.deleteMembership(authorized_session.getToken())
        print ("[main] Deleting Course")
        user_session.deleteUser(authorized_session.getToken())
        print ("[main] Deleting Course")
        course_session.deleteCourse(authorized_session.getToken())
        print ("[main] Deleting Term")
        term_session.deleteTerm(authorized_session.getToken())
        print ("[main] Deleting DataSource")
        datasource_session.deleteDataSource(authorized_session.getToken())
    else:
        print("Remember to delete created demo objects!")


    print("[main] Processing Complete")
开发者ID:hanleybrand,项目名称:BBDN-REST-DEMO_Python,代码行数:104,代码来源:restdemo.py

示例2: process_memberships

# 需要导入模块: from membership import Membership [as 别名]
# 或者: from membership.Membership import createMembership [as 别名]

#.........这里部分代码省略.........

    #req_number is the required number of memberships - user entered or constant max of 1000
    if int(req_number_memberships) == 1000:
        req_number_users = 150
        req_number_courses = 100
    else:
        req_number_users = req_number_memberships
        req_number_courses = req_number_memberships

    print ("number memberships in: %d" % req_number_memberships)
    print ("number users in: %d" % req_number_users)
    print ("number courses in: %d" % req_number_courses)

    #build membership lists for courses
    #create arrays containing memberships randomly associated with courses until
    #req_number_memberships is met.
    #Since membership count is the control:
    #    all courses may not have memberships
    #    all users may not have memberships
    while memberships_count < req_number_memberships:
        user_set = set()
        userID = USEREXTERNALIDSTEM + "_" + str(random.randint(int(index), int(index)+int(req_number_users)-1))
        #print ("userID %d" % userID)
        courseID = COURSEEXTERNALIDSTEM + "_" + str(random.randint(int(index), int(index)+int(req_number_courses)-1))
        #print ("courseID %d" % courseID)
        if courseID in course_memberships and courseID not in full:
            user_set = set(course_memberships[courseID])

        #print ("%s is not full - adding membership" % courseID)
        user_set.add(userID)
        course_memberships[courseID] = list(user_set)
        courses_with_members.add("%s_%s" % (COURSEEXTERNALIDSTEM, courseID))
        users_in_courses.add("%s_%s" % (USEREXTERNALIDSTEM, userID))
        memberships_count += 1
        #check if full add to full set.
        if len(user_set) >= MAX_PER_COURSE_MEMBERSHIPS:
            #print ("%s is full." % courseID)
            full.add(courseID)

    #what courses did not get members?
    all_courses = []
    for num in range( indx, indx+int(req_number_courses)-1):
        all_courses.append("%s_%d" % (COURSEEXTERNALIDSTEM, num))
    with open(output_file + "Courses_with_no_enrollments-" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")+".txt", "w") as text_file:
        text_file.write("\n##### This file contains the list of courses not given enrollments #####\n")
        text_file.write(str(set(all_courses) - courses_with_members))
    print ("COURSES WITH NO ENROLLMENTS FILE WRITTEN")

    #what users did not get into courses?
    all_users = []
    for num in range( indx, indx+int(req_number_users)-1):
        all_users.append("%s_%d" % (USEREXTERNALIDSTEM, num))
    #print (all_courses)
    with open(output_file + "Users_with_no_enrollments-" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")+".txt", "w") as text_file:
        text_file.write("\n##### This file contains the list of users not enrolled in a course #####\n")
        text_file.write(str(set(all_users) - users_in_courses))
    print ("USERS WITH NO ENROLLMENTS FILE WRITTEN")
    #print (set(all_users) - users_in_courses)

    if rest:
        print("WRITING DATA FILE and PROCESSING via REST, this will take a minute or so...")
    else:
        print("WRITING DATA FILE ONLY - you must process via SIS Framework...")

    with open(output_file+"_MEMBERSHIPS-"+datetime.datetime.now().strftime("%Y%m%d-%H%M%S")+".txt", "w") as text_file:
        text_file.write("\n##### DELETE THIS LINE....THE FOLLOWING IS A MEMBERSHIP SNAPSHOT FLAT FILE FOR STORE OR DELETE #####\n")
        text_file.write("##### DELETE THIS LINE.... DATASOURCEKEY %s #####\n" % DSKEXTERNALID)
        text_file.write("EXTERNAL_COURSE_KEY|EXTERNAL_PERSON_KEY|ROLE\n")

        if rest:
            print("WRITING DATA FILE and PROCESSING via REST, this will take a minute or so...")
            extId = "externalId:%s" % DSKEXTERNALID
            #same payload used for all membership requests
            json_payload = {
                "dataSourceId": extId,
                "availability": {
                    "available":"Yes"
                },
                "courseRoleId":"Student"
            }
        else:
            print("WRITING DATA FILE ONLY - you must process via SIS Framework...")
        counter = 0

        # take the above course_memberships dictionary,
        # iterate through the keys,
        # the values are the list of userIDs by index
        # write the snapshot file and
        # if REST send the request payload

        for key in course_memberships:
            courseID = key
            userID_list = course_memberships[key]

            for user in userID_list:
                text_file.write("%s|%s|Student\n" % (key, user))
                if rest:
                    global authorized_session
                    membership_session = Membership(rest, authorized_session.getToken())
                    membership_session.createMembership(courseID, user, json.dumps(json_payload), authorized_session.getToken())
开发者ID:blackboard,项目名称:BBDN-LearnObjectGen_Python,代码行数:104,代码来源:learnObjectGen.py


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