示例#1
0
文件: views.py 项目: Cheekio/glean
def newCounty(request):
	if request.method == "POST":
		form = CountyForm(request.POST)
		if form.is_valid():
			new_save = County(**form.cleaned_data)
			new_save.save()
			return HttpResponseRedirect(reverse('counties:detailcounty', args=(new_save.id,) ))
		else:
			return render(request, 'counties/new_county.html', {'form':form, 'error':'Your County Form Was Not Valid'})
	else:
		form = CountyForm()
		return render(request, 'counties/new_county.html', {'form':form})
示例#2
0
文件: views.py 项目: Cheekio/glean
def editCounty(request, county_id):
	county = get_object_or_404(County, pk=county_id)
	if request.method == "POST":
		form = CountyForm(request.POST)
		if form.is_valid():
			new_save = County(**form.cleaned_data)
			new_save.id = county_id
			new_save.save()
			return HttpResponseRedirect(reverse('counties:index'))
		else:
			return render(request, 'counties/edit_county.html', {'form':form, 'county':county, 'error':'form needs some work', 'editmode':True})
	form = CountyForm(instance = county)

	return render(request, 'counties/edit_county.html', {'form':form, 'county':county, 'editmode':True})
示例#3
0
        row_dict = {}
        for index, column in enumerate(row):
            key = header[index]
            print(key)
            row_dict.update({key: column})
        print(row_dict)
        counties.append(row_dict)
    print(counties)
    for county in counties:
        print('bouta save this county')
        print(county)
        county_name = re.sub(r'^ County$', '', county['county_name'])
        county_name
        c = County(fips=county['county_fips'],
                   name=county['county_name'].replace(' County', ''),
                   state=county['state'],
                   state_fips=county['state_fips'],
                   fips_class=county['fips_class'])
        c.save()
    print('something good happened')

# import geojson for all the counties
import json
import pprint
with open('counties/scripts/ms-counties.json') as json_file:
    ms = County.objects.get(pk='000')
    data = json.load(json_file)
    ms_geo_json = CountyBorderGeoJSON(county=ms, geojson=data)
    ms_geo_json.save()
    print('ms geojson saved')