Esempio n. 1
0
def get_school(code):
    schools = School.objects(code=code)
    if len(schools) == 0:
        return jsonify(message='No school found'), 404
    response = {}
    school = schools.first()
    for key in school:
        response[key] = school[key]
    return jsonify(response), 200
Esempio n. 2
0
def get_all_schools():
    schools = School.objects()
    response = []
    for school in schools:
        temp = {}
        for key in school:
            temp[key] = school[key]
        response.append(temp)
    return jsonify(response), 200
Esempio n. 3
0
def school_list(level):
    search = False
    temp_level = level
    if level == 'special':
        temp_level = 'specific'
    query = request.args.get('query')
    if query:
        search = True
        schools = School.objects(level__icontains=temp_level, name__icontains=query)
    else:
        schools = School.objects(level__icontains=temp_level)
    schools = schools.order_by('-enrolments')
    page, per_page, offset = get_page_args()
    per_page *= 5
    offset *= 5
    pagination_schools = schools[offset: offset + per_page]
    pagination = Pagination(page=page, per_page=per_page, total=schools.count(), record_name="schools",
                            css_framework="bootstrap4", alignment="center", search=search, found=schools.count())
    return render_template("school_list.html", schools=pagination_schools, level=level, pagination=pagination)
def get_all_school_data():
    qs = School.objects()
    entries = []
    for school in qs:
        entries.append({'school_name': school.school_name,
                        'lga_name': school.lga_name,
                        'post_code': school.post_code,
                        'latitude': school.latitude,
                        'longitude': school.longitude,
                        'school_type': school.school_type})
    return jsonify(title='NSW School Data',
                   id=request.base_url,
                   entry=entries), 200
Esempio n. 5
0
def compare_schools():
    codes = request.args.getlist('code')
    if len(codes) == 0:
        return jsonify(message='No input'), 204
    schools = School.objects(code__in=codes)
    if len(schools) == 0:
        return jsonify(message='No schools found matching the codes'), 404
    response = []
    for school in schools:
        temp = {}
        for key in school:
            temp[key] = school[key]
        response.append(temp)
    return jsonify(response), 200
def get_school_data_by_lga(lga_name):
    qs = School.objects(lga_name=lga_name)
    entries = []
    if qs.count() != 0:
        for school in qs:
            entries.append({'school_name': school.school_name,
                            'post_code': school.post_code,
                            'latitude': school.latitude,
                            'longitude': school.longitude,
                            'school_type': school.school_type})
        return jsonify(title='School Data in {} Local Government Area'.format(lga_name),
                       lga_name=lga_name,
                       id=request.base_url,
                       entry=entries), 200
    else:
        return "LGA name not found.", 404
Esempio n. 7
0
def school_list():
    if request.args.get("name"):
        schools = School.objects(name__contains = request.args.get("name").upper())
    else:
        schools = School.objects

    json = []

    for school in list(schools):
        city = school.city.name if school.city else ""
        state = school.state.acronym if school.state else ""

        json.append({
            "id": school.code,
            "text": "%s (%s / %s)" % (school.name, city, state)
        })

    return jsonify({ "schools": json })