Esempio n. 1
0
def transfer(url, username, password):
    """ begin transfer """

    # url = "https://tca.wela.online/"
    # username = "******"
    # password = "******"

    conn = FrappeClient(url, username, password)

    program_enrollments = frappe.get_all(doctype="Program Enrollment",
                                         fields=[
                                             'student', 'student_name',
                                             'program', 'academic_year',
                                             'enrollment_date'
                                         ],
                                         filters={"docstatus": 1})
    len(program_enrollments)
    for enrollment in program_enrollments:
        if "-" in enrollment['program']:

            student = frappe.get_doc("Student", enrollment['student'])
            if student.first_name and student.last_name:
                params = {
                    # "student_name": enrollment['student_name'],
                    "fname": student.first_name,
                    "lname": student.last_name,
                    "academic_year": enrollment['academic_year'],
                    "program": enrollment['program']
                }
                print(params)
                to_wela = conn.get_api(
                    "wela.registration.doctype.sectioning.silid_to_wela",
                    params)
            else:
                print("Err ", student.first_name, " ", student.last_name)
Esempio n. 2
0
def custom_text_(msg, program):
    students = frappe.db.sql("""SELECT `tabStudent`.first_name,
                             `tabStudent`.student_mobile_number
                             FROM `tabProgram Enrollment`
                             INNER JOIN `tabStudent` ON `tabStudent`.name = `tabProgram Enrollment`.student
                              WHERE program=%s""", (program),
                             as_dict=True)
    wela_setting = frappe.get_doc("Wela Settings")
    if wela_setting.content_text_service == "Memo":
        for student in students:
            if student['student_mobile_number']:
                try:
                    send_sms(student['student_mobile_number'], msg)
                except:
                    print("error sms")
            else:
                print("mobile no not specified")
    else:
        conn = FrappeClient("https://wela.tailerp.com", "*****@*****.**",
                            "hbTcTdFtBag9RV4Y")
        for student in students:
            params = {
                "mobile_number": student['student_mobile_number'],
                "message": msg
            }

            lms_user = conn.get_api("gsmbox.gsmbox.doctype.memo.add_memo",
                                    params)
Esempio n. 3
0
def get_contribution_status(message_id):
	from frappe.frappeclient import FrappeClient
	doc = frappe.get_doc('Translation', message_id)
	translator = FrappeClient(get_translator_url())
	contributed_translation = translator.get_api('translator.api.get_contribution_status', params={
		'translation_id': doc.contribution_docname
	})
	return contributed_translation
def send_list_to_memo(message_list):
    """This function will send the gathered notifications to Memo List"""
    message_priority = 0
    for message in message_list:
        wela_setting = frappe.get_doc("Wela Settings")
        user_info = execute_query("GET_USER_MOBILE_NO",
                                  filters={"name": message['owner']},
                                  as_dict=1)
        number = user_info[0]['mobile_no']
        if is_correct_number(number):
            try:
                if wela_setting.post_notification_text_service == "Memo":
                    sms = frappe.get_doc({
                        "doctype": "Memo",
                        "mobile_number": number,
                        "message": message['message'],
                        "priority": message_priority
                    })
                    sms.insert(ignore_permissions=True)
                elif wela_setting.post_notification_text_service == "Tailerp":
                    try:
                        conn = FrappeClient("https://wela.tailerp.com",
                                            "*****@*****.**",
                                            "hbTcTdFtBag9RV4Y")
                        params = {
                            "mobile_number": number,
                            "message": message['message']
                        }
                        lms_user = conn.get_api(
                            "gsmbox.gsmbox.doctype.memo.add_memo", params)
                    except:
                        sms = frappe.get_doc({
                            "doctype": "Memo",
                            "mobile_number": number,
                            "message": message['message'],
                            "priority": message_priority
                        })
                        sms.insert(ignore_permissions=True)
                else:
                    sms = frappe.get_doc({
                        "doctype": "Memo",
                        "mobile_number": number,
                        "message": message['message'],
                        "priority": message_priority
                    })
                    sms.insert(ignore_permissions=True)

            except Exception as e:
                print(e)
                pass
Esempio n. 5
0
def send_to_memo():
    wela_setting = frappe.get_doc("Wela Settings")
    if wela_setting.text_notification == 1:
        if wela_setting.text_notification_service == "Wela":
            try:
                from frappe.utils.password import get_decrypted_password
                wela_api_password = get_decrypted_password(
                    "Wela Settings",
                    "Wela Settings",
                    fieldname="wela_password")
                conn = FrappeClient(wela_setting.wela_url,
                                    wela_setting.wela_username,
                                    wela_api_password)
            except:
                conn = FrappeClient("https://wela.tailerp.com",
                                    "*****@*****.**", "hbTcTdFtBag9RV4Y")
        else:
            conn = FrappeClient("https://wela.tailerp.com",
                                "*****@*****.**", "hbTcTdFtBag9RV4Y")

        user_info = frappe.db.sql(
            f"SELECT first_name,last_name, student_mobile_number FROM tabStudent WHERE student_email_id='{frappe.session.user}'",
            as_dict=1)
        for user in user_info:
            first_name = user['first_name'] or ""
            last_name = user['last_name'] or ""
            full_name = (first_name + " " + last_name).strip()
            site_name = frappe.utils.get_site_name(frappe.local.request.host)
            message = f"Student {full_name} has logged on to {site_name}"
            if user['student_mobile_number']:
                params = {
                    "mobile_number": user['student_mobile_number'],
                    "message": message
                }

                lms_user = conn.get_api("gsmbox.gsmbox.doctype.memo.add_memo",
                                        params)
Esempio n. 6
0
def send_grades_to_wela(grades):
    from frappe.utils.password import get_decrypted_password
    import json
    json_grades = json.loads(grades)
    params = {"grades": json_grades}
    wela_settings = frappe.get_doc("Wela Settings")
    wela_api_url = wela_settings.wela_api_url
    wela_api_username = wela_settings.wela_api_username
    wela_api_password = get_decrypted_password("Wela Settings",
                                               "Wela Settings",
                                               fieldname="wela_api_password")
    if wela_api_url and wela_api_username and wela_api_password:

        conn = FrappeClient(wela_api_url, wela_api_username, wela_api_password)
        lms_user = conn.get_api(
            "wela.grading.doctype.submit_grading_sheet.submit_grades_from_silid",
            params)
        return lms_user

    else:
        frappe.throw("Please Set API settings on Wela Settings")


# OLD VERSION
# def execute(filters=None):
#     columns, data = [],[]
#
#     columns = [
#         {"label": "Student", 'width': 100, "fieldname": "student"}
#     ]
#     data.append(
#         {"student": "<b>Highest Possible Score</b>"}
#     )
#     classwork_categories = frappe.db.sql(
#         f"SELECT name FROM `tabClasswork Category`", as_dict=1
#     )
#     program = filters.get("program")
#     for category in classwork_categories:
#         category_name = category['name']
#         total_points_earned_obj = {}
#         total_points_earned = 0
#
#         # Get Written Activities by Course and Classwork Category
#         written_activities = frappe.db.sql(
#             f"SELECT "
#             f"`tabCourse Enrollment`.student as student_code, "
#             f"`tabStudent`.student_email_id,"
#             f"`tabStudent`.first_name,"
#             f"`tabStudent`.middle_name,"
#             f"`tabStudent`.last_name,"
#             f"`tabWritten Activity`.`activity` as written_activity_activity,"
#             f"`tabWritten Activity`.`program` as written_activity_program,"
#             f"`tabWritten Activity`.`grade` as written_activty_grade,"
#             f"`tabContent Silid`.`highest_possible_score`,"
#             f"`tabContent Silid`.`classwork_category`"
#             f"FROM `tabCourse Enrollment` "
#             f"JOIN `tabStudent` ON `tabCourse Enrollment`.student=`tabStudent`.name "
#             f"JOIN `tabWritten Activity` ON `tabWritten Activity`.`student`=`tabStudent`.`student_email_id` "
#             f"LEFT JOIN `tabContent Silid` ON `tabContent Silid`.`name`=`tabWritten Activity`.`activity` "
#             f"WHERE `tabContent Silid`.`classwork_category`='{category_name}' "
#             f"AND `tabWritten Activity`.`program`='{program}' "
#             f"GROUP BY `tabWritten Activity`.`activity`"
#             , as_dict=1
#         )
#
#         # Get Quizzes Activities by Course and Worklass Category
#         quiz_activities = frappe.db.sql(
#             f"SELECT "
#             f"`tabCourse Enrollment`.student as student_code, "
#             f"`tabStudent`.student_email_id,"
#             f"`tabStudent`.first_name,"
#             f"`tabStudent`.middle_name,"
#             f"`tabStudent`.last_name,"
#             f"`tabQuiz Activity`.`name` ,"
#             f"`tabQuiz Activity`.`quiz` as quiz_name,"
#             f"`tabQuiz Activity`.`course`,"
#             f"`tabQuiz Activity`.`score`,"
#             f"`tabQuiz`.`max_points`,"
#             f"`tabQuiz`.`classwork_category` as quiz_classwork_category "
#             f"FROM `tabCourse Enrollment` "
#             f"LEFT JOIN `tabStudent` ON `tabCourse Enrollment`.student=`tabStudent`.name "
#             f"LEFT JOIN `tabQuiz Activity` ON `tabCourse Enrollment`.`student`=`tabQuiz Activity`.`student` "
#             f"LEFT JOIN `tabQuiz` ON `tabQuiz`.`name`=`tabQuiz Activity`.`quiz` "
#             f"WHERE `tabQuiz`.`classwork_category`='{category_name}' "
#             f"AND `tabQuiz Activity`.`course`='{program}' "
#             f"GROUP BY `tabCourse Enrollment`.student, quiz"
#             ,as_dict=1
#         )
#
#
#
#         if written_activities:
#             for written_activity in written_activities:
#                 # Append Column name according to written activity
#                 columns.append({
#                     "label": written_activity['written_activity_activity'],
#                     "width": 130,
#                     "fieldname": written_activity['written_activity_activity']
#                 })
#
#                 # Append Highest possible score on first row
#                 data[0].update({
#                     written_activity['written_activity_activity']: f"{written_activity['highest_possible_score']}",
#                     "hps": written_activity['highest_possible_score']
#                 })
#
#                 total_points_earned += float(written_activity['written_activty_grade'])
#
#                 total_points_earned_obj.update({
#                     f"{written_activity['student_code']}_tpe": total_points_earned
#                 })
#
#                 # Append Data of student
#                 full_name = f"{written_activity['first_name'] or ''} {written_activity['middle_name'] or ''} {written_activity['last_name'] or ''}"
#                 data.append({
#                     "student_code": written_activity['student_code'],
#                     "student": full_name,
#                     written_activity['written_activity_activity']: written_activity['written_activty_grade'],
#
#                 })
#
#         if quiz_activities:
#
#             for quiz in quiz_activities:
#
#                 # Append column name according to Quiz Name
#                 columns.append({
#                     "label": quiz['quiz_name'],
#                     "width": 130,
#                     "fieldname": quiz['quiz_name']
#                 })
#
#                 # Append Max Points on first row
#                 data[0].update({
#                     quiz['quiz_name']: quiz['max_points'],
#                     "hps": quiz['max_points']
#                 })
#
#                 # Find existing Object of Student from data and update with Quiz Score
#                 does_exist = next((x for x in data if x== quiz['student_code']), None)
#                 if does_exist is not None:
#                     does_exist.update({
#                         quiz['quiz_name']: quiz['score']
#                     })
#                 else:
#                     full_name = f"{quiz['first_name'] or ''} {quiz['middle_name'] or ''} {quiz['last_name'] or ''}"
#                     data.append({
#                         "student_code": quiz['student_code'],
#                         "student": full_name,
#                         quiz['quiz_name']: quiz['score']
#                     })
#
#         # Count Total and Percentile per Workclass Category
#         if written_activities or quiz_activities:
#             columns.append({
#                 "label": "Total",
#                 "width": 130,
#                 "fieldname": f"total_{category_name}"
#             })
#             columns.append({
#                 "label": f"{category_name} Percentage",
#                 "width": 130,
#                 "fieldname": f"percentile_{category_name}"
#             })
#             for databit in data:
#                 total = 0
#                 for attr, value in databit.items():
#                     try:
#                         total += float(value) if attr != "hps" else 0
#                     except:
#                         pass
#                 percentile = float((total / int(data[0]['hps'])) * 100) if int(data[0]['hps']) else 100.0
#                 databit.update({
#                     f"total_{category_name}": f"{total}",
#                     f"percentile_{category_name}":
#                         f"<span style='color:#006400!important;font-weight:bold';>{percentile}%</span>" if percentile > 75.0 else
#                         f"<span style='color:#c30c0c!important;font-weight:bold';>{percentile}%</span>"
#                 })
#
#     if len(data) == 1:
#         data.clear()
#     return columns, data