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(), })
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 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 location_filter(request): locations_filter = LocationsFilterForm(data=request.GET) locations = locations_filter.get_locations().values( 'id', 'name', ).order_by('name') json_dump = json.dumps(list(locations), cls=DjangoJSONEncoder) return HttpResponse(json_dump, content_type='application/json')
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(), })
def location_filter(request): locations_filter = LocationsFilterForm(data=request.GET) locations = locations_filter.get_locations().values('id', 'name', ).order_by('name') json_dump = json.dumps(list(locations), cls=DjangoJSONEncoder) return HttpResponse(json_dump, mimetype='application/json')