Beispiel #1
0
def importSchoolState(school_id):
    try:
        info = schoolStateApi.school_state({"school_id": str(school_id)})

        if info is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in info:
            error.log(__file__, False, "Unknown Object")
            return False

        if info["status"] == "ok":
            unique = {"school_id": str(school_id)}

            element = {
                "school_id": str(school_id),
                "state": info["state"],
                "active": "True" if info["state"] == "ok" else "False"
            }

            status = sync.sync(db.schools, unique, element)

        else:
            if "error" in info:
                error.log(__file__, False, info["error"])
            else:
                error.log(__file__, False, "Unknown Error")
    except Exception, e:
        error.log(__file__, False, str(e))
Beispiel #2
0
def importSubjectList ( school_id, start, end ):
	try:

		objectList = subjectListApi.subject_list(start, end, school_id)

		for row in objectList:
			unique = {
				"subject_id" : row["subject_id"]
			}

			notice_ids = []

			element = {
				"subject_id" : row["subject_id"],
				"name" : row["name"],
				"abbrevation" : row["abbrevation"]
			}

			status = sync.sync(db.subjects, unique, element)

		return True

	except Exception, e:
		error.log(__file__, False, str(e))
		return False

#importSubjectList(517, 500, 540)
#importSubjectList(517, 540, 580)
#importSubjectList(517, 580, 615)
#importSubjectList(517, 1363322359, 1363322359)
#importSubjectList(517, 1364002147, 1364002147)
#importSubjectList(517, 1452164869, 1452164869)
Beispiel #3
0
def importSchoolState ( school_id ):
	try:
		info = schoolStateApi.school_state({
			"school_id" : str(school_id)
		})

		if info is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in info:
			error.log(__file__, False, "Unknown Object")
			return False

		if info["status"] == "ok":
			unique = {
				"school_id" : str(school_id)
			}

			element = {
				"school_id" : str(school_id),
				"state" : info["state"],
				"active" : "True" if info["state"] == "ok" else "False"
			}

			status = sync.sync(db.schools, unique, element)

		else:
			if "error" in info:
				error.log(__file__, False, info["error"])
			else:
				error.log(__file__, False, "Unknown Error")
	except Exception, e:
		error.log(__file__, False, str(e))
Beispiel #4
0
def importSubjectList(school_id, start, end):
    try:

        objectList = subjectListApi.subject_list(start, end, school_id)

        for row in objectList:
            unique = {"subject_id": row["subject_id"]}

            notice_ids = []

            element = {
                "subject_id": row["subject_id"],
                "name": row["name"],
                "abbrevation": row["abbrevation"]
            }

            status = sync.sync(db.subjects, unique, element)

        return True

    except Exception, e:
        error.log(__file__, False, str(e))
        return False


#importSubjectList(517, 500, 540)
#importSubjectList(517, 540, 580)
#importSubjectList(517, 580, 615)
#importSubjectList(517, 1363322359, 1363322359)
#importSubjectList(517, 1364002147, 1364002147)
#importSubjectList(517, 1452164869, 1452164869)
Beispiel #5
0
def importTeamElements(school_id, branch_id, subject_id):
    try:
        objectList = teamElementsApi.team_elements({
            "school_id": school_id,
            "branch_id": branch_id,
            "subject_id": subject_id
        })

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            for row in objectList["team_elements"]:
                unique = {
                    "team_element_id": str(row["team_element_id"]),
                }

                contextCards = []
                contextCards.append(row["context_card_id"])
                existsing = db.team_elements.find(unique).limit(1)

                if existsing.count() > 0:
                    existsing = existsing[0]
                    if "context_cards" in existsing:
                        for card in existsing["context_cards"]:
                            if not card in contextCards:
                                contextCards.append(card)

                element = {
                    "team_element_id": str(row["team_element_id"]),
                    "school_id": str(row["school_id"]),
                    "branch_id": str(row["branch_id"]),
                    "subject_id": str(subject_id),
                    "type": "team",
                    "context_cards": contextCards,
                    "name": unicode(str(row["name"]).decode("utf8")),
                    "term": str(objectList["term"]["value"])
                }

                status = sync.sync(db.team_elements, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
def importTeamElements ( school_id, branch_id, subject_id ):
	try:
		objectList = teamElementsApi.team_elements({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"subject_id" : subject_id
		})

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			for row in objectList["team_elements"]:
				unique = {
					"team_element_id" : str(row["team_element_id"]),
				}

				contextCards = []
				contextCards.append(row["context_card_id"])
				existsing = db.team_elements.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"team_element_id" : str(row["team_element_id"]),
					"school_id" : str(row["school_id"]),
					"branch_id" : str(row["branch_id"]),
					"subject_id" : str(subject_id),
					"type" : "team",
					"context_cards" : contextCards,
					"name" : unicode(str(row["name"]).decode("utf8")),
					"term" : str(objectList["term"]["value"])
				}

				status = sync.sync(db.team_elements, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
def importFieldOfStudyPresentation ( school_id, branch_id, field_of_study_id ):
	try:
		objectList = field_of_study({
			"school_id" : school_id,
			"branch_id" : branch_id
		}, field_of_study_id)

		if objectList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			unique = {
				"field_of_study_id" : str(field_of_study_id)
			}

			contextCards = []
			contextCards.append("SR" + str(field_of_study_id))
			existsing = db.field_of_studies.find(unique).limit(1)

			if existsing.count() > 0:
				existsing = existsing[0]
				if "context_cards" in existsing:
					for card in existsing["context_cards"]:
						if not card in contextCards:
							contextCards.append(card)

			element = {
				"years" : objectList["years"],
				"semesters" : objectList["semesters"],
				"presentation" : objectList["presentation"],
				"subject_types" : objectList["subject_types"],
				"elective_groups" : objectList["elective_groups"],
				"subjects" : objectList["subjects"],
				"field_of_study_id" : str(field_of_study_id),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"context_cards" : contextCards
			}

			# Link with XPRS Subjects
			status = sync.sync(db.field_of_studies, unique, element)
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
def importTeamAccounting ( school_id, branch_id, team_element_id ):
	try:
		objectList = teamAccountingApi.team_accounting({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"team_element_id" : team_element_id
		})

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			unique = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id)
			}

			element = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id),
				"team_accounting" : objectList["total"]
			}

			teachers = []

			for row in objectList["teachers"]:
				existsing = db.persons.find({"name" : row["name"], "type" : "teacher", "abbrevation" : row["abbrevation"]}).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					row["teacher_id"] = existsing["teacher_id"]

				teachers.append(row)

			element["team_accounting"]["teachers"] = teachers

			status = sync.sync(db.team_elements, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
def importFieldOfStudyPresentation(school_id, branch_id, field_of_study_id):
    try:
        objectList = field_of_study(
            {
                "school_id": school_id,
                "branch_id": branch_id
            }, field_of_study_id)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            unique = {"field_of_study_id": str(field_of_study_id)}

            contextCards = []
            contextCards.append("SR" + str(field_of_study_id))
            existsing = db.field_of_studies.find(unique).limit(1)

            if existsing.count() > 0:
                existsing = existsing[0]
                if "context_cards" in existsing:
                    for card in existsing["context_cards"]:
                        if not card in contextCards:
                            contextCards.append(card)

            element = {
                "years": objectList["years"],
                "semesters": objectList["semesters"],
                "presentation": objectList["presentation"],
                "subject_types": objectList["subject_types"],
                "elective_groups": objectList["elective_groups"],
                "subjects": objectList["subjects"],
                "field_of_study_id": str(field_of_study_id),
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "context_cards": contextCards
            }

            # Link with XPRS Subjects
            status = sync.sync(db.field_of_studies, unique, element)
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #10
0
def importXPRSSubjects(school_id,
                       start,
                       end,
                       increase,
                       checkLevels=False,
                       levels=["01", "02", "03", "04", "05", "06"]):
    try:

        objectList = xprsSubjectsApi.xprs_subjects(start, end, increase,
                                                   school_id, checkLevels,
                                                   levels)

        for row in objectList:
            unique = {"xprs_subject_id": row["xprs_subject_id"]}

            notice_ids = []

            for x in row["notices"]:
                status = sync.sync(db.notices, {"name": x}, {"name": x})

                notice_ids.append(status["_id"])

            level = row["level"]

            if "-" in row["code"]:
                level = "-"

            element = {
                "xprs_subject_id": row["xprs_subject_id"],
                "context_card_id": row["context_card_id"],
                "name": row["name"],
                "code": row["code"].replace("-", ""),
                "subject_sub_type": row["subject_sub_type"],
                "level": level,
                "code_full": row["code_full"],
                "notices": row["notices"],
                "notice_ids": notice_ids,
                "code_full_name": row["code_full_name"]
            }

            status = sync.sync(db.xprs_subjects, unique, element)

        return True

    except Exception, e:
        error.log(__file__, False, str(e))
        return False


#importXPRSSubjects(517, 6043, 6048, 1, True, ["01"])
#importXPRSSubjects(517, 7000, 7019, 1, True, ["01", "02"])
#importXPRSSubjects(517, 1453150702, 1453150720, 1, False, False)
#importXPRSSubjects(517, 1453150720, 1453150750, 1, False, False)
#importXPRSSubjects(517, 1453150750, 1453150790, 1, False, False)
#importXPRSSubjects(517, 1453150790, 1453150830, 1, False, False)
#importXPRSSubjects(517, 1453150830, 1453150867, 1, False, False)
Beispiel #11
0
def importSchools():
    try:
        schoolList = schoolsApi.schools()

        if schoolList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in schoolList:
            error.log(__file__, False, "Unknown Object")
            return False

        if schoolList["status"] == "ok":
            for school in schoolList["schools"]:
                status = sync.sync(
                    db.schools, {
                        "school_id": school["school_id"],
                        "branch_id": school["branch_id"]
                    }, {
                        "school_id": school["school_id"],
                        "branch_id": school["branch_id"],
                        "name": school["name"],
                        "full_name": school["full_name"]
                    })

                if sync.check_action_event(status) == True:
                    # Launch School_info Scraper
                    # Launch Address scraper

                    for url in sync.find_listeners(
                            'school', {
                                "school_id": school["school_id"],
                                "branch_id": school["branch_id"]
                            }):
                        sync.send_event(
                            url, status["action"], {
                                "school_id": school["school_id"],
                                "branch_id": school["branch_id"],
                                "name": school["name"]
                            })

                    for url in sync.find_general_listeners('school_general'):
                        sync.send_event(
                            url, status["action"], {
                                "school_id": school["school_id"],
                                "branch_id": school["branch_id"],
                                "name": school["name"]
                            })

        else:
            if "error" in schoolList:
                error.log(__file__, False, schoolList["error"])
            else:
                error.log(__file__, False, "Unknown Error")
    except Exception, e:
        error.log(__file__, False, str(e))
Beispiel #12
0
def importSubjects ( school_id, branch_id ):
	try:

		objectList = subjectApi.subjects({
			"school_id" : school_id,
			"branch_id" : branch_id
		})

		if objectList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			for row in objectList["subjects"]:
				unique = {
					"subject_id" : str(row["subject_id"]),
					"term" : objectList["term"]["value"]
				}

				element = {
					"subject_id" : str(row["subject_id"]),
					"abbrevation" : row["initial"],
					"name" : row["name"]
				}

				status = sync.sync(db.subjects, unique, element)

				unique = {
					"school_id" : str(row["school_id"]),
					"branch_id" : str(row["branch_id"]),
					"term" : objectList["term"]["value"],
					"subject_id" : str(row["subject_id"]),
					"type" : row["type"]
				}

				status = sync.sync(db.school_subjects, unique, unique)

				# Possible Connect with XPRS Subjects

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #13
0
def importXPRSSubjects ( school_id, start, end, increase, checkLevels = False, levels = ["01", "02", "03", "04", "05", "06"] ):
	try:

		objectList = xprsSubjectsApi.xprs_subjects(start, end, increase, school_id, checkLevels, levels)

		for row in objectList:
			unique = {
				"xprs_subject_id" : row["xprs_subject_id"]
			}

			notice_ids = []

			for x in row["notices"]:
				status = sync.sync(db.notices, {"name" : x}, {"name" : x})

				notice_ids.append(status["_id"])

			level = row["level"]

			if "-" in row["code"]:
				level = "-"

			element = {
				"xprs_subject_id" : row["xprs_subject_id"],
				"context_card_id" : row["context_card_id"],
				"name" : row["name"],
				"code" : row["code"].replace("-", ""),
				"subject_sub_type" : row["subject_sub_type"],
				"level" : level,
				"code_full" : row["code_full"],
				"notices" : row["notices"],
				"notice_ids" : notice_ids,
				"code_full_name" : row["code_full_name"]
			}

			status = sync.sync(db.xprs_subjects, unique, element)

		return True

	except Exception, e:
		error.log(__file__, False, str(e))
		return False

#importXPRSSubjects(517, 6043, 6048, 1, True, ["01"])
#importXPRSSubjects(517, 7000, 7019, 1, True, ["01", "02"])
#importXPRSSubjects(517, 1453150702, 1453150720, 1, False, False)
#importXPRSSubjects(517, 1453150720, 1453150750, 1, False, False)
#importXPRSSubjects(517, 1453150750, 1453150790, 1, False, False)
#importXPRSSubjects(517, 1453150790, 1453150830, 1, False, False)
#importXPRSSubjects(517, 1453150830, 1453150867, 1, False, False)
Beispiel #14
0
def sync ( table, query, document, unset=["_updated", "_id", "_created"] ):
	existsing = table.find(query).limit(1)

	if existsing.count() is 0:
		document["_created"] = datetime.now()
		document["_updated"] = datetime.now()
		try:
			_id = table.insert(document, manipulate=True)
		except Exception, e:
			error.log(__file__, False, str(e))
		return {
			"status" : True,
			"action" : "created",
			"_id" : _id
		}
Beispiel #15
0
def importWorkMethods(school_id, branch_id, team_element_id):
    try:
        objectList = wordMethodsApi.work_methods({
            "school_id":
            school_id,
            "branch_id":
            branch_id,
            "team_element_id":
            team_element_id
        })

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            unique = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id)
            }

            element = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id),
                "work_methods": objectList["methods"]
            }

            status = sync.sync(db.team_elements, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #16
0
def importWorkMethods ( school_id, branch_id, team_element_id ):
	try:
		objectList = wordMethodsApi.work_methods({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"team_element_id" : team_element_id
		})

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			unique = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id)
			}

			element = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id),
				"work_methods" : objectList["methods"]
			}

			status = sync.sync(db.team_elements, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #17
0
def importSchoolInfo ( school_id ):
	try:
		info = school_info({
			"school_id" : str(school_id)
		})

		if info is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in info:
			error.log(__file__, False, "Unknown Object")
			return False

		if info["status"] == "ok":
			unique = {
				"school_id" : str(school_id),
				"branch_id" : info["information"]["branch_id"]
			}

			element = {
				"school_id" : str(school_id),
				"branch_id" : info["information"]["branch_id"],
				"terms" : info["information"]["terms"],
				"name" : info["information"]["name"]
			}

			status = sync.sync(db.schools, unique, element)

		else:
			if "error" in info:
				error.log(__file__, False, info["error"])
			else:
				error.log(__file__, False, "Unknown Error")
	except Exception, e:
		error.log(__file__, False, str(e))
Beispiel #18
0
def importXPRSSubject(school_id, xprs_subject_id):
    try:

        objectList = context_card.xprs_subject({
            "school_id":
            school_id,
            "context_card_id":
            "XF" + str(xprs_subject_id)
        })

        if objectList["status"] == "ok":

            row = objectList["xprs_subject"]

            unique = {"xprs_subject_id": row["xprs_subject_id"]}

            notice_ids = []

            for x in row["notices"]:
                status = sync.sync(db.notices, {"name": x}, {"name": x})

                notice_ids.append(status["_id"])

            level = row["level"]

            if "-" in row["code"]:
                level = "-"

            element = {
                "xprs_subject_id": row["xprs_subject_id"],
                "context_card_id": row["context_card_id"],
                "name": row["name"],
                "code": row["code"].replace("-", ""),
                "subject_sub_type": row["subject_sub_type"],
                "level": level,
                "code_full": row["code_full"],
                "notices": row["notices"],
                "notice_ids": notice_ids,
                "code_full_name": row["code_full_name"]
            }

            status = sync.sync(db.xprs_subjects, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #19
0
def importTeamBooks ( school_id, branch_id, team_id, session = False, username = False, password = False ):
	try:
		objectList = teamBooksApi.team_books({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"team_id" : team_id,
			"username" : username,
			"password" : password
		}, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			for row in objectList["books"]:
				unique = {
					"title" : row["title"],
					"type" : row["type"]
				}

				element = {
					"title" : row["title"],
					"type" : row["type"]
				}

				status = sync.sync(db.books, unique, element)
				row["_id"] = status["_id"]
				del(row["team_id"])

			unique = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_id" : str(team_id)
			}

			element = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_id" : str(team_id),
				"books" : objectList["books"]
			}

			status = sync.sync(db.teams, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #20
0
def importExamTeam ( school_id, branch_id, test_team_id ):
	#try:
	objectList = examTeamApi.exam_team({
		"school_id" : school_id,
		"branch_id" : branch_id,
		"test_team_id" : test_team_id
	})

	if objectList is None:
		error.log(__file__, False, "Unknown Object")
		return False

	if not "status" in objectList:
		error.log(__file__, False, "Unknown Object")
		return False

	if objectList["status"] == "ok":
		row = objectList["information"]

		# Teachers
		teachers = []

		for x in row["teachers"]:
			existing = db.persons.find({"school_id" : str(school_id), "name" : x["name"], "branch_id" : str(branch_id), "abbrevation" : x["abbrevation"]})

			if existing.count() > 0:
				existing = existing[0]
				teachers.append({
					"name" : x["name"],
					"abbrevation" : x["abbrevation"],
					"_id" : existing["_id"]
				})
			else:
				teachers.append({
					"name" : x["name"],
					"abbrevation" : x["abbrevation"]
				})

		existing = db.schools.find({"school_id" : str(school_id), "branch_id" : str(branch_id)})[0]

		insitution_types = []

		if "insitution_types" in existing:
			insitution_types = existing["insitution_types"]

		if not row["gym_type"] in insitution_types:
			insitution_types.append(row["gym_type"])

		sync.sync(db.schools, {"school_id" : str(school_id), "branch_id" : str(branch_id)}, {"insitution_types" : insitution_types})

		# XPRS Subjects
		xprs = row["xprs"]

		existing = db.xprs_subjects.find({"code_full" : xprs["code_full"]})

		if existing.count() > 0:
			existing = existing[0]
			xprs["_id"] = existing["_id"]

			insitution_types = []
			test_name_codes = []
			test_types = []
			test_type_long_codes = []

			if "insitution_types" in existing:
				insitution_types = existing["insitution_types"]

			if "test_name_codes" in existing:
				test_name_codes = existing["test_name_codes"]

			if "test_types" in existing:
				test_types = existing["test_types"]

			if "test_type_long_codes" in existing:
				test_type_long_codes = existing["test_type_long_code"]

			if not row["gym_type"] in insitution_types:
				insitution_types.append(row["gym_type"])

			if not row["test_type_code"] in test_name_codes:
				test_name_codes.append(row["test_type_code"])

			if not row["xprs"]["xprs_type"] in test_types:
				test_types.append(row["xprs"]["xprs_type"])

			if not row["test_type_long_code"] in test_type_long_codes:
				test_type_long_codes.append(row["test_type_long_code"])

			element = {
				"insitution_types" : insitution_types,
				"test_name_codes" : test_name_codes,
				"test_types" : test_types,
				"test_type_long_codes" : test_type_long_codes
			}

			status = sync.sync(db.xprs_subjects, {"xprs_subject_id" : existing["xprs_subject_id"]}, element)

		censors = []

		# Censors - Connect With Insitutions Database when it arrives
		for x in row["censors"]:
			existing = db.schools.find({"$or" : [{"name" : re.compile("^" + x["institution"] + "$", re.IGNORECASE)}, {"institution" : x["institution"]}, {"institution_id" : x["institution_id"]}]})
			if existing.count() > 0:
				existing = existing[0]

				censors.append({
					"institution_id" : x["institution_id"],
					"institution" : x["institution"],
					"_id" : existing["_id"]
				})

				element = {
					"institution_id" : x["institution_id"],
					"institution" : x["institution"]
				}

				status = sync.sync(db.schools, {"school_id" : existing["school_id"]}, element)
			else:
				censors.append({
					"institution_id" : x["institution_id"],
					"institution" : x["institution"]
				})

		# Rooms
		rooms = []

		for x in row["rooms"]:
			data = {
				"alternative_name" : x["alternative_name"],
				"room_name" : x["room_name"],
				"exam_room_type" : x["exam_room_type"],
				"room_type" : x["room_type"]
			}

			existing = db.rooms.find({"name" : x["room_name"], "alternative_name" : x["alternative_name"]})

			if existing.count() > 0:
				data["_id"] = existing[0]["_id"]

			rooms.append(data)

		# Students
		students = []

		for x in row["students"]:
			data = {
				"student_class_id_full" : x["student_class_id_full"],
				"name" : x["name"],
				"in_group" : x["is_group"],
				"group_number" : x["group_number"],
				"group_time" : {
					"start" : x["group_time"]["start"],
					"end" : x["group_time"]["end"]
				},
				"examination" : {
					"start" : x["examination"]["start"],
					"end" : x["examination"]["end"]
				},
				"start" : x["start"],
				"end" : x["end"],
				"preperation_type" : x["preperation_type"],
				"preperation" : {
					"start" : x["preperation"]["start"],
					"end" : x["preperation"]["end"]
				},
				"class" : {
					"name" : x["class_name"],
					"code" : x["class_code"]
				}
			}

			classExisting = db.classes.find({"names.term" : row["term"]["value"], "names.name" : x["class_name"]})

			classObject = None

			if classExisting.count() > 0:
				classExisting = classExisting[0]
				classObject = classExisting

				data["class"]["_id"] = classExisting["_id"]

				status = sync.sync(db.classes, {"class_id" : classExisting["class_id"]}, {"name" : x["class_code"]})

			existing = db.persons.find({"$or" : [{"school_id" : str(school_id), "name" : x["name"], "class_student_id" : x["student_class_id_full"]}, {"school_id" : str(school_id), "name" : x["name"]}]})

			members = []

			if not classObject is None and "members" in classObject:
				for i in classObject["members"]:
					members.append(str(i))

			if existing.count() > 0:
				if not classObject is None and "members" in classObject:
					for match in existing:
						if str(match["_id"]) in members:
							data["_id"] = match["_id"]
				else:
					existing = existing[0]
					data["_id"] = existing["_id"]

			students.append(data)

		team = {
			"name" : row["team"]["team_class_name"],
			"team_name" : row["test_type_team_name"]
		}

		existing = db.team_elements.find({"name" : row["team"]["team_class_name"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

		if existing.count() > 0:
			existing = existing[0]
			team["_id"] = existing["_id"]

			if "team_id" in existing:
				team["team_id"] = existing["team_id"]
				status = sync.sync(db.teams, {"team_id" : existing["team_id"]}, {"name" : row["test_type_team_name"]})

		# Connect With External Censor Event

		# Exam Team
		unique = {
			"test_team_id" : str(test_team_id),
			"type" : "exam"
		}


		element = {
			"test_team_id" : str(test_team_id),
			"type" : "exam",
			"school_id" : str(school_id),
			"branch_id" : str(branch_id),
			"test_type" : row["test_type"],
			"preperation_type" : row["preperation_type"],
			"start" : row["event"]["start"],
			"end" : row["event"]["end"],
			"exam" : {
				"start" : row["time"]["start"],
				"end" : row["time"]["end"]
			},
			"preperation" : {
				"start" : row["preperation"]["start"],
				"end" : row["preperation"]["end"]
			},
			"note" : row["note"],
			"test_team_name" : row["test_team_name"],
			"group_examination" : row["group_examination"],
			"test_type" : row["test_type"],
			"number_of_students" : row["number_of_students"],
			"test_type_long_code" : row["test_type_long_code"],
			"insitution_type" : row["gym_type"],
			"test_type_team_name" : row["test_type_team_name"],
			"test_type_code" : row["test_type_code"],
			"team_element" : team,
			"xprs_test" : row["xprs_test"],
			"xprs" : xprs,
			"teachers" : teachers,
			"censors" : censors,
			"rooms" : rooms,
			"students" : students
		}

		existing = db.subjects.find({"name" : xprs["subject"]})

		if existing.count() > 0:
			element["subject_id"] = existing[0]["subject_id"]

		status = sync.sync(db.events, unique, element)

		return True
	else:
		if "error" in objectList:
			error.log(__file__, False, objectList["error"])
			db.events.remove({"test_team_id" : str("test_team_id")})
			return False
		elif "type" in objectList:
			error.log(__file__, False, objectList["type"])
			return False
		else:
			error.log(__file__, False, "Unknown error")

	'''except Exception, e:
def importFieldOfStudies ( school_id, branch_id, startYear ):
	try:
		objectList = field_of_studies({
			"school_id" : school_id,
			"branch_id" : branch_id
		}, startYear)

		if objectList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":

			for row in objectList["list"]:
				unique = {
					"field_of_study_id" : str(row["field_of_study_id"])
				}

				contextCards = []
				contextCards.append(row["context_card_id"])
				existsing = db.field_of_studies.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"study_direction_name" : unicode(str(row["study_direction_name"]).decode("utf8")),
					"gym_type" : unicode(str(row["gym_type"]).decode("utf8")),
					"start_year" : row["start_year"],
					"gym_type_short" :  unicode(str(row["gym_type_short"]).decode("utf8")),
					"field_of_study_id" : str(row["field_of_study_id"]),
					"school_id" : str(school_id),
					"branch_id" : str(branch_id),
					"name" : unicode(str(row["name"]).decode("utf8")),
					"context_cards" : contextCards,
					"main_subjects" : row["classes"]
				}

				# Classes Feature - Connection With XPRS Subjects
				# Launch Field Of Study Presentation Scraper
				status = sync.sync(db.field_of_studies, unique, element)

		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #22
0
def importAssignmentInfo ( school_id, branch_id, student_id, exercise_id, session = False, username = False, password = False ):
	try:
		objectList = assignmentInfoApi.assignment_info({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"student_id" : student_id,
			"username" : username,
			"password" : password,
			"assignment_id" : str(exercise_id)
		}, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			row = objectList["information"]

			# Uploads
			comments = []

			for comment in row["comments"]:
				data = {
					"comment" : comment["comment"],
					"user" : {
						"context_card_id" : comment["uploader"]["context_card_id"]
					},
					"date" : comment["date"]
				}

				if len(comment["file"]["entry_id"]) > 1:
					unique = {
						"entry_id" : str(comment["file"]["entry_id"])
					}

					element = {
						"entry_id" : str(comment["file"]["entry_id"]),
						"type" : comment["file"]["type"],
						"school_id" : str(school_id),
						"branch_id" : str(branch_id),
						"date" : comment["date"],
						"name" : comment["file"]["name"],
						"user" : {
							"context_card_id" : comment["uploader"]["context_card_id"]
						}
					}

					status = sync.sync(db.documents, unique, element)

					# Launch Document Scraper

					data["document_id"] = status["_id"]

				comments.append(data)

			members = []

			for member in row["members"]:
				unique = {
					"student_id" : str(member["student_id"])
				}

				contextCards = []
				contextCards.append(member["context_card_id"])
				existsing = db.persons.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"type" : "student",
					"student_id" : str(member["student_id"]),
					"name" : unicode(str(member["name"]).decode("utf8")),
					"class_student_id" : unicode(str(member["student_class_code"]).decode("utf8")),
					"context_cards" : contextCards,
					"school_id" : str(school_id),
					"branch_id" : str(branch_id)
				}

				status = sync.sync(db.persons, unique, element)

				members.append(status["_id"])

			documents = []

			for document in row["documents"]:
				unique = {
					"exercise_file_id" : str(document["exercise_file_id"])
				}

				element = {
					"school_id" : str(school_id),
					"branch_id" : str(branch_id),
					"exercise_file_id" : str(document["exercise_file_id"]),
					"type" : document["type"],
					"name" : document["name"],
					"uploaded_date_string" : document["uploaded_date_string"]
				}

				status = sync.sync(db.documents, unique, element)

				# Launch Document Scraper

				documents.append(status["_id"])

			availableStudents = []

			for student in row["group"]["available_students"]:
				unique = {
					"student_id" : str(student["student_id"])
				}

				contextCards = []
				contextCards.append("S" + student["student_id"])
				existsing = db.persons.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"type" : "student",
					"student_id" : str(student["student_id"]),
					"name" : unicode(str(student["name"]).decode("utf8")),
					"class_student_id" : unicode(str(student["student_class_code"]).decode("utf8")),
					"context_cards" : contextCards,
					"school_id" : str(school_id),
					"branch_id" : str(branch_id)
				}

				status = sync.sync(db.persons, unique, element)

				availableStudents.append(status["_id"])

			teachers = []

			for teacher in row["teachers"]:
				unique = {
					"teacher_id" : str(teacher["teacher_id"])
				}

				contextCards = []
				contextCards.append(teacher["context_card_id"])
				existsing = db.persons.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"type" : "teacher",
					"teacher_id" : str(teacher["teacher_id"]),
					"name" : unicode(str(teacher["name"]).decode("utf8")),
					"context_cards" : contextCards,
					"abbrevation" : teacher["abbrevation"],
					"school_id" : str(school_id),
					"branch_id" : str(branch_id)
				}

				status = sync.sync(db.persons, unique, element)

				teachers.append(status["_id"])

			team_elements = []

			for team_element in row["team"]:
				unique = {
					"team_element_id" : team_element["team_element_id"]
				}

				contextCards = []
				contextCards.append(team_element["context_card_id"])
				existsing = db.team_elements.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"team_element_id" : team_element["team_element_id"],
					"name" : team_element["team_element_name"],
					"context_cards" : contextCards
				}

				status = sync.sync(db.team_elements, unique, element)

				team_elements.append(status["_id"])

			unique = {
				"exercise_id" : str(exercise_id),
				"student_id" : str(student_id)
			}

			element = {
				"exercise_id" : str(exercise_id),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"student_id" : str(student_id),
				"team_elements" : team_elements,
				"student_note" : row["student"]["student_note"],
				"grade_note" : row["student"]["grade_note"],
				"status" : row["student"]["status"],
				"grade" : row["student"]["grade"],
				"leave" : row["student"]["leave"],
				"finished" : row["student"]["finished"],
				"waiting_for" : row["student"]["waiting_for"],
				"comments" : comments,
				"members" : members,
				"documents" : documents,
				"group" : {
					"available_students" : availableStudents
				},
				"title" : row["title"],
				"date" : row["date"],
				"hours" : row["student_time"],
				"grading_scale" : row["grading_scale"],
				"note" : row["note"],
				"in_instruction_detail" : str(row["in_instruction_detail"]),
				"teachers" : teachers,
				"group_assignment" : str(row["group_assignment"])
			}

			status = sync.sync(db.assignments, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #23
0
def importPrivateActivity ( school_id, branch_id, student_id, activity_id, session = False, username = False, password = False ):
	try:
		objectList = privateActivityApi.private_activity({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"student_id" : student_id,
			"username" : username,
			"password" : password,
			"activity_id" : activity_id
		}, session)

		if objectList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			row = objectList["appointment"]

			unique = {
				"activity_id" : str(activity_id),
				"type" : "private"
			}

			element = {
				"activity_id" : str(activity_id),
				"type" : "private",
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"student_id" : str(student_id),
				"title" : row["title"],
				"comment" : row["comment"],
				"start" : row["start"],
				"end" : row["end"]
			}

			status = sync.sync(db.events, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				db.events.remove({"activity_id" : str("activity_id")})
				return False
			elif "type" in objectList:
				error.log(__file__, False, objectList["type"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #24
0
def importRooms ( school_id, branch_id ):
	try:

		objectList = roomsApi.rooms({
			"school_id" : school_id,
			"branch_id" : branch_id
		})

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			for row in objectList["rooms"]:
				unique = {
					"room_id" : str(row["room_id"])
				}

				terms = []

				existsing = db.persons.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]

					if "terms" in existsing:
						terms = existsing["terms"]

				if not objectList["term"]["value"] in terms:
					terms.append(objectList["term"]["value"])

				element = {
					"room_id" : str(row["room_id"]),
					"name" : row["name"],
					"alternative_name" : row["number"],
					"school_id" : str(row["school_id"]),
					"branch_id" : str(row["branch_id"]),
					"type" : row["type"],
					"terms" : terms
				}

				status = sync.sync(db.rooms, unique, element)

				'''if sync.check_action_event(status) == True:
					for url in sync.find_listeners('room', unique):
						sync.send_event(url, status["action"], element)

					for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
						sync.send_event(url, "room", element)

					for url in sync.find_general_listeners('room_general'):
						sync.send_event(url, status["action"], element)'''

			'''deleted = sync.find_deleted(db.rooms, {"school_id" : school_id, "branch_id" : branch_id}, ["room_id"], objectList["rooms"])

			for element in deleted:
				for url in sync.find_listeners('room', {"room_id" : element["room_id"]}):
					sync.send_event(url, 'deleted', element)

				for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
					sync.send_event(url, "room_deleted", element)'''

			return True

		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #25
0
def importGrades ( school_id, branch_id, student_id, term, session = False, username = False, password = False ):
	try:
		objectList = gradesApi.grades({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"student_id" : student_id,
			"username" : username,
			"password" : password
		}, term, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			diplomaLines = []

			for row in objectList["diploma"]:
				existsing = db.xprs_subjects.find({"name" : row["subject_name"], "level" : row["subject_level"]})

				if existsing.count() > 0:
					row["xprs_subject_id"] = existsing[0]["_id"]
					row["context_card_id"] = existsing[0]["context_card_id"]

				diplomaLines.append(row)

			existsing = db.persons.find({"student_id" : str(student_id)})

			unique = {
				"student_id" : str(student_id)
			}

			if existsing.count() > 0:
				element = existsing[0]
			else:
				element = {
					"student_id" : str(student_id)
				}

			if not "grades" in element:
				element["grades"] = {}

			if not "comments" in element["grades"]:
				element["grades"]["comments"] = {}

			if not "grades" in element["grades"]:
				element["grades"]["grades"] = {}

			if not "notes" in element["grades"]:
				element["grades"]["notes"] = {}

			element["grades"]["protocol_average"] = objectList["average"]
			element["grades"]["diploma"] = diplomaLines
			element["grades"]["protocol"] = objectList["protocol_lines"]
			element["grades"]["grades"][objectList["term"]["value"]] = objectList["grades"]
			element["grades"]["comments"][objectList["term"]["value"]] = objectList["comments"]
			element["grades"]["notes"][objectList["term"]["value"]] = objectList["grade_notes"]

			status = sync.sync(db.persons, unique, element)

		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #26
0
def importBooks ( school_id, branch_id, student_id, session = False, username = False, password = False ):
	try:
		objectList = booksApi.books({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"student_id" : student_id,
			"username" : username,
			"password" : password
		}, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			books = []

			for row in objectList["loans"]:
				unique = {
					"title" : row["title"]
				}

				element = {
					"title" : row["title"],
					"price" : row["price"]
				}

				status = sync.sync(db.books, unique, element)

				row["_id"] = status["_id"]

				existing = db.team_elements.find({"name" : row["team_name"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

				if existing.count() > 0:
					if "team_id" in existing[0]:
						row["team_id"] = existing[0]["team_id"]

					row["team_element_id"] = existing[0]["team_element_id"]
				else:
					existing = db.teams.find({"name" : row["team_name"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

					if existing.count() > 0:
						row["team_id"] = existing[0]["team_id"]

				books.append(row)

			unique = {
				"student_id" : str(student_id)
			}

			element = {
				"student_id" : str(student_id),
				"books" : books
			}

			status = sync.sync(db.persons, unique, element)

		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #27
0
def importPhase ( school_id, branch_id, phase_id, session = False, username = False, password = False ):
	try:
		objectList = phaseApi.phase({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"phase_id" : phase_id,
			"username" : username,
			"password" : password,
		}, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			row = objectList["phase"]

			activities = []

			for x in row["activities"]:
				unique = {
					"activity_id" : x["activity_id"]
				}

				element = {
					"activity_id" : x["activity_id"],
					"school_id" : str(school_id),
					"branch_id" : str(branch_id)
				}

				status = sync.sync(db.events, unique, element)

				activities.append(status["_id"])

				# Launch Activity scraper

			unique = {
				"phase_id" : str(phase_id)
			}

			team_elements = []

			for x in row["teams"]:
				existsing = db.team_elements.find({"team_element_id" : x["team_element_id"]}).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					team_elements.append(existsing["_id"])

			written = []

			# TODO: Test
			for x in row["assignments"]:
				existsing = db.assignments.find({"title" : x["name"], "date" : x["date"], "team_elements" : { "$in" : team_elements}}).limit(1)

				data = {
					"title" : x["name"],
					"date" : x["date"]
				}

				if existsing.count() > 0:
					existsing = existsing[0]
					data["exercise_id"] = existsing["exercise_id"]

				written.append(data)

			created = row["created"]

			existsing = db.persons.find({"name" : str(created["teacher"]["name"]), "abbrevation" : str(created["teacher"]["abbrevation"]), "branch_id" : str(branch_id)})

			if existsing.count() > 0:
				existsing = existsing[0]

				created["teacher"]["_id"] = existsing["_id"]

			changed = row["changed"]

			existsing = db.persons.find({"name" : str(changed["teacher"]["name"]), "abbrevation" : str(changed["teacher"]["abbrevation"]), "branch_id" : str(branch_id)})

			if existsing.count() > 0:
				existsing = existsing[0]

				changed["teacher"]["_id"] = existsing["_id"]

			element = {
				"title" : row["title"],
				"phase_id" : str(phase_id),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"note" : row["note"],
				"estimate" : row["estimate"],
				"changed" : changed,
				"teams" : row["teams"],
				"skills" : row["focus_points"],
				"work_methods" : row["methods"],
				"created" : created,
				"periods" : row["periods"],
				"activities" : activities,
				"written" : written
			}

			# Launch Activity Scraper

			status = sync.sync(db.phases, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
def importTeamAccounting(school_id, branch_id, team_element_id):
    try:
        objectList = teamAccountingApi.team_accounting({
            "school_id":
            school_id,
            "branch_id":
            branch_id,
            "team_element_id":
            team_element_id
        })

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            unique = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id)
            }

            element = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id),
                "team_accounting": objectList["total"]
            }

            teachers = []

            for row in objectList["teachers"]:
                existsing = db.persons.find({
                    "name": row["name"],
                    "type": "teacher",
                    "abbrevation": row["abbrevation"]
                }).limit(1)

                if existsing.count() > 0:
                    existsing = existsing[0]
                    row["teacher_id"] = existsing["teacher_id"]

                teachers.append(row)

            element["team_accounting"]["teachers"] = teachers

            status = sync.sync(db.team_elements, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #29
0
def importGrades(school_id,
                 branch_id,
                 student_id,
                 term,
                 session=False,
                 username=False,
                 password=False):
    try:
        objectList = gradesApi.grades(
            {
                "school_id": school_id,
                "branch_id": branch_id,
                "student_id": student_id,
                "username": username,
                "password": password
            }, term, session)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            diplomaLines = []

            for row in objectList["diploma"]:
                existsing = db.xprs_subjects.find({
                    "name": row["subject_name"],
                    "level": row["subject_level"]
                })

                if existsing.count() > 0:
                    row["xprs_subject_id"] = existsing[0]["_id"]
                    row["context_card_id"] = existsing[0]["context_card_id"]

                diplomaLines.append(row)

            existsing = db.persons.find({"student_id": str(student_id)})

            unique = {"student_id": str(student_id)}

            if existsing.count() > 0:
                element = existsing[0]
            else:
                element = {"student_id": str(student_id)}

            if not "grades" in element:
                element["grades"] = {}

            if not "comments" in element["grades"]:
                element["grades"]["comments"] = {}

            if not "grades" in element["grades"]:
                element["grades"]["grades"] = {}

            if not "notes" in element["grades"]:
                element["grades"]["notes"] = {}

            element["grades"]["protocol_average"] = objectList["average"]
            element["grades"]["diploma"] = diplomaLines
            element["grades"]["protocol"] = objectList["protocol_lines"]
            element["grades"]["grades"][objectList["term"]
                                        ["value"]] = objectList["grades"]
            element["grades"]["comments"][objectList["term"]
                                          ["value"]] = objectList["comments"]
            element["grades"]["notes"][objectList["term"]
                                       ["value"]] = objectList["grade_notes"]

            status = sync.sync(db.persons, unique, element)

        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
def importTeamElementInfo(school_id, branch_id, team_element_id):
    try:
        objectList = context_card.team({
            "school_id":
            school_id,
            "branch_id":
            branch_id,
            "context_card_id":
            "HE" + str(team_element_id)
        })

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            row = objectList["team"]
            unique = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id)
            }

            classes = []

            team_type = "other"

            for x in row["classes"]:
                team_type = "elective"
                current = db.classes.find({"class_id": x["class_id"]}).limit(1)

                if current.count() > 0:
                    current = current[0]
                    if not current["_id"] in classes:
                        classes.append(current["_id"])

            existsing = db.team_elements.find(unique).limit(1)

            if existsing.count() > 0:
                existsing = existsing[0]

                if "classes" in existsing:
                    if "classes" in existsing:
                        for i in existsing["classes"]:
                            if not i in classes:
                                classes.append(i)

                classProg = re.compile(
                    r"(?P<class_name>.*) (?P<subject_abbrevation>.*)")
                classGroups = classProg.match(row["name"])

                if len(classes) == 0 and not classGroups is None:
                    current = db.classes.find({
                        "names.term":
                        existsing["term"],
                        "names.name":
                        classGroups.group("class_name")
                    }).limit(1)

                    if current.count() > 0:
                        team_type = "class_team"
                        current = current[0]
                        classes.append(current["_id"])

                if len(classes) == 1:
                    team_type = "class_team"

            element = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id),
                "name": row["name"],
                "subject_name": row["subject"],
                "active": str(row["active"]),
                "classes": classes,
                "type": row["type"],
                "team_type": team_type
            }

            # Link with subject ID

            status = sync.sync(db.team_elements, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #31
0
def importTeamBooks(school_id,
                    branch_id,
                    team_id,
                    session=False,
                    username=False,
                    password=False):
    try:
        objectList = teamBooksApi.team_books(
            {
                "school_id": school_id,
                "branch_id": branch_id,
                "team_id": team_id,
                "username": username,
                "password": password
            }, session)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            for row in objectList["books"]:
                unique = {"title": row["title"], "type": row["type"]}

                element = {"title": row["title"], "type": row["type"]}

                status = sync.sync(db.books, unique, element)
                row["_id"] = status["_id"]
                del (row["team_id"])

            unique = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_id": str(team_id)
            }

            element = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_id": str(team_id),
                "books": objectList["books"]
            }

            status = sync.sync(db.teams, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #32
0
def importPrivateTimetable ( school_id, branch_id, student_id, username, password, number_of_weeks = 1 ):
	weeksInfo = functions.weeks(number_of_weeks)

	session = authenticate.authenticate({
		"school_id" : school_id,
		"branch_id" : branch_id,
		"username" : username,
		"password" : password
	})

	if session == False:
		error.log(__file__, False, "authenticate")
		return False

	url = timetable_url("student", school_id, branch_id, student_id)

	for week in weeksInfo["weeks"]:
		# If the year has to be incremented, increment it
		if week < weeksInfo["current_week"]:
			year = weeksInfo["start_year"]+1
		else:
			year = weeksInfo["start_year"]

		weekDateTime = datetime.strptime(str(year) + "-" + str(week) + "-" + "1", "%Y-%W-%w")

		data = None

		try:
			data =  timetable.timetable({
				"school_id" : school_id,
				"student_id" : student_id,
				"branch_id" : branch_id
			}, url, int(week), int(year), session)
		except Exception, e:
			error.log(__file__, False, str(e))

		if data is None:
			error.log(__file__, False, "Unknown Object")
			return

		if not "status" in data:
			error.log(__file__, False, "Unknown Object")
			return

		if data["status"] == "ok":
			unique = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id)
			}

			element = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"module_info" : data["module_info"]
			}

			status = sync.sync(db.schools, unique, element)

			for element in data["timetable"]:
				teachers = []
				teams = []

				if element["type"] == "school":
					for row in element["teachers"]:
						status = sync.sync(db.persons, {"teacher_id" : row["teacher_id"]}, {"teacher_id" : row["teacher_id"]})

						teachers.append(status["_id"])

					for row in element["teams"]:
						status = sync.sync(db.team_elements, {"team_element_id" : row["team_id"]}, {"team_element_id" : row["team_id"]})

						teams.append(status["_id"])

					unique = {
						"activity_id" : element["activity_id"],
						#"type" : "private"
					}

					element = {
						"teachers" : teachers,
						"activity_id" : str(element["activity_id"]),
						"school_id" : str(element["school_id"]),
						"branch_id" : str(branch_id),
						"text" : element["text"],
						"status" : element["status"],
						"start" : element["startTime"],
						"end" : element["endTime"],
						"event_type" : element["type"],
						"team_elements" : teams,
						"location_text" : element["location_text"],
						"room_text" : element["room_text"],
						#"type" : "private"
					}

					status = sync.sync(db.events, unique, element)

					# Launch Activity Info Scraper

					'''if sync.check_action_event(status) == True:
						# Launch Activity Info Sraper

						for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id, "activity_id" : element["activity_id"]}):
							sync.send_event(url, "event", element)

						# Teachers
						# Teams
						# Students'''
				elif element["type"] == "exam":
					# Launch Exam Scraper
					print "Exam"
				elif element["type"] == "outgoing_censor":
					# Launch Outgoing censor scraper
					print "outgoing_censor"
				elif element["type"] == "private":
					# Launch Private scraper
					print "private"

			# Infomation Elements
			for element in data["information"]:
				if "activity_id" in element:
					unique = {
						"date" : element["date"],
						"activity_id" : element["activity_id"],
						"school_id" : school_id,
						"branch_id" : branch_id,
						"week" : week,
						"term" : data["term"]["value"]
					}

					element = {
						"date" : element["date"],
						"message" : element["message"],
						"activity_id" : element["activity_id"],
						"status" : element["status"],
						"school_id" : school_id,
						"branch_id" : branch_id,
						"week" : week,
						"term" : data["term"]["value"]
					}
				else:
					unique = {
						"date" : element["date"],
						"message" : element["message"],
						"school_id" : school_id,
						"branch_id" : branch_id,
						"week" : week,
						"term" : data["term"]["value"]
					}

					element = {
						"date" : element["date"],
						"message" : element["message"],
						"school_id" : school_id,
						"branch_id" : branch_id,
						"week" : week,
						"term" : data["term"]["value"]
					}

				status = sync.sync(db.information, unique, element)

				if sync.check_action_event(status) == True:
					for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
						sync.send_event(url, "information", element)

			# Information Elements removed
			'''deleted = sync.find_deleted(db.information, {"school_id" : school_id, "branch_id" : branch_id, "term" : data["term"]["value"]}, ["message", "date", "week", "term", "school_id", "branch_id"], data["information"])

			for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
				sync.send_event(url, "information_deleted", element)'''
		else:
			if "error" in data:
				error.log(__file__, False, data["error"])
			else:
				error.log(__file__, False, "Unknown Error")
Beispiel #33
0
def importAssignment ( school_id, branch_id, student_id, exercise_id, session = False, username = False, password = False ):
	try:
		objectList = assignmentsfoApi.assignments({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"student_id" : student_id,
			"username" : username,
			"password" : password,
		}, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			for row in objectList["list"]:

				team_elements = []

				unique = {
					"team_element_id" : row["team_element_id"]
				}

				contextCards = []
				contextCards.append(row["context_card_id"])
				existsing = db.team_elements.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"team_element_id" : row["team_element_id"],
					"name" : row["group"],
					"context_cards" : contextCards
				}

				status = sync.sync(db.team_elements, unique, element)

				team_elements.append(status["_id"])

				unique = {
					"exercise_id" : str(row["exercise_id"]),
					"student_id" : student_id
				}

				element = {
					"exercise_id" : str(row["exercise_id"]),
					"school_id" : str(school_id),
					"branch_id" : str(branch_id),
					"student_id" : str(student_id),
					"week" : row["week"],
					"title" : row["title"],
					"date" : row["date"],
					"hours" : row["hours"],
					"status" : row["status"],
					"leave" : row["leave"],
					"waiting_for" : row["waiting_for"],
					"note" : row["note"],
					"grade" : row["grade"],
					"student_note" : row["student_note"],
					"team_elements" : team_elements
				}

				status = sync.sync(db.assignments, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #34
0
def importGroupMembers(school_id,
                       branch_id,
                       team_element_id,
                       session=False,
                       username=False,
                       password=False):
    try:
        objectList = groupMembersApi.group_members(
            {
                "school_id": school_id,
                "branch_id": branch_id,
                "team_element_id": team_element_id,
                "username": username,
                "password": password
            }, session)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            members = []

            for row in objectList["objects"]:
                if row["type"] == "student":
                    unique = {"student_id": row["person_id"]}

                    contextCards = []
                    contextCards.append(row["context_card_id"])
                    existsing = db.persons.find(unique).limit(1)

                    if existsing.count() > 0:
                        existsing = existsing[0]
                        if "context_cards" in existsing:
                            for card in existsing["context_cards"]:
                                if not card in contextCards:
                                    contextCards.append(card)

                    element = {
                        "type":
                        "student",
                        "student_id":
                        row["person_id"],
                        "name":
                        unicode(str(row["full_name"]).decode("utf8")),
                        "class_student_id":
                        unicode(str(row["person_text_id"]).decode("utf8")),
                        "last_name":
                        unicode(str(row["last_name"]).decode("utf8")),
                        "first_name":
                        unicode(str(row["first_name"]).decode("utf8")),
                        "context_cards":
                        contextCards,
                        "school_id":
                        str(school_id),
                        "branch_id":
                        str(branch_id)
                    }

                    if "field_of_study" in row:
                        # Add Field of Study Sybc
                        element["field_of_study"] = {
                            "name":
                            row["field_of_study"]["name"],
                            "field_of_study_id":
                            row["field_of_study"]["field_of_study_id"]
                        }

                    if "picture_id" in row:
                        # Launch Fetch Picture Task
                        element["picture_id"] = row["picture_id"]
                else:
                    unique = {"teacher_id": row["person_id"]}

                    contextCards = []
                    contextCards.append(row["context_card_id"])
                    existsing = db.persons.find(unique).limit(1)

                    if existsing.count() > 0:
                        existsing = existsing[0]
                        if "context_cards" in existsing:
                            for card in existsing["context_cards"]:
                                if not card in contextCards:
                                    contextCards.append(card)

                    element = {
                        "teacher_id":
                        str(row["person_id"]),
                        "last_name":
                        unicode(str(row["last_name"]).decode("utf8")),
                        "first_name":
                        unicode(str(row["first_name"]).decode("utf8")),
                        "type":
                        "teacher",
                        "name":
                        unicode(str(row["full_name"]).decode("utf8")),
                        "abbrevation":
                        unicode(str(row["person_text_id"]).decode("utf8")),
                        "context_cards":
                        contextCards,
                        "school_id":
                        str(school_id),
                        "branch_id":
                        str(branch_id)
                    }

                    # Add Team to teacher

                if "picture_id" in row:
                    # Launch Fetch Picture Task
                    element["picture_id"] = row["picture_id"]

                status = sync.sync(db.persons, unique, element)

                members.append(status["_id"])

            unique = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id)
            }

            element = {
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "team_element_id": str(team_element_id),
                "members": members
            }

            status = sync.sync(db.team_elements, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")
                return False

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #35
0
def importRessources ( school_id, branch_id ):
	try:
		objectList = ressourcesApi.ressources({
			"school_id" : school_id,
			"branch_id" : branch_id
		})

		if objectList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			for row in objectList["ressources"]:
				unique = {
					"ressource_id" : str(row["ressource_id"])
				}

				terms = []

				existsing = db.persons.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]

					if "terms" in existsing:
						terms = existsing["terms"]

				if not objectList["term"]["value"] in terms:
					terms.append(objectList["term"]["value"])

				element = {
					"ressource_id" : str(row["ressource_id"]),
					"school_id" : str(row["school_id"]),
					"branch_id" : str(row["branch_id"]),
					"title" : row["title"],
					"name" : row["name"],
					"terms" : terms
				}

				status = sync.sync(db.ressources, unique, element)

				'''if sync.check_action_event(status) == True:
					for url in sync.find_listeners('ressource', unique):
						sync.send_event(url, status["action"], element)

					for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
						sync.send_event(url, "ressource", element)

					for url in sync.find_general_listeners('ressource_general'):
						sync.send_event(url, status["action"], element)'''

			deleted = sync.find_deleted(db.ressources, {"school_id" : school_id, "branch_id" : branch_id}, ["ressource_id"], objectList["ressources"])

			'''for element in deleted:
				for url in sync.find_listeners('ressource', {"ressource_id" : element["ressource_id"]}):
					sync.send_event(url, 'deleted', element)

				for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
					sync.send_event(url, "ressource_deleted", element)'''


			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #36
0
def importExamTeam(school_id, branch_id, test_team_id):
    #try:
    objectList = examTeamApi.exam_team({
        "school_id": school_id,
        "branch_id": branch_id,
        "test_team_id": test_team_id
    })

    if objectList is None:
        error.log(__file__, False, "Unknown Object")
        return False

    if not "status" in objectList:
        error.log(__file__, False, "Unknown Object")
        return False

    if objectList["status"] == "ok":
        row = objectList["information"]

        # Teachers
        teachers = []

        for x in row["teachers"]:
            existing = db.persons.find({
                "school_id": str(school_id),
                "name": x["name"],
                "branch_id": str(branch_id),
                "abbrevation": x["abbrevation"]
            })

            if existing.count() > 0:
                existing = existing[0]
                teachers.append({
                    "name": x["name"],
                    "abbrevation": x["abbrevation"],
                    "_id": existing["_id"]
                })
            else:
                teachers.append({
                    "name": x["name"],
                    "abbrevation": x["abbrevation"]
                })

        existing = db.schools.find({
            "school_id": str(school_id),
            "branch_id": str(branch_id)
        })[0]

        insitution_types = []

        if "insitution_types" in existing:
            insitution_types = existing["insitution_types"]

        if not row["gym_type"] in insitution_types:
            insitution_types.append(row["gym_type"])

        sync.sync(db.schools, {
            "school_id": str(school_id),
            "branch_id": str(branch_id)
        }, {"insitution_types": insitution_types})

        # XPRS Subjects
        xprs = row["xprs"]

        existing = db.xprs_subjects.find({"code_full": xprs["code_full"]})

        if existing.count() > 0:
            existing = existing[0]
            xprs["_id"] = existing["_id"]

            insitution_types = []
            test_name_codes = []
            test_types = []
            test_type_long_codes = []

            if "insitution_types" in existing:
                insitution_types = existing["insitution_types"]

            if "test_name_codes" in existing:
                test_name_codes = existing["test_name_codes"]

            if "test_types" in existing:
                test_types = existing["test_types"]

            if "test_type_long_codes" in existing:
                test_type_long_codes = existing["test_type_long_code"]

            if not row["gym_type"] in insitution_types:
                insitution_types.append(row["gym_type"])

            if not row["test_type_code"] in test_name_codes:
                test_name_codes.append(row["test_type_code"])

            if not row["xprs"]["xprs_type"] in test_types:
                test_types.append(row["xprs"]["xprs_type"])

            if not row["test_type_long_code"] in test_type_long_codes:
                test_type_long_codes.append(row["test_type_long_code"])

            element = {
                "insitution_types": insitution_types,
                "test_name_codes": test_name_codes,
                "test_types": test_types,
                "test_type_long_codes": test_type_long_codes
            }

            status = sync.sync(
                db.xprs_subjects,
                {"xprs_subject_id": existing["xprs_subject_id"]}, element)

        censors = []

        # Censors - Connect With Insitutions Database when it arrives
        for x in row["censors"]:
            existing = db.schools.find({
                "$or": [{
                    "name":
                    re.compile("^" + x["institution"] + "$", re.IGNORECASE)
                }, {
                    "institution": x["institution"]
                }, {
                    "institution_id": x["institution_id"]
                }]
            })
            if existing.count() > 0:
                existing = existing[0]

                censors.append({
                    "institution_id": x["institution_id"],
                    "institution": x["institution"],
                    "_id": existing["_id"]
                })

                element = {
                    "institution_id": x["institution_id"],
                    "institution": x["institution"]
                }

                status = sync.sync(db.schools,
                                   {"school_id": existing["school_id"]},
                                   element)
            else:
                censors.append({
                    "institution_id": x["institution_id"],
                    "institution": x["institution"]
                })

        # Rooms
        rooms = []

        for x in row["rooms"]:
            data = {
                "alternative_name": x["alternative_name"],
                "room_name": x["room_name"],
                "exam_room_type": x["exam_room_type"],
                "room_type": x["room_type"]
            }

            existing = db.rooms.find({
                "name": x["room_name"],
                "alternative_name": x["alternative_name"]
            })

            if existing.count() > 0:
                data["_id"] = existing[0]["_id"]

            rooms.append(data)

        # Students
        students = []

        for x in row["students"]:
            data = {
                "student_class_id_full": x["student_class_id_full"],
                "name": x["name"],
                "in_group": x["is_group"],
                "group_number": x["group_number"],
                "group_time": {
                    "start": x["group_time"]["start"],
                    "end": x["group_time"]["end"]
                },
                "examination": {
                    "start": x["examination"]["start"],
                    "end": x["examination"]["end"]
                },
                "start": x["start"],
                "end": x["end"],
                "preperation_type": x["preperation_type"],
                "preperation": {
                    "start": x["preperation"]["start"],
                    "end": x["preperation"]["end"]
                },
                "class": {
                    "name": x["class_name"],
                    "code": x["class_code"]
                }
            }

            classExisting = db.classes.find({
                "names.term": row["term"]["value"],
                "names.name": x["class_name"]
            })

            classObject = None

            if classExisting.count() > 0:
                classExisting = classExisting[0]
                classObject = classExisting

                data["class"]["_id"] = classExisting["_id"]

                status = sync.sync(db.classes,
                                   {"class_id": classExisting["class_id"]},
                                   {"name": x["class_code"]})

            existing = db.persons.find({
                "$or": [{
                    "school_id": str(school_id),
                    "name": x["name"],
                    "class_student_id": x["student_class_id_full"]
                }, {
                    "school_id": str(school_id),
                    "name": x["name"]
                }]
            })

            members = []

            if not classObject is None and "members" in classObject:
                for i in classObject["members"]:
                    members.append(str(i))

            if existing.count() > 0:
                if not classObject is None and "members" in classObject:
                    for match in existing:
                        if str(match["_id"]) in members:
                            data["_id"] = match["_id"]
                else:
                    existing = existing[0]
                    data["_id"] = existing["_id"]

            students.append(data)

        team = {
            "name": row["team"]["team_class_name"],
            "team_name": row["test_type_team_name"]
        }

        existing = db.team_elements.find({
            "name": row["team"]["team_class_name"],
            "school_id": str(school_id),
            "branch_id": str(branch_id)
        })

        if existing.count() > 0:
            existing = existing[0]
            team["_id"] = existing["_id"]

            if "team_id" in existing:
                team["team_id"] = existing["team_id"]
                status = sync.sync(db.teams, {"team_id": existing["team_id"]},
                                   {"name": row["test_type_team_name"]})

        # Connect With External Censor Event

        # Exam Team
        unique = {"test_team_id": str(test_team_id), "type": "exam"}

        element = {
            "test_team_id": str(test_team_id),
            "type": "exam",
            "school_id": str(school_id),
            "branch_id": str(branch_id),
            "test_type": row["test_type"],
            "preperation_type": row["preperation_type"],
            "start": row["event"]["start"],
            "end": row["event"]["end"],
            "exam": {
                "start": row["time"]["start"],
                "end": row["time"]["end"]
            },
            "preperation": {
                "start": row["preperation"]["start"],
                "end": row["preperation"]["end"]
            },
            "note": row["note"],
            "test_team_name": row["test_team_name"],
            "group_examination": row["group_examination"],
            "test_type": row["test_type"],
            "number_of_students": row["number_of_students"],
            "test_type_long_code": row["test_type_long_code"],
            "insitution_type": row["gym_type"],
            "test_type_team_name": row["test_type_team_name"],
            "test_type_code": row["test_type_code"],
            "team_element": team,
            "xprs_test": row["xprs_test"],
            "xprs": xprs,
            "teachers": teachers,
            "censors": censors,
            "rooms": rooms,
            "students": students
        }

        existing = db.subjects.find({"name": xprs["subject"]})

        if existing.count() > 0:
            element["subject_id"] = existing[0]["subject_id"]

        status = sync.sync(db.events, unique, element)

        return True
    else:
        if "error" in objectList:
            error.log(__file__, False, objectList["error"])
            db.events.remove({"test_team_id": str("test_team_id")})
            return False
        elif "type" in objectList:
            error.log(__file__, False, objectList["type"])
            return False
        else:
            error.log(__file__, False, "Unknown error")
    '''except Exception, e:
def importEducationDescription(school_id,
                               branch_id,
                               team_element_id,
                               session=False,
                               username=False,
                               password=False):
    try:
        objectList = descriptionApi.description(
            {
                "school_id": school_id,
                "branch_id": branch_id,
                "team_element_id": team_element_id,
                "username": username,
                "password": password,
            }, session)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            existsing = db.team_elements.find({
                "team_element_id":
                str(team_element_id)
            }).limit(1)

            team_elements = []

            if existsing.count() > 0:
                existsing = existsing[0]

                if "team_id" in existsing:
                    unique = {"team_id": str(existsing["team_id"])}

                    element = {
                        "team_id": str(existsing["team_id"]),
                        "name": objectList["information"]["team_name"],
                        "terms": objectList["information"]["terms"],
                        "subject": objectList["information"]["subject"],
                        "school_id": str(school_id),
                        "branch_id": str(branch_id),
                    }

                    existsing = db.subjects.find({
                        "name":
                        objectList["information"]["subject"]["name"]
                    }).limit(1)

                    if existsing.count() > 0:
                        existsing = existsing[0]
                        element["subject"]["subject_id"] = existsing[
                            "subject_id"]

                    status = sync.sync(db.teams, unique, element)

                    existsing = db.teams.find(unique).limit(1)[0]
                    if "team_elements" in existsing:
                        team_elements = existsing["team_elements"]

            for row in objectList["phases"]:
                documents = []

                # TODO: Add link with document DB
                for x in row["documents"]:
                    documents.append({"name": x["name"]})

                written = []

                # TODO: Test
                for x in row["written"]:
                    existsing = db.assignments.find({
                        "title": x["title"],
                        "date": x["date"],
                        "team_elements": {
                            "$in": team_elements
                        }
                    }).limit(1)

                    data = {"title": x["title"], "date": x["date"]}

                    if existsing.count() > 0:
                        existsing = existsing[0]
                        data["exercise_id"] = existsing["exercise_id"]

                    written.append(data)

                unique = {"phase_id": str(row["phase_id"])}

                element = {
                    "school_id": str(school_id),
                    "branch_id": str(branch_id),
                    "phase_id": str(row["phase_id"]),
                    "reach": row["reach"],
                    "work_methods": row["methods"],
                    "skills": row["focus_points"],
                    "links": row["links"],
                    "name": row["name"],
                    "readings": row["readings"],
                    "description": row["description"],
                    "documents": documents,
                    "planned_written": written,
                    "title": row["title"],
                    "estimate": row["estimate"]
                }

                status = sync.sync(db.phases, unique, element)

                # Launch Phase Importer

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #38
0
def importOutgoingCensor ( school_id, branch_id, outgoing_censor_id ):
	#try:
	objectList = outgoingCensorApi.outgoing_censor({
		"school_id" : school_id,
		"branch_id" : branch_id,
		"outgoing_censor_id" : outgoing_censor_id
	})

	if objectList is None:
		error.log(__file__, False, "Unknown Object")
		return False

	if not "status" in objectList:
		error.log(__file__, False, "Unknown Object")
		return False

	if objectList["status"] == "ok":
		row = objectList
		censor = {
			"name" : row["censor"]["name"],
			"abbrevation" : row["censor"]["abbrevation"]
		}

		existing = db.persons.find({"school_id" : str(school_id), "branch_id" : str(branch_id), "name" : censor["name"], "abbrevation" : censor["abbrevation"]})

		if existing.count() > 0:
			existing = existing[0]

			censor["_id"] = existing["_id"]

		institution = {
			"institution" : row["institution"]["name"],
			"institution_id" : row["institution"]["institution_id"]
		}

		# Institutions Link
		existing = db.schools.find({"$or" : [{"name" : re.compile("^" + institution["institution"] + "$", re.IGNORECASE)}, {"institution" : institution["institution"]}, {"institution_id" : institution["institution_id"]}]})
		if existing.count() > 0:
			existing = existing[0]

			institution["_id"] = existing["_id"]

			element = {
				"institution_id" : x["institution_id"],
				"institution" : x["institution"]
			}

			status = sync.sync(db.schools, {"school_id" : existing["school_id"]}, element)

		# XPRS Subjects
		xprs = row["xprs"]

		existing = db.xprs_subjects.find({"code_full" : xprs["code_full"]})

		if existing.count() > 0:
			existing = existing[0]
			xprs["_id"] = existing["_id"]

			insitution_types = []
			test_name_codes = []
			test_types = []
			test_type_long_codes = []

			if "insitution_types" in existing:
				insitution_types = existing["insitution_types"]

			if "test_name_codes" in existing:
				test_name_codes = existing["test_name_codes"]

			if "test_types" in existing:
				test_types = existing["test_types"]

			if "test_type_long_codes" in existing:
				test_type_long_codes = existing["test_type_long_codes"]

			if not xprs["gym_type"] in insitution_types:
				insitution_types.append(xprs["gym_type"])

			if not xprs["test_type_code"] in test_name_codes:
				test_name_codes.append(xprs["test_type_code"])

			if not xprs["xprs_type"] in test_types:
				test_types.append(xprs["xprs_type"])

			if not xprs["test_type_long_code"] in test_type_long_codes:
				test_type_long_codes.append(xprs["test_type_long_code"])

			element = {
				"insitution_types" : insitution_types,
				"test_name_codes" : test_name_codes,
				"test_types" : test_types,
				"test_type_long_codes" : test_type_long_codes
			}

			status = sync.sync(db.xprs_subjects, {"xprs_subject_id" : existing["xprs_subject_id"]}, element)

		unique = {
			"outgoing_censor_id" : str(outgoing_censor_id)
		}

		element = {
			"outgoing_censor_id" : str(outgoing_censor_id),
			"branch_id" : str(branch_id),
			"school_id" : str(school_id),
			"censor" : censor,
			"note" : row["note"],
			"number_of_students" : row["number_of_students"],
			"test_type_team_name" : row["test_type_team_name"],
			"test_team" : row["test_team"],
			"institution" : institution,
			"period" : row["period"],
			"xprs" : xprs,
			"subject" : {
				"name" : xprs["subject"],
				"level" : xprs["level"]
			}
		}

		if row["description"] == True:
			element["subject"] = row["information"]["subject"]
			element["terms"] = row["information"]["terms"]
			element["institution"]["name"] = row["information"]["institution"]
			element["team_name"] = row["information"]["team_name"]

			existing = db.schools.find({"name" : re.compile(r".*" + element["institution"]["name"] + ".*")})

			if existing.count() > 0:
				existing = existing[0]
				element["institution"]["school_id"] = existing["school_id"]

				teachers = []

				team = db.teams.find({"school_id" : existing["school_id"], "name" : row["information"]["team_name"]})
				print row["information"]["team_name"]
				if team.count() > 0:
					print "Team Found!"
					teams = []
					team = team[0]

					element["team_id"] = team["team_id"]

					for x in row["information"]["teams"]:
						team_element = db.team_elements.find({"$or" : [{"team_id" : team["team_id"], "name" : x["name"]}, {"name" : x["name"], "school_id" :  existing["school_id"]}]})

						if team_element.count() > 0:
							team_element = team_element[0]

							teams.append({"name" : x["name"], "_id" : team_element["_id"]})
						else:
							teams.append(x)

					element["team_elements"] = teams

				else:
					element["team_elements"] = row["information"]["teams"]

				for x in row["information"]["teachers"]:
					teacher = db.persons.find({"name" : x["name"], "school_id" : existing["school_id"]})

					if teacher.count() > 0:
						teacher = teacher[0]

						teachers.append({"name" : x["name"], "_id" : teacher["_id"]})

					else:
						teachers.append({"name" : x["name"]})

				element["teachers"] = teachers

			else:
				element["team_elements"] = row["information"]["teams"]
				element["teachers"] = row["information"]["teachers"]

		sync.sync(db.events, unique, element)

		return True
	else:
		if "error" in objectList:
			error.log(__file__, False, objectList["error"])
			db.events.remove({"outgoing_censor_id" : str("outgoing_censor_id")})
			return False
		elif "type" in objectList:
			error.log(__file__, False, objectList["type"])
			return False
		else:
			error.log(__file__, False, "Unknown error")

	'''except Exception, e:
Beispiel #39
0
def importStudents ( school_id, branch_id ):
	try:
		studentsList = studentsApi.students({
			"school_id" : school_id,
			"branch_id" : branch_id
		})

		if studentsList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in studentsList:
			error.log(__file__, False, "Unknown Object")
			return False

		if studentsList["status"] == "ok":
			for student in studentsList["students"]:
				#class_id = findClassId(student["class_name"], classList)

				unique = {
					"student_id" : str(student["student_id"])
				}

				contextCards = []
				contextCards.append(student["context_card_id"])
				existsing = db.persons.find(unique).limit(1)

				terms = []

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for row in existsing["context_cards"]:
							if not row in contextCards:
								contextCards.append(row)

					if "terms" in existsing:
						terms = existsing["terms"]

				if not studentsList["term"]["value"] in terms:
					terms.append(studentsList["term"]["value"])

				# Student element
				element = {
					"name" : unicode(str(student["name"]).decode("utf8")),
					"student_id" : str(student["student_id"]),
					"context_cards" : contextCards,
					"status" : unicode(str(student["status"]).decode("utf8")),
					"school_id" : str(student["school_id"]),
					"branch_id" : str(student["branch_id"]),
					"type" : "student",
					"terms" : terms
				}

				'''# Link student with a class
				uniqueClassStudent = {
					"class_id" : class_id,
					"class_student_id" : student["class_student_id"],
					"student_id" : student["student_id"],
					"term" : studentsList["term"]["value"],
				}

				classStudentElement = {
					"class_id" : class_id,
					"class_student_id" : student["class_student_id"],
					"student_id" : student["student_id"],
					"term" : studentsList["term"]["value"],
					"class_name" : student["class_name"]
				}'''

				status = sync.sync(db.persons, unique, element)
				#sync.sync(db.class_students, uniqueClassStudent, classStudentElement)

				'''if sync.check_action_event(status) == True:
					for url in sync.find_listeners('student', unique):
						sync.send_event(url, status["action"], element)

					for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
						sync.send_event(url, "student", element)

					for url in sync.find_general_listeners('student_general'):
						sync.send_event(url, status["action"], element)'''

			'''deleted = sync.find_deleted(db.persons, {"school_id" : school_id, "branch_id" : branch_id, "type" : "student"}, ["student_id"], studentsList["students"])

			for element in deleted:
				for url in sync.find_listeners('student', {"student_id" : element["student_id"]}):
					sync.send_event(url, 'deleted', element)

				for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
					sync.send_event(url, "student_deleted", element)'''

			return True
		else:
			if "error" in studentsList:
				error.log(__file__, False, studentsList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown Error")
				return False
	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #40
0
def importClassMembers ( school_id, branch_id, class_id, session = False, username = False, password = False ):
	try:
		objectList = class_members({
			"school_id" : school_id,
			"class_id" : class_id,
			"username" : username,
			"password" : password,
			"branch_id" : branch_id
		}, session)

		if objectList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			members = []

			for row in objectList["students"]:
				unique = {
					"student_id" : row["person_id"]
				}

				contextCards = []
				contextCards.append(row["context_card_id"])
				existsing = db.persons.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"type" : "student",
					"student_id" : row["person_id"],
					"name" : unicode(str(row["full_name"]).decode("utf8")),
					"class_student_id" : unicode(str(row["person_text_id"]).decode("utf8")),
					"last_name" : unicode(str(row["last_name"]).decode("utf8")),
					"first_name" : unicode(str(row["first_name"]).decode("utf8")),
					"context_cards" : contextCards,
					"school_id" : str(school_id),
					"branch_id" : str(branch_id)
				}

				# Add Field of Study
				element["field_of_study"] = {
					"name" : row["field_of_study"]["name"],
					"field_of_study_id" : row["field_of_study"]["field_of_study_id"]
				}

				if "picture_id" in row:
					# Launch Fetch Picture Task
					element["picture_id"] = row["picture_id"]

				status = sync.sync(db.persons, unique, element)

				members.append(status["_id"])

			for row in objectList["teachers"]:
				unique = {
					"teacher_id" : row["person_id"]
				}

				contextCards = []
				contextCards.append(row["context_card_id"])
				existsing = db.persons.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"teacher_id" : str(row["person_id"]),
					"last_name" : unicode(str(row["last_name"]).decode("utf8")),
					"first_name" : unicode(str(row["first_name"]).decode("utf8")),
					"type" : "teacher",
					"name" : unicode(str(row["full_name"]).decode("utf8")),
					"abbrevation" : unicode(str(row["person_text_id"]).decode("utf8")),
					"context_cards" : contextCards,
					"school_id" : str(school_id),
					"branch_id" : str(branch_id)
				}

				if "picture_id" in row:
					# Launch Fetch Picture Task
					element["picture_id"] = row["picture_id"]

				status = sync.sync(db.persons, unique, element)

				# Possible Teams Feature

				members.append(status["_id"])

			unique = {
				"class_id" : str(class_id)
			}

			element = {
				"members" : members,
				"class_id" : str(class_id),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id)
			}

			status = sync.sync(db.classes, unique, element)

		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #41
0
def importActivityInfo ( school_id, branch_id, student_id, activity_id, username = False, password = False, session = False ):
	modules = None

	existing = db.schools.find({"school_id" : str(school_id)}).limit(1)

	if existing.count() > 0:
		existing = existing[0]
		if "module_info" in existing:
			modules = existing["module_info"]

	try:
		objectList = activityApi.activity_info({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"activity_id" : activity_id,
			"username" : username,
			"password" : password,
		}, activity_id, session, modules)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			row = objectList

			updated = row["updated"]

			existing = db.persons.find({"school_id" : str(school_id), "branch_id" : str(branch_id), "abbrevation" : updated["by"]})

			if existing.count() > 0:
				existing = existing[0]
				updated["_id"] = existing["_id"]

			created = row["created"]

			existing = db.persons.find({"school_id" : str(school_id), "branch_id" : str(branch_id), "abbrevation" : created["by"]})

			if existing.count() > 0:
				existing = existing[0]
				created["_id"] = existing["_id"]

			rooms = []
			classes = []
			students = []
			documents = []
			ressources = []
			teachers = []
			team_elements = []
			students_education_assigned = []

			for x in row["rooms"]:
				status = sync.sync(db.rooms, {"room_id" : x["room_id"]}, {"room_id" : x["room_id"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

				rooms.append(status["_id"])

			for x in row["students"]:
				status = sync.sync(db.persons, {"student_id" : x["student_id"]}, {"student_id" : x["student_id"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

				students.append(status["_id"])

				status = sync.sync(db.classes, {"class_id" : x["class_id"]}, {"class_id" : x["class_id"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

				if not status["_id"] in classes:
					classes.append(status["_id"])

			for x in row["documents"]:
				element = {
					"document_id" : x["document_id"],
					"school_id" : str(school_id),
					"branch_id" : str(branch_id),
					"type" : x["type"],
					"size" : x["size"],
					"name" : x["name"]
				}

				status = sync.sync(db.documents, {"document_id" : x["document_id"]}, element)

				documents.append(status["_id"])

			for x in row["ressources"]:
				status = sync.sync(db.ressources, {"ressource_id" : x["ressource_id"]}, {"ressource_id" : x["ressource_id"]})

				ressources.append(status["_id"])

			for x in row["teachers"]:
				status = sync.sync(db.persons, {"teacher_id" : x["teacher_id"]}, {"teacher_id" : x["teacher_id"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

				teachers.append(status["_id"])

			for x in row["students_education_assigned"]:
				status = sync.sync(db.persons, {"student_id" : x["student_id"]}, {"student_id" : x["student_id"], "school_id" : str(school_id), "branch_id" : str(branch_id)})

				students_education_assigned.append(status["_id"])

			for x in row["teams"]:
				status = sync.sync(db.team_elements, {"team_element_id" : x["team_id"]}, {"team_element_id" : x["team_id"], "school_id" : str(school_id), "branch_id" : str(branch_id), "name" : x["name"]})

				team_elements.append(status["_id"])

			unique = {
				"activity_id" : str(activity_id)
			}

			element = {
				"activity_id" : str(activity_id),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"activity_status" : row["activity_status"],
				"event_type" : "school",
				"activity_type" : row["type"],
				"showed_at" : row["showed_at"],
				"updated" : updated,
				"created" : created,
				"students_resserved" : row["students_resserved"],
				"homework" : row["homework"],
				"links" : row["links"],
				"start" : row["date"]["start"],
				"end" : row["date"]["end"],
				"teachers" : teachers,
				"team_elements" : team_elements,
				"classes" : classes,
				"students" : students,
				"rooms" : rooms,
				"ressources" : ressources,
				"students_education_assigned" : students_education_assigned
			}

			if row["activity_status"] == "cancelled":
				element["status"] = "cancelled"

			if len(documents) > 0:
				element["documents"] = documents

			status = sync.sync(db.events, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #42
0
def importPhase(school_id,
                branch_id,
                phase_id,
                session=False,
                username=False,
                password=False):
    try:
        objectList = phaseApi.phase(
            {
                "school_id": school_id,
                "branch_id": branch_id,
                "phase_id": phase_id,
                "username": username,
                "password": password,
            }, session)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            row = objectList["phase"]

            activities = []

            for x in row["activities"]:
                unique = {"activity_id": x["activity_id"]}

                element = {
                    "activity_id": x["activity_id"],
                    "school_id": str(school_id),
                    "branch_id": str(branch_id)
                }

                status = sync.sync(db.events, unique, element)

                activities.append(status["_id"])

                # Launch Activity scraper

            unique = {"phase_id": str(phase_id)}

            team_elements = []

            for x in row["teams"]:
                existsing = db.team_elements.find({
                    "team_element_id":
                    x["team_element_id"]
                }).limit(1)

                if existsing.count() > 0:
                    existsing = existsing[0]
                    team_elements.append(existsing["_id"])

            written = []

            # TODO: Test
            for x in row["assignments"]:
                existsing = db.assignments.find({
                    "title": x["name"],
                    "date": x["date"],
                    "team_elements": {
                        "$in": team_elements
                    }
                }).limit(1)

                data = {"title": x["name"], "date": x["date"]}

                if existsing.count() > 0:
                    existsing = existsing[0]
                    data["exercise_id"] = existsing["exercise_id"]

                written.append(data)

            created = row["created"]

            existsing = db.persons.find({
                "name":
                str(created["teacher"]["name"]),
                "abbrevation":
                str(created["teacher"]["abbrevation"]),
                "branch_id":
                str(branch_id)
            })

            if existsing.count() > 0:
                existsing = existsing[0]

                created["teacher"]["_id"] = existsing["_id"]

            changed = row["changed"]

            existsing = db.persons.find({
                "name":
                str(changed["teacher"]["name"]),
                "abbrevation":
                str(changed["teacher"]["abbrevation"]),
                "branch_id":
                str(branch_id)
            })

            if existsing.count() > 0:
                existsing = existsing[0]

                changed["teacher"]["_id"] = existsing["_id"]

            element = {
                "title": row["title"],
                "phase_id": str(phase_id),
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "note": row["note"],
                "estimate": row["estimate"],
                "changed": changed,
                "teams": row["teams"],
                "skills": row["focus_points"],
                "work_methods": row["methods"],
                "created": created,
                "periods": row["periods"],
                "activities": activities,
                "written": written
            }

            # Launch Activity Scraper

            status = sync.sync(db.phases, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
def importEducationDescription ( school_id, branch_id, team_element_id, session = False, username = False, password = False ):
	try:
		objectList = descriptionApi.description({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"team_element_id" : team_element_id,
			"username" : username,
			"password" : password,
		}, session)

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			existsing = db.team_elements.find({"team_element_id" : str(team_element_id)}).limit(1)

			team_elements = []

			if existsing.count() > 0:
				existsing = existsing[0]

				if "team_id" in existsing:
					unique = {
						"team_id" : str(existsing["team_id"])
					}

					element = {
						"team_id" : str(existsing["team_id"]),
						"name" : objectList["information"]["team_name"],
						"terms" : objectList["information"]["terms"],
						"subject" : objectList["information"]["subject"],
						"school_id" : str(school_id),
						"branch_id" : str(branch_id),
					}

					existsing = db.subjects.find({"name" : objectList["information"]["subject"]["name"]}).limit(1)

					if existsing.count() > 0:
						existsing = existsing[0]
						element["subject"]["subject_id"] = existsing["subject_id"]

					status = sync.sync(db.teams, unique, element)

					existsing = db.teams.find(unique).limit(1)[0]
					if "team_elements" in existsing:
						team_elements = existsing["team_elements"]

			for row in objectList["phases"]:
				documents = []

				# TODO: Add link with document DB
				for x in row["documents"]:
					documents.append({
						"name" : x["name"]
					})

				written = []

				# TODO: Test
				for x in row["written"]:
					existsing = db.assignments.find({"title" : x["title"], "date" : x["date"], "team_elements" : { "$in" : team_elements}}).limit(1)

					data = {
						"title" : x["title"],
						"date" : x["date"]
					}

					if existsing.count() > 0:
						existsing = existsing[0]
						data["exercise_id"] = existsing["exercise_id"]

					written.append(data)

				unique = {
					"phase_id" : str(row["phase_id"])
				}

				element = {
					"school_id" : str(school_id),
					"branch_id" : str(branch_id),
					"phase_id" : str(row["phase_id"]),
					"reach" : row["reach"],
					"work_methods" : row["methods"],
					"skills" : row["focus_points"],
					"links" : row["links"],
					"name" : row["name"],
					"readings" : row["readings"],
					"description" : row["description"],
					"documents" : documents,
					"planned_written" : written,
					"title" : row["title"],
					"estimate" : row["estimate"]
				}

				status = sync.sync(db.phases, unique, element)

				# Launch Phase Importer

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #44
0
def importActivityInfo(school_id,
                       branch_id,
                       student_id,
                       activity_id,
                       username=False,
                       password=False,
                       session=False):
    modules = None

    existing = db.schools.find({"school_id": str(school_id)}).limit(1)

    if existing.count() > 0:
        existing = existing[0]
        if "module_info" in existing:
            modules = existing["module_info"]

    try:
        objectList = activityApi.activity_info(
            {
                "school_id": school_id,
                "branch_id": branch_id,
                "activity_id": activity_id,
                "username": username,
                "password": password,
            }, activity_id, session, modules)

        if objectList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in objectList:
            error.log(__file__, False, "Unknown Object")
            return False

        if objectList["status"] == "ok":
            row = objectList

            updated = row["updated"]

            existing = db.persons.find({
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "abbrevation": updated["by"]
            })

            if existing.count() > 0:
                existing = existing[0]
                updated["_id"] = existing["_id"]

            created = row["created"]

            existing = db.persons.find({
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "abbrevation": created["by"]
            })

            if existing.count() > 0:
                existing = existing[0]
                created["_id"] = existing["_id"]

            rooms = []
            classes = []
            students = []
            documents = []
            ressources = []
            teachers = []
            team_elements = []
            students_education_assigned = []

            for x in row["rooms"]:
                status = sync.sync(db.rooms, {"room_id": x["room_id"]}, {
                    "room_id": x["room_id"],
                    "school_id": str(school_id),
                    "branch_id": str(branch_id)
                })

                rooms.append(status["_id"])

            for x in row["students"]:
                status = sync.sync(db.persons, {"student_id": x["student_id"]},
                                   {
                                       "student_id": x["student_id"],
                                       "school_id": str(school_id),
                                       "branch_id": str(branch_id)
                                   })

                students.append(status["_id"])

                status = sync.sync(db.classes, {"class_id": x["class_id"]}, {
                    "class_id": x["class_id"],
                    "school_id": str(school_id),
                    "branch_id": str(branch_id)
                })

                if not status["_id"] in classes:
                    classes.append(status["_id"])

            for x in row["documents"]:
                element = {
                    "document_id": x["document_id"],
                    "school_id": str(school_id),
                    "branch_id": str(branch_id),
                    "type": x["type"],
                    "size": x["size"],
                    "name": x["name"]
                }

                status = sync.sync(db.documents,
                                   {"document_id": x["document_id"]}, element)

                documents.append(status["_id"])

            for x in row["ressources"]:
                status = sync.sync(db.ressources,
                                   {"ressource_id": x["ressource_id"]},
                                   {"ressource_id": x["ressource_id"]})

                ressources.append(status["_id"])

            for x in row["teachers"]:
                status = sync.sync(db.persons, {"teacher_id": x["teacher_id"]},
                                   {
                                       "teacher_id": x["teacher_id"],
                                       "school_id": str(school_id),
                                       "branch_id": str(branch_id)
                                   })

                teachers.append(status["_id"])

            for x in row["students_education_assigned"]:
                status = sync.sync(db.persons, {"student_id": x["student_id"]},
                                   {
                                       "student_id": x["student_id"],
                                       "school_id": str(school_id),
                                       "branch_id": str(branch_id)
                                   })

                students_education_assigned.append(status["_id"])

            for x in row["teams"]:
                status = sync.sync(db.team_elements,
                                   {"team_element_id": x["team_id"]}, {
                                       "team_element_id": x["team_id"],
                                       "school_id": str(school_id),
                                       "branch_id": str(branch_id),
                                       "name": x["name"]
                                   })

                team_elements.append(status["_id"])

            unique = {"activity_id": str(activity_id)}

            element = {
                "activity_id": str(activity_id),
                "school_id": str(school_id),
                "branch_id": str(branch_id),
                "activity_status": row["activity_status"],
                "event_type": "school",
                "activity_type": row["type"],
                "showed_at": row["showed_at"],
                "updated": updated,
                "created": created,
                "students_resserved": row["students_resserved"],
                "homework": row["homework"],
                "links": row["links"],
                "start": row["date"]["start"],
                "end": row["date"]["end"],
                "teachers": teachers,
                "team_elements": team_elements,
                "classes": classes,
                "students": students,
                "rooms": rooms,
                "ressources": ressources,
                "students_education_assigned": students_education_assigned
            }

            if row["activity_status"] == "cancelled":
                element["status"] = "cancelled"

            if len(documents) > 0:
                element["documents"] = documents

            status = sync.sync(db.events, unique, element)

            return True
        else:
            if "error" in objectList:
                error.log(__file__, False, objectList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown error")

    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #45
0
def importClassTeams ( school_id, branch_id, class_id ):
	try:
		objectList = classTeamsApi.class_teams({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"class_id" : class_id
		})

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			teams = []

			for row in objectList["teams"]:
				unique = {
					"team_element_id" : str(row["team_element_id"]),
					"school_id" : str(school_id),
					"branch_id" : str(branch_id),
				}

				element = {
					"name" : row["name"],
					"team_element_id" : str(row["team_element_id"]),
					"school_id" : str(school_id),
					"branch_id" : str(branch_id),
				}

				status = sync.sync(db.team_elements, unique, element)

				teams.append(status["_id"])

			unique = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"class_id" : str(class_id)
			}

			element = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"class_id" : str(class_id),
				"teams" : teams
			}

			status = sync.sync(db.classes, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #46
0
def importTeamInfo ( school_id, branch_id, team_element_id):
	try:
		objectList = teamInfoApi.team_info({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"team_element_id" : team_element_id,
		})

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			elementObject = objectList["information"]
			unique = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id)
			}

			element = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id),
				"team_id" : str(elementObject["team_id"])
			}

			status = sync.sync(db.team_elements, unique, element)

			unique = {
				"team_id" : str(elementObject["team_id"]),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id)
			}

			contextCards = elementObject["context_cards"]
			existsing = db.teams.find(unique).limit(1)

			if existsing.count() > 0:
				existsing = existsing[0]
				if "context_cards" in existsing:
					for card in existsing["context_cards"]:
						if not card in contextCards:
							contextCards.append(card)

			element = {
				"team_id" : str(elementObject["team_id"]),
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"context_cards" : contextCards
			}

			team_elements = []
			team_elements.append(status["_id"])

			existsing = db.teams.find(unique).limit(1)

			if existsing.count() > 0:
				existsing = existsing[0]

				if "team_elements" in existsing:
					if "team_elements" in existsing:
						for i in existsing["team_elements"]:
							if not i in team_elements:
								team_elements.append(i)

			element["team_elements"] = team_elements

			status = sync.sync(db.teams, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
Beispiel #47
0
def importTeachers(school_id, branch_id):
    try:
        teachersList = teachersApi.teachers({
            "school_id": school_id,
            "branch_id": branch_id
        })

        if teachersList is None:
            error.log(__file__, False, "Unknown Object")
            return False

        if not "status" in teachersList:
            error.log(__file__, False, "Unknown Object")
            return False

        if teachersList["status"] == "ok":
            for teacher in teachersList["teachers"]:
                unique = {"teacher_id": str(teacher["teacher_id"])}

                contextCards = []
                contextCards.append(teacher["context_card_id"])
                existsing = db.persons.find(unique).limit(1)

                terms = []

                if existsing.count() > 0:
                    existsing = existsing[0]
                    if "context_cards" in existsing:
                        for row in existsing["context_cards"]:
                            if not row in contextCards:
                                contextCards.append(row)

                    if "terms" in existsing:
                        terms = existsing["terms"]

                if not teachersList["term"]["value"] in terms:
                    terms.append(teachersList["term"]["value"])

                element = {
                    "name": unicode(str(teacher["name"]).decode("utf8")),
                    "abbrevation": unicode(teacher["initial"].decode("utf8")),
                    "context_cards": contextCards,
                    "teacher_id": str(teacher["teacher_id"]),
                    "school_id": str(teacher["school_id"]),
                    "branch_id": str(teacher["branch_id"]).replace("L", ""),
                    "type": "teacher",
                    "terms": terms
                }

                status = sync.sync(db.persons, unique, element)
                '''if sync.check_action_event(status) == True:
					# Launch Context Card Teacher Scraper, Optional

					for url in sync.find_listeners('teacher', unique):
						sync.send_event(url, status["action"], element)

					for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
						sync.send_event(url, "teacher", element)

					for url in sync.find_general_listeners('teacher_general'):
						sync.send_event(url, status["action"], element)'''
            '''deleted = sync.find_deleted(db.persons, {"school_id" : school_id, "branch_id" : branch_id, "type" : "teacher"}, ["teacher_id"], teachersList["teachers"])

			for element in deleted:
				for url in sync.find_listeners('teacher', {"teacher_id" : element["teacher_id"]}):
					sync.send_event(url, 'deleted', element)

				for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
					sync.send_event(url, "teacher_deleted", element)'''

            return True
        else:
            if "error" in teachersList:
                error.log(__file__, False, teachersList["error"])
                return False
            else:
                error.log(__file__, False, "Unknown Error")
                return False
    except Exception, e:
        error.log(__file__, False, str(e))
        return False
Beispiel #48
0
def importGroups ( school_id, branch_id ):
	try:
		objectList = groupsApi.groups({
			"school_id" : school_id,
			"branch_id" : branch_id
		})

		if objectList is None:
			error.log(__file__, False, "Unknown Object")
			return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			for row in objectList["groups"]:
				unique = {
					"team_element_id" : str(row["group_id"]),
					"term" : objectList["term"]["value"],
					"school_id" : str(row["school_id"]),
					"branch_id" : str(row["branch_id"])
				}

				contextCards = []
				contextCards.append(row["context_card_id"])
				existsing = db.team_elements.find(unique).limit(1)

				if existsing.count() > 0:
					existsing = existsing[0]
					if "context_cards" in existsing:
						for card in existsing["context_cards"]:
							if not card in contextCards:
								contextCards.append(card)

				element = {
					"team_element_id" : str(row["group_id"]),
					"school_id" : str(row["school_id"]),
					"branch_id" : str(row["branch_id"]),
					"name" : row["name"],
					"type" : row["type"],
					"group_type" : row["group_type"],
					"term" : objectList["term"]["value"],
					"type" : "group",
					"context_cards" : contextCards,
					"subject_id" : "1361688526"

				}

				status = sync.sync(db.team_elements, unique, element)

				# Launch Team Info Scraper

				'''if sync.check_action_event(status) == True:
					for url in sync.find_listeners('group', unique):
						sync.send_event(url, status["action"], element)

					for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
						sync.send_event(url, "group", element)

					for url in sync.find_general_listeners('group_general'):
						sync.send_event(url, status["action"], element)'''

			#deleted = sync.find_deleted(db.groups, {"school_id" : school_id, "branch_id" : branch_id, "term" : objectList["term"]["value"], "type" : "group"}, ["group_id"], objectList["groups"])

			'''for element in deleted:
				for url in sync.find_listeners('group', {"group_id" : element["group_id"]}):
					sync.send_event(url, 'deleted', element)

				for url in sync.find_listeners('school', {"school" : school_id, "branch_id" : branch_id}):
					sync.send_event(url, "group_deleted", element)'''

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
			else:
				error.log(__file__, False, "Unknown Error")

	except Exception, e:
		error.log(__file__, False, str(e))
		return False
def importTeamElementInfo ( school_id, branch_id, team_element_id ):
	try:
		objectList = context_card.team({
			"school_id" : school_id,
			"branch_id" : branch_id,
			"context_card_id" : "HE" + str(team_element_id)
		})

		if objectList is None:
				error.log(__file__, False, "Unknown Object")
				return False

		if not "status" in objectList:
			error.log(__file__, False, "Unknown Object")
			return False

		if objectList["status"] == "ok":
			row = objectList["team"]
			unique = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id)
			}

			classes = []

			team_type = "other"

			for x in row["classes"]:
				team_type = "elective"
				current = db.classes.find({"class_id" : x["class_id"]}).limit(1)

				if current.count() > 0:
					current = current[0]
					if not current["_id"] in classes:
						classes.append(current["_id"])

			existsing = db.team_elements.find(unique).limit(1)

			if existsing.count() > 0:
				existsing = existsing[0]

				if "classes" in existsing:
					if "classes" in existsing:
						for i in existsing["classes"]:
							if not i in classes:
								classes.append(i)

				classProg = re.compile(r"(?P<class_name>.*) (?P<subject_abbrevation>.*)")
				classGroups = classProg.match(row["name"])

				if len(classes) == 0 and not classGroups is None:
					current = db.classes.find({"names.term" : existsing["term"], "names.name" : classGroups.group("class_name")}).limit(1)

					if current.count() > 0:
						team_type = "class_team"
						current = current[0]
						classes.append(current["_id"])

				if len(classes) == 1:
					team_type = "class_team"

			element = {
				"school_id" : str(school_id),
				"branch_id" : str(branch_id),
				"team_element_id" : str(team_element_id),
				"name" : row["name"],
				"subject_name" : row["subject"],
				"active" : str(row["active"]),
				"classes" : classes,
				"type" : row["type"],
				"team_type" : team_type
			}

			# Link with subject ID

			status = sync.sync(db.team_elements, unique, element)

			return True
		else:
			if "error" in objectList:
				error.log(__file__, False, objectList["error"])
				return False
			else:
				error.log(__file__, False, "Unknown error")
				return False

	except Exception, e:
		error.log(__file__, False, str(e))
		return False