Esempio n. 1
0
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)
    )
Esempio n. 2
0
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))
Esempio n. 3
0
def list(request):
    if request.method == 'POST':
        taxon = request.POST.get('taxon')
        site = request.POST.get('site')

        submit_type = request.POST.get('submit')
        if submit_type == 'Download CSV':
            return download_csv(request, taxon, site)

        species_list = get_spp_list(taxon, site)

    else:
        species_list = []
        site = None
        taxon = None

    sites = get_site_list()

    # Render list page with the documents and the form
    return render_to_response('list.html', {
        'sites': sites,
        'groups': groups,
        'species_list': species_list,
        'selected_site': site,
        'selected_group': taxon
    },
                              context_instance=RequestContext(request))
Esempio n. 4
0
def list(request):
    if request.method == 'POST':
        taxon = request.POST.get('taxon')
        site = request.POST.get('site')
        
        submit_type = request.POST.get('submit')
        if submit_type == 'Download CSV':
            return download_csv(request, taxon, site)

        species_list = get_spp_list(taxon, site)

    else:
        species_list = []
        site = None
        taxon = None
        
    sites = get_site_list()

    # Render list page with the documents and the form
    return render_to_response(
        'list.html',
        {'sites': sites, 'groups':groups, 'species_list': species_list, 'selected_site': site, 'selected_group': taxon},
        context_instance=RequestContext(request)
    )