Exemple #1
0
def explore(request, *args, **kwargs):
    """
      Show a list of maps. If the user has not used the
      filter options we shall display the last recent maps,
      otherwise we use the filtered maps.
    """
    data = request.POST if request.method=='POST' else None
    form    = FilterMapsForm(data=data)

    qs = DataSet.objects\
                .filter(get_public_data_set_querset(request.user))\
                .order_by('-date_created')

    if form.is_valid() and form.is_active():
        maps = form.filtered_results(qs)
    else:
        maps = qs.order_by('-date_created')

    kwargs.update( {
        'paginate_by': 16,
        'template_name': 'statmap/explore.html',
        'template_object_name': 'map',
    })

    return object_list(request, extra_context={'form': form }, queryset=maps, *args, **kwargs)
Exemple #2
0
def data_set_list(request, region_set_slug):
    """
        Methods return a JSON list for the available datasets for this
        region set.

        .. code-block:: js
            {
                'dataset':
                [
                    { 'slug': '...', 'value': '...'},
                    { 'slug': '...', 'value': '.. },
                    ..
                ]
            }
    """
    try:
        region_set = RegionSet.visible_objects.get(slug=region_set_slug)
    except RegionSet.DoesNotExist:
        raise Http404('Region set does not exist')

    q = get_public_data_set_querset(request.user)

    data_sets = region_set.data_sets\
                           .filter(q) \
                           .values('title', 'slug')
                       
    
    response = HttpResponse(mimetype='application/json')
    json.dump(list(data_sets), response)

    return response
Exemple #3
0
def save(request):
    """
        Requires a post variabel `data`

        Returns a JSON file in the following format:

        .. code ::
            {
                'id': 'the id of the dataset',
                'status': 'success|error',
                'message': 'textual repr. of error / form errors dump',
            }

        `message` and `error_code` will be left out if there
        are no errors.
    """
    if request.user.is_authenticated():
        form = MappingForm(data=request.POST, user=request.user)
        if form.is_valid():
            data_set = form.save()

            json_response = {
                'status': 'success',
                'dataset': data_set.slug,

            }

            json_response['data_sets'] = list(DataSet.objects\
                           .filter(get_public_data_set_querset(request.user))
                           .filter(regionset=data_set.regionset)\
                           .values('title', 'slug'))
        else:
            json_response = {
                'status': 'error',
                'errors': form.errors,
            }
    else:
        json_response = {
            'status': 'error',
            'messages': "You are not signed in",
        }




    response = HttpResponse()
    json.dump(json_response, response)
    return response