예제 #1
0
    def test_increment_locations(self):

        from django.conf import settings
        settings.REDIS_ANALYTICS_DATABASE = 15

        from analytics.shortcuts import increment_locations
        increment_locations("Edinburgh", account=self.account)
        increment_locations("Edinburgh")
예제 #2
0
    def test_increment_locations(self):

        from django.conf import settings
        settings.REDIS_ANALYTICS_DATABASE = 15

        from analytics.shortcuts import increment_locations
        increment_locations("Edinburgh", account=self.account)
        increment_locations("Edinburgh")
예제 #3
0
def resource_find(request, template_name='depot/resource_find.html'):
    """docstring for resource_find"""
    results = []
    pt_results = {}
    centres = None
    new_search = False

    result = request.REQUEST.get('result', '')
    if request.method == 'POST' or result:
        if result == 'Cancel':
            return HttpResponseRedirect(reverse('resource_list'))
        form = FindResourceForm(request.REQUEST)
        if form.is_valid():
            user = get_account(request.user.id)

            # print request.META.get("ENGINE_LOG")
            increment_queries(form.cleaned_data['kwords'], account=user)
            # print form.centre['loc'] if form.centre else None
            increment_locations(
                unicode(form.centre['loc']) if form.centre else None,
                account=user)

            for result in form.results:
                resource = get_one_or_404(Resource,
                                          id=ObjectId(result['res_id']))
                result['resource'] = resource
                if 'pt_location' in result:
                    pt_results.setdefault(
                        tuple(result['pt_location'][0].split(', ')),
                        []).append((result['res_id'], result['title']))
            centres = [form.centre] if form.centre else []
    else:
        form = FindResourceForm(
            initial={'boost_location': settings.SOLR_LOC_BOOST_DEFAULT})
        new_search = True

    # hack cos map not showing if no centre point
    # map should show if pt_results anyway, but not happening
    # see also accounts.view.accounts_find

    # just north of Perth
    # default_centres = [{'location': ('56.5', '-3.5')}]

    context = {
        'next': urlquote_plus(request.get_full_path()),
        'form': form,
        'results': form.results,
        'pt_results': pt_results,
        'centres': centres,  # or default_centres if pt_results else None,
        'google_key': settings.GOOGLE_KEY,
        'show_map': bool(centres or pt_results),
        'new_search': new_search
    }
    return render_to_response(template_name, RequestContext(request, context))
예제 #4
0
def accounts_find(request, template_name='accounts/accounts_find.html'):
    """docstring for accounts_find"""
    results = []
    pt_results = {}
    centres = None
    new_search = False

    result = request.REQUEST.get('result', '')
    if request.method == 'POST' or result:
        pass
        if result == 'Cancel':
            return HttpResponseRedirect(reverse('resource_list'))
        form = FindAccountForm(request.REQUEST)
        if form.is_valid():
            user = get_account(request.user.id)

            increment_queries(form.cleaned_data['kwords'], account=user)
            increment_locations(form.cleaned_data['post_code'], account=user)

            for result in form.results:
                acct = get_one_or_404(Account, id=ObjectId(result['res_id']))
                result['resource'] = acct
                results.append({'resource_result': result})
                if 'pt_location' in result:
                    pt_results.setdefault(tuple(result['pt_location'][0].split(', ')), []).append((result['res_id'], result['title']))
            centres = [form.centre] if form.centre else []
    else:
        form = FindAccountForm(initial={'boost_location': settings.SOLR_LOC_BOOST_DEFAULT})
        new_search = True

    # hack cos map not showing if no centre point
    # map should show if pt_results anyway, but not happening
    # see also resources.view.resource_find

    # just north of Perth
    # default_centres = [{'location': ('56.5', '-3.5')}]

    context = {
        'next': urlquote_plus(request.get_full_path()),
        'form': form,
        'results': results,
        'pt_results': pt_results,
        'centres': centres, # or default_centres if pt_results else None,
        'google_key': settings.GOOGLE_KEY,
        'show_map': bool(centres or pt_results),
        'new_search': new_search
    }
    return render_to_response(template_name, RequestContext(request, context))
예제 #5
0
def resource_find(request, template_name='depot/resource_find.html'):
    """docstring for resource_find"""
    results = []
    pt_results = {}
    centre = None
    new_search = False

    result = request.REQUEST.get('result', '')
    if request.method == 'POST' or result:
        if result == 'Cancel':
            return HttpResponseRedirect(reverse('resource_list'))
        form = FindResourceForm(request.REQUEST)
        if form.is_valid():
            user = get_account(request.user.id)

            increment_queries(form.cleaned_data['kwords'], account=user)
            # print form.centre['loc'] if form.centre else None
            increment_locations(unicode(form.centre['loc']) if form.centre else None, account=user)

            for result in form.results:
                resource = get_one_or_404(Resource, id=ObjectId(result['res_id']))
                result['resource'] = resource
                # try:
                #     curation_index, curation = get_curation_for_user_resource(user, resource)
                #     print curation
                # except TypeError:
                #     curation_index = curation = None

                # curation_form = CurationForm(
                #         initial={'outcome': STATUS_OK},
                #         instance=curation)
                # resource_report_form = ResourceReportForm()
                # results.append({
                #     'resource_result': result,
                #     'curation': curation,
                #     'curation_form': curation_form,
                #     'resource_report_form': resource_report_form,
                #     'curation_index': curation_index
                # })
                if 'pt_location' in result:
                    pt_results.setdefault(tuple(result['pt_location'][0].split(', ')), []).append((result['res_id'], result['title']))
            centre = form.centre
    else:
        form = FindResourceForm(initial={'boost_location': settings.SOLR_LOC_BOOST_DEFAULT})
        new_search = True

    # hack cos map not showing if no centre point
    # map should show if pt_results anyway, but not happening
    # see also accounts.view.accounts_find

    # just north of Perth
    default_centre = {'location': ('56.5', '-3.5')}

    context = {
        'next': urlquote_plus(request.get_full_path()),
        'form': form,
        'results': form.results,
        'pt_results': pt_results,
        'centre': centre or default_centre if pt_results else None,
        'google_key': settings.GOOGLE_KEY,
        'show_map': pt_results,
        'new_search': new_search
    }
    return render_to_response(template_name, RequestContext(request, context))