def enter(request): if request.method == 'POST': params = ('site', 'genus', 'sp', 'subsp', 'common_name', 'source') all_values = [request.POST.getlist(param) for param in params] rows = [params] + zip(*all_values) taxon = request.POST.get('taxon') comments = request.POST.get('comments') filename = 'documents/%s.%s.%s.csv' % (request.user.username, taxon, time.strftime('%Y-%h-%d.%H%M%S')) output_file = open(filename, 'w') output_file.write('\n'.join([','.join(['"%s"' % cell for cell in row]) for row in rows])) output_file.close() newdoc = SpListDocument(docfile=filename, tax_group = taxon, comments=comments, uploaded_by=request.user) newdoc.save() documents = SpListDocument.objects.all() return render_to_response( 'enter.html', {'documents': documents, 'has_permission': u'sp_list.add_splistdocument' in request.user.get_all_permissions(), 'groups': groups, 'sites': get_site_list(), }, context_instance=RequestContext(request) )
def enter(request): if request.method == 'POST': params = ('site', 'genus', 'sp', 'subsp', 'common_name', 'source') all_values = [request.POST.getlist(param) for param in params] rows = [params] + zip(*all_values) taxon = request.POST.get('taxon') comments = request.POST.get('comments') filename = 'documents/%s.%s.%s.csv' % ( request.user.username, taxon, time.strftime('%Y-%h-%d.%H%M%S')) output_file = open(filename, 'w') output_file.write('\n'.join( [','.join(['"%s"' % cell for cell in row]) for row in rows])) output_file.close() newdoc = SpListDocument(docfile=filename, tax_group=taxon, comments=comments, uploaded_by=request.user) newdoc.save() documents = SpListDocument.objects.all() return render_to_response('enter.html', { 'documents': documents, 'has_permission': u'sp_list.add_splistdocument' in request.user.get_all_permissions(), 'groups': groups, 'sites': get_site_list(), }, context_instance=RequestContext(request))
def upload(request): # Handle file upload if request.method == 'POST': form = SpListDocumentForm(request.POST, request.FILES) data = form.data if form.is_valid(): newdoc = SpListDocument(docfile = request.FILES['docfile'], tax_group=data['tax_group'], comments=data['comments'], uploaded_by=request.user) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('sp_list.views.upload')) else: form = SpListDocumentForm() # A empty, unbound form # Load documents for the list page documents = SpListDocument.objects.all() # Render list page with the documents and the form return render_to_response( 'upload.html', {'documents': documents, 'form': form, 'uploader': u'sp_list.add_splistdocument' in request.user.get_all_permissions(), 'deleter': u'sp_list.delete_splistdocument' in request.user.get_all_permissions()}, context_instance=RequestContext(request) )
def upload(request): # Handle file upload if request.method == 'POST': form = SpListDocumentForm(request.POST, request.FILES) data = form.data if form.is_valid(): newdoc = SpListDocument(docfile=request.FILES['docfile'], tax_group=data['tax_group'], comments=data['comments'], uploaded_by=request.user) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('sp_list.views.upload')) else: form = SpListDocumentForm() # A empty, unbound form # Load documents for the list page documents = SpListDocument.objects.all() # Render list page with the documents and the form return render_to_response('upload.html', { 'documents': documents, 'form': form, 'uploader': u'sp_list.add_splistdocument' in request.user.get_all_permissions(), 'deleter': u'sp_list.delete_splistdocument' in request.user.get_all_permissions() }, context_instance=RequestContext(request))