def stock_info(request):
    code = get_string_from_request('stock', request)
    if code is None:
        return HttpResponseRedirect("/stocks/stocks")
    try:
        dictionary = ReutersLibrary.get_stock_values(code)
        try:
            stock = models.Stock.objects.get(code=code)
        except models.Stock.DoesNotExist:
            return HttpResponseRedirect("/stocks/stocks")
        try:
            category_stocks = models.CategoryStock.objects.filter(stock_id=stock.pk)
            categories = set()
            for category_stock in category_stocks:
                try:
                    category = models.Category.objects.get(pk=category_stock.category_id)
                    categories.add(category.name)
                except models.Category.DoesNotExist:
                    pass
            categories = list(categories)
            dictionary["categories"] = categories
        except models.CategoryStock.DoesNotExist:
            pass
        return HttpResponse(json.dumps(dictionary))
    except models.Stock.DoesNotExist:
        return HttpResponse("[]")
def update_nzx(request):
    stocks =  ReutersLibrary.get_NZX()
    add_stocks(stocks, "nzx")
    return HttpResponseRedirect("/stocks/stocks")