Created
August 7, 2012 00:44
-
-
Save cesandoval/3280057 to your computer and use it in GitHub Desktop.
forms - models
This file contains 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
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, request.FILES) | |
for form in formset: | |
print 'reviewing form' | |
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) | |
layer_data = [ f.get_layer_data() for f in data_files ] | |
#print layer_data | |
formset = LayerReviewFormSet( initial=layer_data ) | |
if request.method == 'POST': | |
formset = LayerReviewFormSet(request.POST) | |
for form in formset: | |
srs = request.POST.get('srs', '') | |
upload = DataLayer(srs = srs) | |
NewConfiguration = upload.save() | |
else: | |
formset = LayerReviewFormSet() | |
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
you're doubling up the
if
andelse
here, just use one. On line 20, we would useform.cleaned_data['srs']
to access the string entered into the form, for example:Don't name the DataLayer
upload
, that's really confusing, because we are already working withUploadEvent
objects, which are different. Call it something likelayer
.I don't know what a
NewConfiguration
is, but we should be makingDataLayer
objects. isNewConfiguration
a class you made? Remember that CamelCase capitalization should be used exclusively with classes, based on python good practice. If you have an object instance, rather than a class, use lower case.