Exemple #1
0
 def populate_mongodb(self):
     if settings.MONGODB_HOST == self.mongo_host and \
        settings.MONGODB_USERNAME == self.mongo_username and \
        settings.MONGODB_PASSWORD == self.mongo_password:
         mongo = Mongo('institutions')
         result = mongo.get_one(
             {'institution_id': str(self.institution_id)})
         if result is None:
             management.call_command('populate_institutions')
             management.call_command('populate_courses')
def load_institution_data(institution_id):

    if settings.LOCAL:
        return InstitutionMocks.get_successful_institution_load_response()
    if settings.MONGODB_HOST:
        mongo = Mongo('institutions')
        return mongo.get_one({'institution_id': str(institution_id)})
    else:
        headers = {'Ocp-Apim-Subscription-Key': settings.DATASETAPIKEY}
        base_url = "%s/institutions/%s"

        return requests.get(url=base_url %
                            (settings.DATASETAPIHOST, institution_id),
                            headers=headers)
def load_course_data(institution_id, course_id, mode):
    if settings.LOCAL:
        if course_id == "GN12":
            return JointCourseFormatMocks.get_successful_course_load_response()
        return CourseFormatMocks.get_successful_course_load_response()
    if settings.MONGODB_HOST:
        mongo = Mongo('courses')
        return mongo.get_one({
            'institution_id': str(institution_id),
            'course_id': str(course_id),
        })
    else:
        headers = {'Ocp-Apim-Subscription-Key': settings.DATASETAPIKEY}
        base_url = "%s/institutions/%s/courses/%s/modes/%s"

        response = requests.get(
            url=base_url %
            (settings.DATASETAPIHOST, institution_id, course_id, mode),
            headers=headers)
        return response