Exemplo n.º 1
0
def create_update_map(request, pk=None):

    if pk:
        map_obj = Map.objects.get(pk=pk)
    else:
        map_obj = None

    if request.method == 'POST':
        form = MapForm(request.POST, prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(request.POST,
                                             prefix='layers',
                                             instance=map_obj)

        if form.is_valid() and maplayers_formset.is_valid():
            form.save()
            maplayers_formset.save()
            return HttpResponseRedirect(reverse('job-list'))
    else:
        form = MapForm(prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj)
    return render_to_response('core/generic_form.html', {
        'form': form,
        'layer_formset': maplayers_formset,
        'custom_form': 'core/map_create.html',
        'object': map_obj,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
Arquivo: views.py Projeto: Bauerr/geoq
def create_update_map(request, pk=None):

    if pk:
        map_obj = Map.objects.get(pk=pk)
    else:
        map_obj = None

    if request.method == 'POST':
        form = MapForm(request.POST, prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(request.POST, prefix='layers', instance=map_obj)

        if form.is_valid() and maplayers_formset.is_valid():
            form.save()
            maplayers_formset.instance = form.instance
            maplayers_formset.save()
            return HttpResponseRedirect(reverse('map-list'))
    else:
        form = MapForm(prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj)
    return render_to_response('core/generic_form.html', {
        'form': form,
        'layer_formset': maplayers_formset,
        'custom_form': 'core/map_create.html',
        'object': map_obj,
        }, context_instance=RequestContext(request))
Exemplo n.º 3
0
def create_update_map(request, job_id, map_id):
    if map_id:
        map_obj = Map.objects.get(pk=map_id)
    else:
        map_obj = None

    if request.method == 'POST':
        form = MapForm(request.POST, prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(request.POST,
                                             prefix='layers',
                                             instance=map_obj)

        if form.is_valid() and maplayers_formset.is_valid():
            form.save()
            maplayers_formset.instance = form.instance
            maplayers_formset.save()
            return HttpResponseRedirect(
                reverse('job-detail', kwargs={'pk': job_id}))
    else:
        form = MapForm(prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj)

    # form = [f for f in form if f.name not in ['zoom', 'projection', 'center_x', 'center_y']]

    return render_to_response('core/generic_form.html', {
        'form': form,
        'layer_formset': maplayers_formset,
        'custom_form': 'core/map_create.html',
        'object': map_obj,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 4
0
def create_update_map(request, job_id, map_id):
    if map_id:
        map_obj = Map.objects.get(pk=map_id)
    else:
        map_obj = None

    if request.method == 'POST':
        form = MapForm(request.POST, prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(request.POST, prefix='layers', instance=map_obj)

        if form.is_valid() and maplayers_formset.is_valid():
            form.save()
            maplayers_formset.instance = form.instance
            maplayers_formset.save()
            return HttpResponseRedirect(reverse('job-detail', kwargs = {'pk': job_id}))
    else:
        form = MapForm(prefix='map', instance=map_obj)
        maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj)

    # form = [f for f in form if f.name not in ['zoom', 'projection', 'center_x', 'center_y']]

    return render_to_response('core/generic_form.html', {
        'form': form,
        'layer_formset': maplayers_formset,
        'custom_form': 'core/map_create.html',
        'object': map_obj,
        }, context_instance=RequestContext(request))
Exemplo n.º 5
0
Arquivo: views.py Projeto: Carl4/geoq
def create_map(request):

    if request.method == 'POST':
        map = MapForm(request.POST, prefix='map')
        layer_formset = MapInlineFormset(request.POST, prefix='layers')
        if map.is_valid() and layer_formset.is_valid():
            # do something with the cleaned_data on the formsets.
            m = map.save(commit=False)
            layer_formset.instance = m
            m.save()
            layer_formset.save()
            return HttpResponseRedirect(reverse('job-list'))
    else:
        map = MapForm(prefix='map')
        layer_formset = MapInlineFormset(prefix='layers')
        print layer_formset.management_form.as_p
    return render_to_response('core/generic_form.html', {
        'form': map,
        'layer_formset': layer_formset,
        'custom_form': 'core/map_create.html',
        },context_instance=RequestContext(request))