示例#1
0
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")
示例#2
0
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 })
示例#3
0
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")
示例#4
0
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})
示例#5
0
def _get_nets_distribution_data(location):
    data = NetDistribution.net_data_total(location)
    nets = data["distributed"]
    expected = data["expected"]
    discrepancy = data["discrepancy"]

    #TODO: 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)})
    # Recursion is great but I was thinking that there's not likely going to be a need to use
    # recursion to get descendants seeing that the location code in construct already
    # takes that into consideration hence I'm commenting this out. Sorry Evan :)
    #for child in location.children.all():
    #    child_data = _get_nets_distribution_data(child)
    #    nets += child_data[0]
    #    expected += child_data[1]
    #    discrepancy += 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(nets), int(expected), int(discrepancy)  #, time_info
示例#6
0
def _get_nets_distribution_data(location):
    data = NetDistribution.net_data_total(location)
    nets = data["distributed"]
    expected = data["expected"]
    discrepancy = data["discrepancy"]

    #TODO: 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)})
    # Recursion is great but I was thinking that there's not likely going to be a need to use
    # recursion to get descendants seeing that the location code in construct already
    # takes that into consideration hence I'm commenting this out. Sorry Evan :)
    #for child in location.children.all():
    #    child_data = _get_nets_distribution_data(child)
    #    nets += child_data[0]
    #    expected += child_data[1]
    #    discrepancy += 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(nets), int(expected), int(discrepancy)#, time_info