def items_out_json(request, library_id, account_id, asof_date):
    patron_name = ''
    if 'name' in request.GET:
        patron_name = request.GET['name']
    password = ''
    if 'password' in request.GET:
        password = request.GET['password']
    asof_date = datetime.datetime.strptime(asof_date, '%Y%m%dT%H%M%S')
    patron = models.get_patron(library_id, account_id, password, patron_name)

    try:
        items = patron.get_items(password=password, name=patron_name, asof_date=asof_date, check_cache=True, lastchecked_jscompat=True)
        response = {}
        response['asof'] = str(patron.lastchecked)
        response['items'] = items
        jsonresponse = json.dumps(response, cls=JsonEncoder)
        response = HttpResponse(jsonresponse)
        response['Content-Type'] = 'application/json; charset=utf-8'
        return response
    except Exception as e:
        return handle_exception(request, patron, 'items_out_json', e)
def renew_items(request, reqToken=None):
    titles = []
    index = 0
    while 'title'+str(index) in request.REQUEST:
        titles.append(request.REQUEST['title'+str(index)])
        index = index+1

    patron_name = ''
    if 'name' in request.REQUEST:
        patron_name = request.REQUEST['name']
    password = ''
    if 'password' in request.REQUEST:
        password = request.REQUEST['password']

    patron = models.get_patron(request.REQUEST['libraryid'], request.REQUEST['patronid'], password, patron_name)

    try:
        response = {}
        response['items'] = patron.renew_items(password, patron_name, titles)
        response['versions'] = versions
        jsonresponse = json.dumps(response, cls=JsonEncoder)

        # should we return response instead of storing it for future retrieval?
        if reqToken == None:
            response = HttpResponse(jsonresponse)
            response['Content-Type'] = 'application/json; charset=utf-8'
            return response

        renewalResponse = RenewalResponse(token=reqToken, response=jsonresponse)
        renewalResponse.id
        renewalResponse.save()

        responsetoken = {}
        responsetoken['token'] = reqToken
        response = HttpResponse(json.dumps(responsetoken))
        response['Content-Type'] = 'application/json; charset=utf-8'
        return response
    except Exception as e:
        return handle_exception(request, patron, 'renew_items', e)