def get_hangqinng(username, code_list):
result = []
m_codes = mstockcodes(code_list)
# stockshq = SectorStockHangqing.objects.filter(code__in=code_list)
# pk_list = m_codes
values = ' '.join(['WHEN stockcode="%s" THEN %s' % (pk, i) for i, pk in enumerate(m_codes)])
ordering = 'CASE %s END' % values
stockshq = Hangqing.objects.filter(stockcode__in=m_codes).extra(select={'ordering': ordering}, order_by=('ordering',))
if stockshq.exists():
set1 = set()
for hq in stockshq:
res = {}
if hq.stockcode in set1:
continue
h_code = hq.stockcode.upper()
price = get_num(hq.price)
res['price'] = price
percent, color = get_color(hq.pchange)
res['color'] = color
res['percent'] = percent
res['number'] = h_code
res['title'] = hq.stockname
us = UserStock.objects.filter(username__exact=username).filter(stockcode__exact=h_code)
show = 1
if len(us) > 0 and us[0].active == 1:
show = 0
res['show'] = show
set1.add(hq.stockcode)
result.append(res)
return result
else:
return None