Skip to content

Instantly share code, notes, and snippets.

@cesandoval
Created August 7, 2012 00:44
Show Gist options
  • Save cesandoval/3280057 to your computer and use it in GitHub Desktop.
Save cesandoval/3280057 to your computer and use it in GitHub Desktop.
forms - models
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),
)
@bengolder
Copy link

you're doubling up the if and else here, just use one. On line 20, we would use form.cleaned_data['srs'] to access the string entered into the form, for example:

srs = form.cleaned_data['srs']

Don't name the DataLayer upload, that's really confusing, because we are already working with UploadEvent objects, which are different. Call it something like layer.

I don't know what a NewConfiguration is, but we should be making DataLayer objects. is NewConfiguration 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment