Example #1
0
def ecm_time(value):
    try:
        if isinstance(value, timedelta):
            return unicode(print_date(value))
        else:
            return unicode(print_date(timedelta(seconds=value)))
    except:
        return unicode(value)
Example #2
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)
Example #3
0
        states.remove(Order.DRAFT)

    query = Order.objects.filter(state__in=states)

    sort_by = COLUMNS[params.column][1]

    if not params.asc:
        sort_by = '-' + sort_by

    query = query.order_by(sort_by)

    orders = []
    for order in query[params.first_id:params.last_id]:
        items = [row.catalog_entry.typeName for row in order.rows.all()]
        if order.delivery_date is not None:
            delivDate = print_date(order.delivery_date)
        else:
            delivDate = '(none)'
        orders.append([
            order.permalink(shop=False),
            order.state_text(),
            order.originator_permalink(),
            order.client or '(none)',
            delivDate,
            truncate_words(', '.join(items), 6),
            print_float(order.quote) + ' iSK',
        ])

    return datatable_ajax_data(data=orders, echo=params.sEcho)

Example #4
0
        states.remove(Order.DRAFT)

    query = Order.objects.filter(state__in=states)

    sort_by = COLUMNS[params.column][1]

    if not params.asc:
        sort_by = '-' + sort_by

    query = query.order_by(sort_by)

    orders = []
    for order in query[params.first_id:params.last_id]:
        items = [ row.catalog_entry.typeName for row in order.rows.all() ]
        if order.delivery_date is not None:
            delivDate = print_date(order.delivery_date)
        else:
            delivDate = '(none)'
        orders.append([
            order.permalink(shop=False),
            order.state_text(),
            order.originator_permalink(),
            order.client or '(none)',
            delivDate,
            truncate_words(', '.join(items), 6),
            print_float(order.quote) + ' iSK',
        ])

    return datatable_ajax_data(data=orders, echo=params.sEcho)

#------------------------------------------------------------------------------
Example #5
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)
Example #6
0
def get_members(query, first_id, last_id, search_str=None, sort_by=0, asc=True, for_csv=False):

    query = query.select_related(depth=2) # improve performance

    sort_col = MEMBERS_COLUMNS[sort_by]['db_field']
    # SQL hack for making a case insensitive sort
    if sort_by == 0:
        sort_col = sort_col + "_nocase"
        sort_val = db.fix_mysql_quotes('LOWER("%s")' % MEMBERS_COLUMNS[sort_by]['db_field'])
        query = query.extra(select={ sort_col : sort_val })

    
    if not asc: sort_col = "-" + sort_col
    query = query.extra(order_by=([sort_col]))

    if search_str:
        total_members = query.count()
        search_args = Q(name__icontains=search_str) | Q(nickname__icontains=search_str)

        if "DIRECTOR".startswith(search_str.upper()):
            search_args = search_args | Q(accessLvl=Member.DIRECTOR_ACCESS_LVL)

        query = query.filter(search_args)
        filtered_members = query.count()
    else:
        total_members = filtered_members = query.count()
        
    member_list = []
    if for_csv:
        for member in query:
            member_list.append([
                member.name,
                member.nickname,
                member.corp or '-',
                member.owner,
                member.lastLogin,
                member.dotlan_location,
                member.ship or '(docked)',
                member.accessLvl,
                ' '.join([ t.titleName for t in member.titles.all() ]),
            ])
    else:
        for member in query[first_id:last_id]:
            titles = ["Titles"]
            titles.extend(member.titles.values_list("titleName", flat=True))

            if member.corp:
                corp = '<span title="%s">%s</span>' % (member.corp, member.corp.ticker)
            else:
                corp = '-'
            
            memb = [
                member.permalink,
                corp,
                member.owner_permalink,
                member.accessLvl,
                print_date(member.lastLogin),
                member.dotlan_location,
                member.ship or '(docked)',
                "|".join(titles)
            ]
    
            member_list.append(memb)

    return total_members, filtered_members, member_list
Example #7
0
def ecm_date(value):
    try:
        return unicode(print_date(value))
    except:
        return unicode(value)