Beispiel #1
0
 def get_access_text(self, lesson_id):
     if data_capture_lessons.is_shared(lesson_id) == 1:
         class_id, User = data_capture_lessons.get_user_classid()
         return ("Shared Access:\nLesson ID = " + str(lesson_id) +
                 "\nClass ID = " + str(class_id) + "\nUser = "******""
Beispiel #2
0
def post_lesson(data, token, lesson_id, win):
    try:
        json_object = json.loads(data)
        class_id, User = data_capture_lessons.get_user_classid()
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Token ' + token
        }
        cn = configparser.ConfigParser()
        cn.read("../urls.config")
        url_root = cn['url']['share']
        url = url_root + "lesson/?username="******"&lesson_id=" + json_object[
                'lesson_id'] + "&class_id=" + json_object['class_id']
        response_get = requests.get(url, headers=headers)
        json_object_get = json.loads(response_get.content)
        if response_get.status_code == 200 and json_object_get is not None and len(
                json_object_get) > 0:

            global_lesson_id = json_object_get[0]["global_lesson_id"]
            url_put = url_root + "lesson/" + str(
                global_lesson_id) + "/?username="******"&lesson_id=" + str(
                        json_object['lesson_id']) + "&class_id=" + str(
                            json_object['class_id'])
            response = requests.patch(url_put,
                                      headers=headers,
                                      data=data.encode('utf-8'))
        else:
            response = requests.post(url,
                                     headers=headers,
                                     data=data.encode('utf-8'))
            print(response.status_code)
            print(response.text)

        if response.status_code == 201 or response.status_code == 200:
            data_capture_lessons.update_shared(lesson_id)
            messagebox.showinfo("Post Response",
                                "Posted the Lesson Successfully",
                                parent=win)
        else:
            messagebox.showinfo("Post Response", response.text, parent=win)
        url_logout = url_root + "auth/token/logout/"
        response_logout = requests.post(url_logout, headers=headers)
        print(response_logout.content)

    except Exception:
        print(traceback.print_exc())
        print("exception")
Beispiel #3
0
def prepare_lesson_share(lesson_id):
    class_id, User = data_capture_lessons.get_user_classid()
    userid = data_capture_lessons.get_userid(lesson_id)
    rows = data_capture_lessons.get_lessons_for_share(lesson_id)
    imageroot = file_root + os.path.sep + "Lessons" + os.path.sep + "Lesson" + str(
        lesson_id) + os.path.sep + "images" + os.path.sep

    data = '''{
     "lesson_id": "''' + str(rows[0]) + '''",
     "class_id": "''' + str(class_id) + '''",
     "user": "******",
     "title": "''' + make_json_ready(rows[1]) + '''",
     "title_image": "''' + convert_base_64(imageroot + rows[2]) + '''",
     "title_video": null,
     "title_description": "''' + make_json_ready(rows[4]) + '''",
     "term1": "''' + make_json_ready(rows[5]) + '''",
     "term1_description": "''' + make_json_ready(rows[6]) + '''",
     "term1_image": "''' + convert_base_64(imageroot + rows[7]) + '''",
     "term2": "''' + make_json_ready(rows[8]) + '''",
     "term2_description": "''' + make_json_ready(rows[9]) + '''",
     "term2_image": "''' + convert_base_64(imageroot + rows[10]) + '''",
     "term3": "''' + make_json_ready(rows[11]) + '''",
     "term3_description": "''' + make_json_ready(rows[12]) + '''",
     "term3_image": "''' + convert_base_64(imageroot + rows[13]) + '''",
     "number_of_steps": "''' + str(rows[14]) + '''",
     "step1_description": "''' + make_json_ready(rows[15]) + '''",
     "step1_image": "''' + convert_base_64(imageroot + rows[23]) + '''",
     "step2_description": "''' + make_json_ready(rows[16]) + '''",
     "step2_image": "''' + convert_base_64(imageroot + rows[24]) + '''",
     "step3_description": "''' + make_json_ready(rows[17]) + '''",
     "step3_image": "''' + convert_base_64(imageroot + rows[25]) + '''",
     "step4_description": "''' + make_json_ready(rows[18]) + '''",
     "step4_image": "''' + convert_base_64(imageroot + rows[26]) + '''",
     "step5_description": "''' + make_json_ready(rows[19]) + '''",
     "step5_image": "''' + convert_base_64(imageroot + rows[27]) + '''",
     "step6_description": "''' + make_json_ready(rows[20]) + '''",
     "step6_image": "''' + convert_base_64(imageroot + rows[28]) + '''",
     "step7_description": "''' + make_json_ready(rows[21]) + '''",
     "step7_image": "''' + convert_base_64(imageroot + rows[29]) + '''",
     "step8_description": "''' + make_json_ready(rows[22]) + '''",
     "step8_image": "''' + convert_base_64(imageroot + rows[30]) + '''",
     "questions": "''' + make_json_ready(rows[31]) + '''",
     "lesson_language": "''' + rows[33] + '''",
     "whiteboard_image": "''' + convert_base_64(imageroot + rows[36]) + '''",
     "application_video_link": "''' + rows[34] + '''",
     "application_video_running_notes": "''' + make_json_ready(rows[35]) + '''"
 }'''
    return data
Beispiel #4
0
def prepare_lesson_share(lesson_id):
    class_id, User = data_capture_lessons.get_user_classid()
    rows = data_capture_lessons.get_lessons_for_share(lesson_id)
    imageroot = file_root + os.path.sep + "Lessons" + os.path.sep + "Lesson" + str(
        lesson_id) + os.path.sep + "images" + os.path.sep

    data = '''{
     "lesson_id": "''' + str(rows[0]) + '''",
     "class_id": "''' + str(class_id) + '''",
     "user": "******",
     "title": "''' + rows[1] + '''",
     "title_image": "''' + convert_base_64(imageroot + rows[2]) + '''",
     "title_video": null,
     "title_description": "''' + rows[4].replace("\n", "~") + '''",
     "term1": "''' + rows[5] + '''",
     "term1_description": "''' + rows[6].replace("\n", "~") + '''",
     "term1_image": "''' + convert_base_64(imageroot + rows[7]) + '''",
     "term2": "''' + rows[8] + '''",
     "term2_description": "''' + rows[9].replace("\n", "~") + '''",
     "term2_image": "''' + convert_base_64(imageroot + rows[10]) + '''",
     "term3": "''' + rows[11] + '''",
     "term3_description": "''' + rows[12].replace("\n", "~") + '''",
     "term3_image": "''' + convert_base_64(imageroot + rows[13]) + '''",
     "number_of_steps": "''' + str(rows[14]) + '''",
     "step1_description": "''' + rows[15] + '''",
     "step1_image": "''' + convert_base_64(imageroot + rows[23]) + '''",
     "step2_description": "''' + rows[16] + '''",
     "step2_image": "''' + convert_base_64(imageroot + rows[24]) + '''",
     "step3_description": "''' + rows[17] + '''",
     "step3_image": "''' + convert_base_64(imageroot + rows[25]) + '''",
     "step4_description": "''' + rows[18] + '''",
     "step4_image": "''' + convert_base_64(imageroot + rows[26]) + '''",
     "step5_description": "''' + rows[19] + '''",
     "step5_image": "''' + convert_base_64(imageroot + rows[27]) + '''",
     "step6_description": "''' + rows[20] + '''",
     "step6_image": "''' + convert_base_64(imageroot + rows[28]) + '''",
     "step7_description": "''' + rows[21] + '''",
     "step7_image": "''' + convert_base_64(imageroot + rows[29]) + '''",
     "step8_description": "''' + rows[22] + '''",
     "step8_image": "''' + convert_base_64(imageroot + rows[30]) + '''",
     "questions": "''' + rows[31].replace("\n", "~") + '''"
 }'''
    return data
Beispiel #5
0
def post_lesson(call_screen, data, token, lesson_id):
    try:
        post_status = ""
        userid = ""
        json_object = json.loads(data)
        class_id, User = data_capture_lessons.get_user_classid()
        #first get the user id of the logged in user
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Token ' + token
        }
        url_user = "******"
        response_user = requests.get(url_user, headers=headers)
        if response_user.status_code == 200:
            userjson = json.loads(response_user.content)
            userid = userjson["id"]
            json_object[
                'user'] = "******" + str(
                    userid) + "/"
            data = json.dumps(json_object)
        url_root = "https://thelearningroom.el.r.appspot.com/"
        #url_root = "http://127.0.0.1:8000/"
        url = "https://thelearningroom.el.r.appspot.com/lesson/lesson/?username="******"&lesson_id=" + json_object[
                'lesson_id'] + "&class_id=" + json_object['class_id']
        #url = "http://127.0.0.1:8000/lesson/lesson/?username="******"&lesson_id="+json_object['lesson_id']+"&class_id="+json_object['class_id']
        response_get = requests.get(url, headers=headers)
        json_object_get = json.loads(response_get.content)
        if response_get.status_code == 200 and len(
                json_object_get
        ) > 0 and "global_lesson_id" in json_object_get[0]:
            global_lesson_id = json_object_get[0]["global_lesson_id"]
            url_put = url_root + "lesson/lesson/" + str(
                global_lesson_id) + "/?username="******"&lesson_id=" + str(
                        json_object['lesson_id']) + "&class_id=" + str(
                            json_object['class_id'])
            response = requests.patch(url_put,
                                      headers=headers,
                                      data=data.encode('utf-8'))
        else:
            response = requests.post(url,
                                     headers=headers,
                                     data=data.encode('utf-8'))
            print(response.status_code)
            print(response.text)

        if response.status_code == 201:
            data = response.content

            data_capture_lessons.update_shared(lesson_id, userid)
            post_status = "The lesson has been posted with following details\n User ID: " + str(
                userid) + " Class ID: " + str(class_id) + " Lesson ID:" + str(
                    lesson_id)
        elif response.status_code == 200:
            data_capture_lessons.update_shared(lesson_id, userid)
            post_status = "The lesson has been posted with following details\n User ID: " + str(
                userid) + " Class ID: " + str(class_id) + " Lesson ID:" + str(
                    lesson_id)
        else:
            post_status = response.text
        url_logout = url_root + "auth/token/logout/"
        response_logout = requests.post(url_logout, headers=headers)
        print(response_logout.content)
        call_screen.response_status(post_status)
        return post_status
    except Exception:
        print(traceback.print_exc())
        print("exception")
        call_screen.response_status(
            "Lesson could not be posted, there could be a problem with some corrupted texts.\n Please check once"
        )
        return "Lesson could not be posted,it could be because of copied texts which are corrupted.\n Please check your input texts once"