Esempio n. 1
0
def index(request):
    #Getting the session
    session = get_session()
    schools = {}
    template_name = 'leaguetable/homepage.html'
    geo_level = "country"
    geo_code = "TZ"

    if request.method == 'POST':
        try:
            params = json.loads(request.body)
            year = params['year'].encode("utf8")
            schools = get_overall_topschools(year, geo_level, geo_code,
                                             session)

        finally:
            session.close()

        return HttpResponse(json.dumps({'schools': schools}),
                            content_type='application/json')
    else:
        year = '2017'
        #Getting Schools from overall top schools method
        try:
            schools = get_overall_topschools(year, geo_level, geo_code,
                                             session)
        finally:
            session.close()

        return render(request, 'leaguetable/homepage.html', {
            'schools': schools,
            'root_geo': geo_data.root_geography()
        })
Esempio n. 2
0
def index(request):
    #Getting the session
    session = get_session()
    schools = {}
    template_name = 'leaguetable/homepage.html'
    geo_level = "country"
    geo_code = "TZ"

    #Sorting will only be done using national_rank all, as regional and district ranks are unknown for some result esp historical
    rank_column = Base.metadata.tables['secondary_school'].c.national_rank_all

    # Getting top for schools with more than 40 students
    top_schools_40_more = session.query(Base.metadata.tables['secondary_school'])\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_level == geo_level)\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_code == geo_code)\
                    .filter(Base.metadata.tables['secondary_school'].c.more_than_40 == "yes")\
                    .order_by(asc(cast(rank_column, Integer)))\
                    .all()
    # Getting top for schools with less than 40 students
    top_schools_40_less = session.query(Base.metadata.tables['secondary_school'])\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_level == geo_level)\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_code == geo_code)\
                    .filter(Base.metadata.tables['secondary_school'].c.more_than_40 == "no")\
                    .order_by(asc(cast(rank_column, Integer)))\
                    .all()

    # Getting lowest schools with more than 40 students
    lowest_schools_40_more = session.query(Base.metadata.tables['secondary_school'])\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_level == geo_level)\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_code == geo_code)\
                    .filter(Base.metadata.tables['secondary_school'].c.more_than_40 == "yes")\
                    .order_by(desc(cast(rank_column, Integer)))\
                    .all()
    # Getting lowest for schools with less than 40 students
    lowest_schools_40_less = session.query(Base.metadata.tables['secondary_school'])\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_level == geo_level)\
                    .filter(Base.metadata.tables['secondary_school'].c.geo_code == geo_code)\
                    .filter(Base.metadata.tables['secondary_school'].c.more_than_40 == "no")\
                    .order_by(desc(cast(rank_column, Integer)))\
                    .all()

    schools['best_schools_more_40'] = top_schools_40_more
    schools['worst_schools_more_40'] = lowest_schools_40_more
    schools['best_schools_less_40'] = top_schools_40_less
    schools['worst_schools_less_40'] = lowest_schools_40_less

    return render(request, 'leaguetable/homepage.html', {
        'schools': schools,
        'root_geo': geo_data.root_geography()
    })
Esempio n. 3
0
 def get_context_data(self, *args, **kwargs):
     return {
         'root_geo': geo_data.root_geography(),
     }
Esempio n. 4
0
 def get_context_data(self, *args, **kwargs):
     return {
         'root_geo': geo_data.root_geography(),
     }
Esempio n. 5
0
def index(request):
    #Getting the session
    session = get_session()
    schools = {}
    template_name = 'leaguetable/homepage.html'
    geo_level = "country"
    geo_code = "TZ"

    if request.method == 'POST':
        try:
            params = json.loads(request.body)
            year = params['year'].encode("utf8")
            schools = get_overall_topschools(year, geo_level, geo_code, session)

        finally:
            session.close()

        return HttpResponse(json.dumps({'schools': schools}), content_type='application/json')
    else:
        year = '2017'
        #Getting Schools from overall top schools method
        try:
            schools = get_overall_topschools(year, geo_level, geo_code, session)
        finally:
            session.close()

        return render(request,'leaguetable/homepage.html',{'schools':schools, 'root_geo': geo_data.root_geography()})