-
-
Save bengolder/3289684 to your computer and use it in GitHub Desktop.
forms 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#from forms.py | |
class LayerReviewForm(forms.ModelForm): | |
"""For editing and configuring the layer information for each layer.""" | |
class Meta: | |
model = DataLayer | |
# we should get geometry_type from the shp file. Users can't | |
# change it. | |
fields = ['name', 'notes', 'srs','geometry_type'] | |
#from views.py | |
@login_required | |
def review(request): | |
"""A view for uploading new data. | |
""" | |
user=User.objects.get(username='carlos') | |
if request.method == 'POST': # someone is giving us data | |
formset = LayerReviewFormSet(request.POST) | |
if formset.is_valid(): | |
for form in formset: | |
# this line will give us a DataLayer object, but it won't be | |
# saved to the database. | |
# it will add any information given in the form, including | |
# geometry_type, srs, and name | |
layer = form.save(commit=False) | |
# This layer has not been committed to the database | |
# here we can do other things if we like | |
# and then we can save it to the database | |
layer.save() | |
else: # we are asking them to review data | |
# get the last upload of this user | |
upload = UploadEvent.objects.filter(user=user).order_by('-date')[0] | |
data_files = DataFile.objects.filter(upload=upload) | |
# maybe we should get the geometry type as well when we get the layer | |
# data | |
layer_data = [ f.get_layer_data() for f in data_files ] | |
formset = LayerReviewFormSet( initial=layer_data ) | |
c = { | |
'formset':formset, | |
} | |
return render_to_response( | |
'webfinches/review.html', | |
RequestContext(request, c), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def review(request):