Пример #1
0
def index(req):    
   
    return render_to_response(req,
        "mapping/index.html", {
        "all_locations": Location.objects.all().order_by("code"),
        "location_types": LocationType.objects.all() 
        })
Пример #2
0
def logistics_summary(req, locid):
    # Get the location we are going to work with.
    # If there is no location set, this will default to the first
    # one in the database.  If there are no locations in the
    # database we are S.O.L.
    if not locid:
        locid = 1
    try: 
        location = Location.objects.get(pk=locid)
    except Location.DoesNotExist:
        location = None

    # get all the partialtransactions that this location is involved in 
    transactions_from_loc = PartialTransaction.objects.all().filter(origin=location) 
    transactions_to_loc = PartialTransaction.objects.all().filter(destination=location)  
    transactions = (transactions_from_loc | transactions_to_loc).order_by("-date") 
        
    # get any place this location has shipped to or from.  
    # we will use these to generate some plots
    # and pass them forward to the template
    locations_shipped_to = []
    [locations_shipped_to.append(trans.destination) for trans in transactions_from_loc if trans.destination not in locations_shipped_to]
    
    # set the stock value in all the children.
    # this is now handled by signals!  see supply/models.py
    #[_set_stock(child) for child in locations_shipped_to]
    
    # get some JSON strings for the plots
    stock_per_loc_data, stock_per_loc_options, bar_ticks = _get_stock_per_location_strings(locations_shipped_to)
    stock_over_time_data, stock_over_time_options = _get_stock_over_time_strings([location])
    stock_over_time_child_data, stock_over_time_child_options = _get_stock_over_time_strings(locations_shipped_to)
    
    paginator = Paginator(transactions, ITEMS_PER_PAGE)

    try:
        page = int(req.GET['page'])
    except:
        page = 1

    try:
        transactions_pager = paginator.page(page)
    except:
        raise Http404

    # send the whole list of stuff back to the template
    return render_to_response(req, "nigeria/logistics_summary.html", 
                              {'location': location,
                               'child_locations': locations_shipped_to,
                               'transactions_pager': transactions_pager,
                               'paginator': paginator,
                               'page': page,
                               'stock_per_loc_plot_data' : stock_per_loc_data, 
                               'stock_per_loc_plot_options' : stock_per_loc_options, 
                               'stock_over_time_data' : stock_over_time_data, 
                               'stock_over_time_options' : stock_over_time_options, 
                               'stock_over_time_child_data' : stock_over_time_child_data, 
                               'stock_over_time_child_options' : stock_over_time_child_options, 
                               'bar_ticks' : bar_ticks
                               })
Пример #3
0
def coupons_summary(req, locid=1):
    #Declarations
    coupons_distribution_data_per_ward = []
    coupons_distribution_data_over_time = []  
    try: 
        location = Location.objects.get(pk=locid)
        parent = location.parent
        location_type = Location.objects.get(pk=locid).type
        loc_children = []
        bar_data = []
        pie_data = {"settlements" : [], "people" : [], "coupons": []}
    
        index = 0
        # The loop below will be replaced by a neater code when method of returning children field properties are discovered
        coupon_data = []
        people_data = []
        settlements_data = []
        labels = []
        type = ""
        for child in location.children.all():
            people, coupons, settlements = _get_card_distribution_data(child)
            child.people = people
            child.settlements = settlements
            child.coupons = coupons
            type = child.type
            if child.people or child.settlements or child.coupons:
                settlements_data.append([index, child.settlements])
                people_data.append([index + 1, child.people])
                coupon_data.append([index + 2, child.coupons])
                # you need to add the str() to prevent the leading unicode 
                # character from showing up, which blows up flot
                labels.append(str(child.name))
                #bar_data.append({'data' : [[index, coupons]], "bars":{"show":"true"}, "label":str(child.name)})
                pie_data["coupons"].append({ "label": str(child.name),  "data": child.coupons})
                pie_data["settlements"].append({ "label": str(child.name),  "data": child.settlements})
                pie_data["people"].append({ "label": str(child.name),  "data": child.people})
                index += 4
            loc_children.append(child)
    except Location.DoesNotExist:
        location = None
    
    bar_data.append({"data" : settlements_data, "bars": { "show" : "true" }, "label":"settlements"})
    bar_data.append({"data" : people_data, "bars": { "show" : "true" }, "label":"people"})
    bar_data.append({"data" : coupon_data, "bars": { "show" : "true" }, "label":"coupons"})
    
    ticks = [[index * 4 + 1.5, label] for index, label in enumerate(labels)]
    
    options = '{"grid":{"clickable":true},"xaxis":{"min":0,"ticks":[],"tickFormatter":"string"},"yaxis":{"min":0}}'
    return render_to_response(req, "nigeria/coupons_summary.html", {'location': location,
                     'children' : loc_children, 
                     'child_type':type, 
                     'parent':parent, 
                     'bar_data':bar_data,
                     'bar_ticks':ticks,
                     'pie_data': pie_data
                     }
                 )
Пример #4
0
def edit(req, pk):
    trigger = get_object_or_404(FeedbackTrigger, pk=pk)

    return render_to_response(req,
        "feedback/edit.html", {
            "trigger": trigger,
            "all_tags": Tag.objects.all(),
            "triggers": paginated(req, FeedbackTrigger.objects.all())
        })
Пример #5
0
def index(req, locid=None):
    if not locid:
        locid = 1
    try:
        location = Location.objects.get(id=locid)
    except Location.DoesNotExist:
        location= None
    #print "location: %s" % location
    return render_to_response(req, "nigeria/index.html",{'location':location })
Пример #6
0
def bednets_daily(req, locid):
    if not locid:
        locid = 1
    try: 
        location = Location.objects.get(pk=locid)
        #_set_stock(location)
    except Location.DoesNotExist:
        location = None
        
    return render_to_response(req, "nigeria/bednets_daily.html", {'location': location})
Пример #7
0
def coupons_daily(req, locid=1):
    #Declarations
    coupons_distribution_data_per_ward = []
    coupons_distribution_data_over_time = []  
    child = Location.objects.get(pk=locid).children.all()[0]
    try: 
        location = Location.objects.get(pk=locid)
        location_type = Location.objects.get(pk=locid).type
        loc_children = []
        bar_data = []
        pie_data = []
        index = 0
        # The loop below will be replaced by a neater code when method of returning children field properties are discovered
        for child in location.children.all():
            people, coupons, settlements = _get_card_distribution_data(child)
            child.people = people
            child.settlements = settlements
            child.coupons = coupons
            type = child.type
            if coupons != 0:
                # you need to add the str() to prevent the leading unicode 
                # character from showing up, which blows up flot
                bar_data.append({'data' : [[index, coupons]], "bars":{"show":"true"}, "label":str(child.name)})
                pie_data.append({ "label": str(child.name),  "data": child.coupons})
                index += 1
            else:
                #hack
                child.coupons = 100
            loc_children.append(child)
    except Location.DoesNotExist:
        location = None

    #TODO: Generate and Send all plots data from here to the templates
    

    coupons_data_for_dps_mts1 = [[1,100],[5,60],[9,70],[13,40]]
    coupons_data_for_dps_mts2 = [[2,50],[6,60],[10,60],[14,100]]
    coupons_data_for_dps_mts3 = [[3,50],[7,60],[11,60],[15,100]]

    overflow_data = [[20,0]]
    bar_options = '{"xaxis":{"min":0,"ticks":[],"tickFormatter":"string"},"yaxis":{"min":0}}'
    coupons_data =  [{ 'data': coupons_data_for_dps_mts1, "bars": { "show": "true"}, "label":"MT 1" },
                     {'data': coupons_data_for_dps_mts2, "bars": { "show": "true" },"label":"MT 2" },
                     { 'data': coupons_data_for_dps_mts3, "bars": { "show": "true" },"label":"MT 3" },
                     { 'data': overflow_data, "bars": { "show": "true", "fill": "true", "fillColor":"#FFFFFF","label":"MT 4" }} ] 
    return render_to_response(req, "nigeria/coupons_daily.html", {'location': location,
                     'children' : loc_children, 
                     'type':type, 
                     'child':child, 
                     'coupons_data':coupons_data,
                     'bar_data':bar_data,
                     'bar_options':bar_options,
                     'pie_data': pie_data
                     }
                 )
Пример #8
0
def index(req):
    tmpls = Template.objects.values_list("key", "text")
    tmpl_map = dict([(int(k), t) for k, t in tmpls])
    
    all_tmpls = [
        { "key": n, "text": tmpl_map.get(n, "") }
        for n in range(1,10)]
    
    return render_to_response(req,
        "training/index.html",
        { "templates": all_tmpls })
Пример #9
0
def index_basic(req):
    
    template_name="http/setphone.html"
    if req.method == 'POST':
        phone_number = '' 
        if req.POST.has_key("phone_number"):
            phone_number = req.POST["phone_number"]
        if (len(phone_number) == 0):
            phone_number = random.randint(100000, 999999) 
        return HttpResponseRedirect("/httpbasic/%s" % (phone_number))
        #return basic_ui(req, phone_number, True)
    return render_to_response(req, template_name, {})
Пример #10
0
def index(req, form_class=MessageForm):
    form_instance = form_class()
    template_name="http/ajaxified.html"
    # the following lines have been commented out since they aren't useful any longer
    #if req.method == 'POST':
    #   form_instance = form_class(req.POST)
    #   if form_instance.is_valid():
    #       msg = form_instance.save(commit=False)
    #       msg.date = datetime.datetime.now()
    #       msg.save();
    #       url = "http://localhost:8080/%s/%s" % (msg.phone_number, urllib2.quote(msg.body))
    #       urllib2.urlopen(url)
    #       #return render_to_response('shared/thanks.html')
    #   else:
    #       print "something bad happened"
    return render_to_response(req, template_name, {
    })
Пример #11
0
def view_location_type(req, location_type_slug):

    # look up the location type by the slug
    # (maybe not as concise as the 
    loc_type = get_object_or_404(
        LocationType,
        slug=location_type_slug)

    # prefetch all locations in this loc_type,
    # since we're going to plot them ALL on the
    # google map whether or not they're visible
    all_locations = list(loc_type.locations.all().order_by("code"))

    return render_to_response(req,
        "locations/view_location_type.html", {
            "active_location_type_tab": loc_type.pk,
            "locations": paginated(req, all_locations, prefix="loc", wrapper=with_related_objects),
            "relations": related_objects(Location),
            "all_locations": all_locations,
            "location_type": loc_type })
Пример #12
0
def edit_location(req, location_type_slug, location_pk):
    loc_type = get_object_or_404(LocationType, slug=location_type_slug)
    location = get_object_or_404(Location, pk=location_pk)

    if req.method == "GET":
        return render_to_response(req,
            "locations/location_form.html", {
                "active_location_type_tab": loc_type.pk,
                "location": location,

                # redirect back to this view to save (below)
                "save_url": reverse("edit_location", kwargs={
                    "location_type_slug": location_type_slug,
                    "location_pk": location_pk }),

            # is the map visible? default to 0 (hidden)
            # since the map makes everything very slow
            "show_map": int(req.GET.get("map", 0)) })

    elif req.method == "POST":

        # if DELETE was clicked... delete
        # the object, then and redirect
        if req.POST.get("delete", ""):
            pk = location.pk
            location.delete()

            return message(req,
                "Location %d deleted" % (pk),
                link=reverse("locations_dashboard"))

        # otherwise, just update the object
        # and display the success message
        else:
            location = update_via_querydict(location, req.POST)
            location.save()

            return message(req,
                "Location %d saved" % (location.pk),
                link=reverse("locations_dashboard"))
Пример #13
0
def add_location(req, location_type_slug):
    loc_type = get_object_or_404(LocationType, slug=location_type_slug)

    if req.method == "GET":
        return render_to_response(req,
            "locations/location_form.html", {
                "active_location_type_tab": loc_type.pk,

                # redirect back to this view to save (below)
                "save_url": reverse("add_location", kwargs={
                    "location_type_slug": location_type_slug}),

                # is the map visible? default to 1 (visible),
                # since i almost always want to set the location
                "show_map": int(req.GET.get("map", 1)) })

    elif req.method == "POST":
        location = insert_via_querydict(Location, req.POST, { "type": loc_type })
        location.save()
        
        return message(req,
            "Location %d saved" % (location.pk),
            link=reverse("locations_dashboard"))
Пример #14
0
def basic_ui(req, number, skip_post=False, form_class=MessageForm):
    form_instance = form_class()
    template_name="http/index.html"
    if req.method == 'POST' and req.POST.has_key("phone_number"):
        number = req.POST["phone_number"]
    msgs = Message.objects.all().filter(phone_number=number)
    if not skip_post and req.method == 'POST':
       form_instance = form_class(req.POST)
       if form_instance.is_valid():
           msg = form_instance.save(commit=False)
           msg.phone_number = number
           msg.date = datetime.datetime.now()
           msg.save();
           url = "http://localhost:8080/%s/%s" % (msg.phone_number, urllib2.quote(msg.body))
           urllib2.urlopen(url)
           #return render_to_response('shared/thanks.html')
           return basic_ui(req, msg.phone_number, True)
       else: 
           print "something bad happened"
    return render_to_response(req, template_name, {
        "form": form_instance,
        "msgs": msgs,
        "number": number
    })
Пример #15
0
def index(req):
    return render_to_response(req,
        "feedback/index.html", {
            "triggers": paginated(req, FeedbackTrigger.objects.all())
        })
Пример #16
0
def dashboard(req):
    return render_to_response(req,
        "locations/dashboard.html", {
            "all_locations": Location.objects.all() })
Пример #17
0
def message(req, msg, link=None):
    return render_to_response(req,
        "message.html", {
            "message": msg,
            "link": link
    })
Пример #18
0
def dashboard(req):
	return render_to_response(req, "dashboard.html")
Пример #19
0
def supply_summary(req, frm, to, range):
    return render_to_response(req, "nigeria/supply_summary.html")
Пример #20
0
def bednets_summary(req, frm, to, range):
    return render_to_response(req, "nigeria/bednets_summary.html")
Пример #21
0
def coupons_monthly(req, locid):
    return render_to_response(req, "nigeria/coupons_monthly.html")
Пример #22
0
def supply_monthly(req, locid):
    return render_to_response(req, "nigeria/supply_monthly.html")
Пример #23
0
def bednets_monthly(req, locid):
    return render_to_response(req, "nigeria/bednets_monthly.html")