예제 #1
0
파일: views.py 프로젝트: imclab/upwardly
def overview(request, location, compare_to, comparison, **kwargs):

    occupation_id = kwargs.get('occupation_id', None)

    if not occupation_id:
        occupation_id = request.preferences.occupation_id
        occupation = request.preferences['occupation']
    else:
        occupation = {
            'id': occupation_id,
            'name': get_occupation_name(occupation_id),
        }

    chart_data = {
        'salary': json.dumps(charts.salary_graph(occupation_id, location, compare_to)),
        'housing': json.dumps(charts.rpp_graph('housing_goods', occupation_id, location, compare_to)),
        'education': json.dumps(charts.rpp_graph('education_services', occupation_id, location, compare_to)),
        'recreation': json.dumps(charts.rpp_graph('recreation_services', occupation_id, location, compare_to)),
    }

    context = {
        'location': location,
        'compare_to': compare_to,
        'comparison': comparison,
        'occupation': occupation,
        'chart_data': chart_data,
    }
    return render(request, 'locations/overview.html', context)
예제 #2
0
파일: views.py 프로젝트: imclab/upwardly
def filter(request):

    if request.method == 'POST':
        pass

    occupation_id = request.GET.get('occ', None) or request.preferences.occupation_id
    pref_location = request.preferences.get('location', None)

    if pref_location is None:
        pref_location = {
            'zipcode': '00000',
            'name': 'United States',
            'id': '00000',
        }

    weights = request.preferences['weights']

    locations = location_scores(occupation_id, pref_location['id'], weights)
    score = location_score(occupation_id, pref_location['id'], weights)

    occupation = {
        'id': occupation_id,
        'name': get_occupation_name(occupation_id),
    }

    return render(request, 'results.html', {
        'locations': locations,
        'current_location': pref_location,
        'score': score,
        'occupation': occupation,
    })
예제 #3
0
    def process_request(self, request):

        # delete current preferences and reset to default

        if 'resetprefs' in request.GET and 'preferences' in request.session:
            del request.session['preferences']

        # if user preferences are of an older version, replace with default
        # they'll just have to deal

        if 'preferences' not in request.session or request.session['preferences'].get('version', None) != Preferences.version:
            request.session['preferences'] = Preferences({
                'version': Preferences.version,
                'current_location': None,
                'category': None,
                'occupation': None,
                'weights': DEFAULT_WEIGHTS,
            })

        # POST is intended to update user preferences

        if 'update_preferences' in request.POST:

            if 'zipcode' in request.POST:

                zipcode = request.POST['zipcode']
                loc = location_from_zip(zipcode)

                if loc:

                    request.session['preferences']['location'] = {
                        'zipcode': request.POST['zipcode'],
                        'name': loc['name'],
                        'id': loc['code'],
                    }

            if 'occupation' in request.POST:

                occ_id = request.POST['occupation']
                cat_id = occ_id.split('-')[0]

                if occ_id and cat_id:

                    request.session['preferences']['category'] = {
                        'id': cat_id,
                    }
                    request.session['preferences']['occupation'] = {
                        'id': occ_id,
                        'category': cat_id,
                        'name': get_occupation_name(occ_id) or 'Hard Worker',
                    }

            request.session['preferences']['weights'] = DEFAULT_WEIGHTS.copy()
            request.session['preferences']['selected_weights'] = None

            if 'weights' in request.POST:

                selected_weights = request.POST.getlist('weights')

                request.session['preferences']['selected_weights'] = selected_weights

                for weight, default_value in DEFAULT_WEIGHTS.iteritems():

                    if weight in selected_weights:
                        request.session['preferences']['weights'][weight] = default_value * 2
                    else:
                        request.session['preferences']['weights'][weight] = default_value

            request.session.modified = True

        request.preferences = request.session['preferences']