def location_tree(req): location = None locid = 1 try: locid = req.GET['root'] except: pass tree = [] if locid: if locid == "source": locid = 1 try: location = Location.objects.get(id=locid) if location.type.name == "State": children = location.children.filter( type__name='LGA', code__in=constants.KANO_PILOT_LGAS).all() else: children = location.children.filter(type__name='Ward').all() for child in children: try: stock_balance = Stock.objects.get(location=child).balance except Stock.DoesNotExist: stock_balance = 0 cards_distributed = CardDistribution.card_data_total( child)["distributed"] nets_distributed = NetDistribution.net_data_total( child)["distributed"] text = '''<span>%s</span> <span class="field"> <span class="datafield"><a href="/reports/logistics/summary/%d/">%s</a></span> <span><a href="/reports/coupons/summary/%d/">%s</a></span> <span><a href="/reports/bednets/summary/%d/">%s</a></span> </span>''' tree.append({ 'text': text % (child.name, child.pk, stock_balance, child.pk, cards_distributed, child.pk, nets_distributed), 'expanded': False, 'id': child.pk, 'hasChildren': True if child.children.filter( type__name__in=['LGA', 'Ward']).all() else False }) except Location.DoesNotExist: location = None tree_json = simplejson.dumps(tree) return HttpResponse(tree_json, mimetype="application/json")
def index(req, locid=None): if not locid: locid = 1 try: location = Location.objects.get(id=locid) # prepopulate the card and net data dictionaries location.card_data = CardDistribution.card_data_total(location) location.net_data = NetDistribution.net_data_total(location) location.stock = { 'balance': sum(Stock.objects.filter(location__code__startswith=location.code).all().values_list('balance', flat=True)) } except Location.DoesNotExist: location= None return render_to_response(req, "bednets/index.html",{'location':location })
def location_tree(req): location = None locid = 1 try: locid = req.GET['root'] except: pass tree = [] if locid: if locid == "source": locid = 1 try: location = Location.objects.get(id=locid) if location.type.name == "State": children = location.children.filter(type__name='LGA',code__in=constants.KANO_PILOT_LGAS).all() else: children = location.children.filter(type__name='Ward').all() for child in children: try: stock_balance = Stock.objects.get(location=child).balance except Stock.DoesNotExist: stock_balance = 0 cards_distributed = CardDistribution.card_data_total(child)["distributed"] nets_distributed = NetDistribution.net_data_total(child)["distributed"] text = '''<span>%s</span> <span class="field"> <span class="datafield"><a href="/reports/logistics/summary/%d/">%s</a></span> <span><a href="/reports/coupons/summary/%d/">%s</a></span> <span><a href="/reports/bednets/summary/%d/">%s</a></span> </span>''' tree.append({ 'text': text % (child.name, child.pk, stock_balance, child.pk, cards_distributed, child.pk, nets_distributed), 'expanded': False, 'id': child.pk, 'hasChildren': True if child.children.filter(type__name__in=['LGA', 'Ward']).all() else False }) except Location.DoesNotExist: location = None tree_json = simplejson.dumps(tree) return HttpResponse(tree_json, mimetype="application/json")
def _get_card_distribution_data(location): data = CardDistribution.card_data_total(location) people = data["people"] coupons = data["distributed"] settlements = data["settlements"] #This generates data for flots time-sensitive plots for net cards and benets. Not working. #time_info = {} #time_info.update({'lines':{'show':'true'}, 'data':location.card_data["time_info"], 'label':str(location.name)}) #for child in location.children.all(): # child_data = _get_card_distribution_data(child) # people += child_data[0] # coupons += child_data[1] # settlements += child_data[2] # if str(child.type) == 'State' or str(child.type) == 'LGA' or str(child.type) == 'Ward': #The line below added to build the time-sentitive data for plote - not completed. # time_info.update({'lines':{'show':'true'}, 'data':child_data[3], 'label':str(location.name)}) return int(people), int(coupons), int(settlements) #, time_info
def index(req, locid=None): if not locid: locid = 1 try: location = Location.objects.get(id=locid) # prepopulate the card and net data dictionaries location.card_data = CardDistribution.card_data_total(location) location.net_data = NetDistribution.net_data_total(location) location.stock = { 'balance': sum( Stock.objects.filter(location__code__startswith=location.code). all().values_list('balance', flat=True)) } except Location.DoesNotExist: location = None return render_to_response(req, "bednets/index.html", {'location': location})
def _get_card_distribution_data(location): data = CardDistribution.card_data_total(location) people = data["people"] coupons = data["distributed"] settlements = data["settlements"] #This generates data for flots time-sensitive plots for net cards and benets. Not working. #time_info = {} #time_info.update({'lines':{'show':'true'}, 'data':location.card_data["time_info"], 'label':str(location.name)}) #for child in location.children.all(): # child_data = _get_card_distribution_data(child) # people += child_data[0] # coupons += child_data[1] # settlements += child_data[2] # if str(child.type) == 'State' or str(child.type) == 'LGA' or str(child.type) == 'Ward': #The line below added to build the time-sentitive data for plote - not completed. # time_info.update({'lines':{'show':'true'}, 'data':child_data[3], 'label':str(location.name)}) return int(people), int(coupons), int(settlements)#, time_info