def new(request):
    locations_filter = LocationsFilterForm(data=request.GET)
    enumeration_area_form = EnumerationAreaForm(
        locations=locations_filter.get_locations())
    if request.method == 'POST':
        enumeration_area_form = EnumerationAreaForm(data=request.POST)
        if enumeration_area_form.is_valid():
            enumeration_area_form.save()
            messages.success(request, "Enumeration Area successfully created.")
            return HttpResponseRedirect(
                reverse('enumeration_area_home', args=()))
        messages.error(request, "Enumeration area was not created.")
    request.breadcrumbs([
        ('Enumeration Areas', reverse('enumeration_area_home')),
    ])
    return render(
        request, 'enumeration_area/new.html', {
            'enumeration_area_form': enumeration_area_form,
            'locations_filter': locations_filter,
            'title': 'New Enumeration Area',
            'button_label': 'Create',
            'action': reverse('new_enumeration_area_page', args=()),
            'location_filter_types': LocationType.in_between(),
            'redirect_url': '/enumeration_area'
        })
def edit(request, ea_id):
    ea = get_object_or_404(EnumerationArea, pk=ea_id)
    if request.GET:
        data = request.GET
    else:
        data = dict([(loc.type.name, loc.pk) for loc in ea.parent_locations()])
    locations_filter = LocationsFilterForm(data=data)
    enumeration_area_form = EnumerationAreaForm(
        instance=ea, locations=locations_filter.get_locations())
    if request.method == 'POST':
        enumeration_area_form = EnumerationAreaForm(
            data=request.POST,
            instance=ea,
            locations=locations_filter.get_locations())

        if enumeration_area_form.is_valid():
            enumeration_area_form.save()
            messages.success(request, "Enumeration Area successfully Changed.")
            return HttpResponseRedirect(
                reverse('enumeration_area_home', args=()))
        messages.error(request, "Enumeration area was not Changed.")
    request.breadcrumbs([
        ('Enumeration Areas', reverse('enumeration_area_home')),
    ])
    return render(
        request, 'enumeration_area/new.html', {
            'enumeration_area_form': enumeration_area_form,
            'locations_filter': locations_filter,
            'title': 'New Enumeration Area',
            'button_label': 'Create',
            'action': reverse('edit_enumeration_area_page', args=(ea_id, )),
            'location_filter_types': LocationType.in_between(),
        })
Exemplo n.º 3
0
def new(request):
    locations_filter = LocationsFilterForm(data=request.GET)
    enumeration_area_form = EnumerationAreaForm(
        locations=locations_filter.get_locations())
    if request.method == 'POST':
        enumeration_area_form = EnumerationAreaForm(data=request.POST)
        if enumeration_area_form.is_valid():
            enumeration_area_form.save()
            messages.success(request, "Enumeration Area successfully created.")
            return HttpResponseRedirect(
                reverse('enumeration_area_home', args=()))
        messages.error(request, "Enumeration area was not created.")
    request.breadcrumbs([
        ('Enumeration Areas', reverse('enumeration_area_home')),
    ])
    return render(request,
                  'enumeration_area/new.html',
                  {'enumeration_area_form': enumeration_area_form,
                   'locations_filter': locations_filter,
                   'title': 'New Enumeration Area',
                   'button_label': 'Create',
                   'action': reverse('new_enumeration_area_page',
                                     args=()),
                   'location_filter_types': LocationType.in_between(),
                   'redirect_url': '/enumeration_area'})
Exemplo n.º 4
0
def edit(request, ea_id):
    locations_filter = LocationsFilterForm(data=request.GET)
    ea = get_object_or_404(EnumerationArea, pk=ea_id)
    enumeration_area_form = EnumerationAreaForm(instance=ea, locations=locations_filter.get_locations())
    if request.method == 'POST':
        enumeration_area_form = EnumerationAreaForm(data=request.POST, instance=ea)

        if enumeration_area_form.is_valid():
            enumeration_area_form.save()
            messages.success(request, "Enumeration Area successfully Changed.")
            return HttpResponseRedirect(reverse('enumeration_area_home', args=()))
        messages.error(request, "Enumeration area was not Changed.")
    request.breadcrumbs([
        ('Enumeration Areas', reverse('enumeration_area_home')),
#         (_('%s %s') % (action.title(),model.title()),'/crud/%s/%s' % (model,action)),
    ])
    return render(request, 'enumeration_area/new.html',
                  {'enumeration_area_form': enumeration_area_form, 'locations_filter' : locations_filter, 'title': 'New Enumeration Area', 'button_label': 'Create',
                   'action': reverse('edit_enumeration_area_page', args=(ea_id, )), 
                   'location_filter_types' : LocationType.in_between(),
                   })