Beispiel #1
0
def _print_repackaged_volume(item, quantity=1):
    result = ""
    if REPACKAGED_VOLUMES.has_key(item.group.groupName):
        vol_rep = print_volume(REPACKAGED_VOLUMES[item.group.groupName] * quantity, rounded=True)
        vol_tot = print_volume(item.volume * quantity, rounded=True)
        result = "%s / %s" % ( vol_rep, vol_tot)
    else:
        vol = print_volume(item.volume * quantity, rounded=True)
        result = "%s / %s" % (vol, vol)
    return result
Beispiel #2
0
def _print_repackaged_volume(item, quantity=1):
    result = ""
    if REPACKAGED_VOLUMES.has_key(item.group.groupName):
        vol_rep = print_volume(REPACKAGED_VOLUMES[item.group.groupName] *
                               quantity,
                               rounded=True)
        vol_tot = print_volume(item.volume * quantity, rounded=True)
        result = "%s / %s" % (vol_rep, vol_tot)
    else:
        vol = print_volume(item.volume * quantity, rounded=True)
        result = "%s / %s" % (vol, vol)
    return result
Beispiel #3
0
def contracts_data(request):
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == 'GET' else request.POST
        params.type = int(REQ.get('type', 0)) # default to All
        params.status = int(REQ.get('status', 0)) # default to All
    except (ValueError, KeyError):
        return HttpResponseBadRequest()

    query = Contract.objects.all()

    total_entries = query.count()
    if params.search or params.type or params.status:
        search_args = Q()

        if params.search:
            # Search for contract title
            search_args |= Q(title__icontains=params.search)

            # Search for contract item in the contracts
            matching_ids = [t.typeID for t in Type.objects.filter(typeName__icontains=params.search)[:100]]
            
            # HACK: Django 1.3. distincts always on the default order attribute, so we use an aggregation
            # to get unique ids
            query_items = ContractItem.objects.filter(Q(typeID__in=matching_ids)).values('contract').annotate(Count('contract'))
            for match in query_items:
                search_args |= Q(contractID=match['contract'])
                    
        if params.type:     
            search_args &= Q(type=params.type)
        if params.status:
            search_args &= Q(status=params.status)

        query = query.filter(search_args)
    
    filtered_entries = query.count()
    
    entries = []
    for entry in query[params.first_id:params.last_id]:
        entries.append([
            entry.permalink_type,
            entry.status_html,
            entry.permalink,
            print_date(entry.dateIssued),
            print_date(entry.dateExpired),
            print_date(entry.dateAccepted),
            print_date(entry.dateCompleted),
            print_float(entry.price),
            print_float(entry.reward),
            print_float(entry.collateral),
            print_float(entry.buyout),
            print_volume(entry.volume, rounded=True),
        ])

    return datatable_ajax_data(entries, params.sEcho, total_entries, filtered_entries)
Beispiel #4
0
def contracts_data(request):
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == 'GET' else request.POST
        params.type = int(REQ.get('type', 0))  # default to All
        params.status = int(REQ.get('status', 0))  # default to All
    except (ValueError, KeyError):
        return HttpResponseBadRequest()

    query = Contract.objects.all()

    total_entries = query.count()
    if params.search or params.type or params.status:
        search_args = Q()

        if params.search:
            # Search for contract title
            search_args |= Q(title__icontains=params.search)

            # Search for contract item in the contracts
            matching_ids = [
                t.typeID for t in Type.objects.filter(
                    typeName__icontains=params.search)[:100]
            ]

            # HACK: Django 1.3. distincts always on the default order attribute, so we use an aggregation
            # to get unique ids
            query_items = ContractItem.objects.filter(
                Q(typeID__in=matching_ids)).values('contract').annotate(
                    Count('contract'))
            for match in query_items:
                search_args |= Q(contractID=match['contract'])

        if params.type:
            search_args &= Q(type=params.type)
        if params.status:
            search_args &= Q(status=params.status)

        query = query.filter(search_args)

    filtered_entries = query.count()

    entries = []
    for entry in query[params.first_id:params.last_id]:
        entries.append([
            entry.permalink_type,
            entry.status_html,
            entry.permalink,
            print_date(entry.dateIssued),
            print_date(entry.dateExpired),
            print_date(entry.dateAccepted),
            print_date(entry.dateCompleted),
            print_float(entry.price),
            print_float(entry.reward),
            print_float(entry.collateral),
            print_float(entry.buyout),
            print_volume(entry.volume, rounded=True),
        ])

    return datatable_ajax_data(entries, params.sEcho, total_entries,
                               filtered_entries)