Exemplo n.º 1
0
def api_statements_commalist(request, pks=''):
    statements = Statement.objects.published().only('id', 'text', 'tag')
    statements_new_keys = []
    decode_cookie_string(pks)
    for statement in statements.filter(pk__in=decode_cookie_string(pks)):
        statements_new_keys.append(dict(
            id=statement.id, 
            statement=statement.text,
            tag=[statement.tag.slug, statement.tag.tag, statement.tag.color]
        ))
    statements = simplejson.dumps(statements_new_keys, ensure_ascii=False)
    return HttpResponse(statements, mimetype="application/json")
Exemplo n.º 2
0
def collection_as_csv(request):
    """Read ids from the user's cookie, return the results as a CSV file."""
    collection = request.COOKIES.get('itis_collection', None)
    if collection:
        collection = decode_cookie_string(collection, split_on='%2C')
        csv_string = Statement.objects.get_csv(id_list=collection)
        return HttpResponse(csv_string, mimetype="text/csv")
    else:
        raise Http404, "No collection found."