Ejemplo n.º 1
0
def item_edit_page(request, item_id):
    response = reply_object()
    try:
        property_form = ItemPropertyForm()
        item = Item.objects.get(pk = item_id)
        item_properties = describe_item_pretty(item.id)
        item_form = ItemForm(
            initial = {"name" : item.name,
                       "cost_price" : item.cost_price,
                       "selling_price" : item.selling_price,
                       "purchase_date" : format_date(item.purchase_date),
                       "sold_date" : format_date(item.sold_date),
                       "item_type" : item.item_type.id,
                       "item_code" : item.item_code,
                       "location" : item.location.id,
                       "guarantee_period_months" : item.guarantee_period_months,
                       "guarantee_start_date" : 
                       format_date(item.guarantee_start_date),
                       "paid" : item.paid,
                       "sold" : item.sold,
                       "company" : item.company.id,
                       "showroom" : item.showroom.id,
                       "item_object_id" : item_id,
                       "unit" : item.unit})
        page = render_to_string("item.html",
                                {"item_form" : item_form,
                                 "property_form" : property_form,
                                 "properties" : item_properties.iteritems()})
        response["code"] = settings.APP_CODE["PAGE LOADED"]
        response["page"] = page
    except:
        response["code"] = settings.APP_CODE["SYSTEM ERROR"]
        response["page"] = "An error has occured while loading this page"

    return HttpResponse(simplejson.dumps(response))
Ejemplo n.º 2
0
def manage_campaign(request, object_id):
    response = reply_object()
    #try:
    if True:
        camp = Campaign.objects.get(id=object_id)
        c_form = CampaignForm\
            (initial={"name":camp.name,
                      "object_id":camp.id,
                      "total_budget":camp.total_budget,
                      "daily_budget":camp.daily_budget,
                      "start_date":format_date(camp.start_date),
                      "end_date":format_date(camp.end_date)})
        sn_form = SocialNetworkForm\
            (initial={"network_name":camp.social_networks})
        l_form = LocationForm(object_id=object_id)
        ad_form = CreateAdForm()
        adv_params = get_adv_parameters(request, 1, camp)
        page = render_to_string\
            ("campaigns_manager.html",
             context_instance=\
                 RequestContext(request,
                                {"c_form":c_form,
                                 "sn_form":sn_form,
                                 "l_form":l_form,
                                 "ad_form":ad_form,
                                 "advs":adv_params["advs"],
                                 "adv_paginator":adv_params["adv_paginator"]}))
        response["page"] = page
        response["code"] = settings.APP_CODE["PAGE LOADED"]
    #except:
    #    response["code"] = settings.APP_CODE["SYSTEM ERROR"]
    return HttpResponse(simplejson.dumps(response))
Ejemplo n.º 3
0
def edit_purchase(request, object_id):
    response = reply_object()
    try:
        purchase = Purchase.objects.get(pk = object_id)
        print purchase.purchase_date
        form = PurchaseForm(initial = {"purchase_id" : purchase.id,
                                       "item_name" : purchase.item.name,
                                       "number" : purchase.number,
                                       "item_unit" : purchase.item_unit.id,
                                       "purchase_date" : format_date(purchase.purchase_date),
                                       "paid" : purchase.paid,
                                       "distributor" : purchase.distributor.id,
                                       "total_amount" : purchase.total_amount,
                                       "price_per_unit" : purchase.price_per_unit})
        page = render_to_string("purchase.html", {"form" : form})
        response["code"] = settings.APP_CODE["PAGE LOADED"]
        response["page"] = page
    except:
        response["code"] = settings.APP_CODE["SYSTEM ERROR"]

    return HttpResponse(simplejson.dumps(response))