Example #1
0
def transactions_data(request):
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == 'GET' else request.POST
        params.walletID = int(REQ.get('walletID', 0))
        params.entryTypeID = int(REQ.get('entryTypeID', -1))
        params.entryForID = int(REQ.get('entryForID', -1))
        params.amount = request.GET.get('amount', None)
        params.comparator = request.GET.get('comparator', 'gt')
        params.from_date = timezone.make_aware(
            datetime.strptime(REQ.get('from_date', None), DATE_PATTERN),
            timezone.get_current_timezone())
        params.to_date = timezone.make_aware(
            datetime.strptime(REQ.get('to_date', None), DATE_PATTERN),
            timezone.get_current_timezone())
    except:
        return HttpResponseBadRequest()
    query = TransactionEntry.objects.select_related(
        depth=1).all().order_by('-date')

    if params.search or params.walletID or params.entryTypeID or params.amount or (
            params.from_date and params.to_date):
        total_entries = query.count()
        search_args = Q()

        if params.search:
            search_args |= Q(clientName__icontains=params.search)
            station_ids = list(
                CelestialObject.objects.filter(
                    itemName__icontains=params.search,
                    group=constants.STATIONS_GROUPID).values_list(
                        'itemID', flat=True)[:100])
            item_ids = list(
                Type.objects.filter(
                    typeName__icontains=params.search).values_list(
                        'typeID', flat=True)[:100])
            search_args |= Q(stationID__in=station_ids)
            search_args |= Q(typeID__in=item_ids)
            if is_number(params.search):
                search_args |= Q(amount__gte=params.search)
        if params.walletID:
            search_args &= Q(wallet=params.walletID)
        if params.entryTypeID != -1:
            search_args &= Q(transactionType=params.entryTypeID)
        if params.entryForID != -1:
            search_args &= Q(transactionFor=params.entryForID)
        # Add query amount
        if params.amount:
            comparator_map = {
                'gt': Q(price__gt=params.amount),
                'lt': Q(price__lt=params.amount),
                'gte': Q(price__gte=params.amount),
                'lte': Q(price__lte=params.amount),
                'eq': Q(price=params.amount),
                'neq': Q(price__lt=params.amount, price__gt=params.amount),
            }
            search_args &= comparator_map[params.comparator]

        # Add query dates
        if params.from_date and params.to_date:
            # + 24 hours on the to date
            search_args &= Q(date__range=(params.from_date,
                                          params.to_date + timedelta(days=1)))

        query = query.filter(search_args)
        filtered_entries = query.count()
    else:
        total_entries = filtered_entries = query.count()

    query = query[params.first_id:params.last_id]
    entries = []

    my_corp = Corporation.objects.mine()

    for entry in query:
        try:
            amount = print_float(entry.journal.amount, force_sign=True)
        except AttributeError:
            amount = '0.0'
        try:
            balance = print_float(entry.journal.balance)
        except AttributeError:
            balance = ''

        entries.append([
            print_time_min(entry.date),
            entry.typeName,
            entry.price,
            entry.quantity,
            amount,
            balance,
            truncate_words(entry.stationName, 6),
            entry.wallet.corp_wallets.get(corp=my_corp).name,
        ])

    json_data = {
        "sEcho": params.sEcho,
        "iTotalRecords": total_entries,
        "iTotalDisplayRecords": filtered_entries,
        "aaData": entries
    }

    return HttpResponse(json.dumps(json_data))
Example #2
0
def journal_data(request):
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == 'GET' else request.POST
        params.walletID = int(REQ.get('walletID', 0))
        params.entryTypeID = int(REQ.get('entryTypeID', 0))
        params.amount = request.GET.get('amount', None)
        params.comparator = request.GET.get('comparator', 'gt')
        params.from_date = timezone.make_aware(
            datetime.strptime(REQ.get('from_date', None), DATE_PATTERN),
            timezone.get_current_timezone())
        params.to_date = timezone.make_aware(
            datetime.strptime(REQ.get('to_date', None), DATE_PATTERN),
            timezone.get_current_timezone())
    except:
        return HttpResponseBadRequest()

    orderBy = journal_cols[params.column]
    if not params.asc: orderBy = "-" + orderBy
    query = JournalEntry.objects.select_related(
        depth=1).all().order_by(orderBy)

    if params.search or params.walletID or params.entryTypeID or params.amount or (
            params.from_date and params.to_date):
        total_entries = query.count()
        search_args = Q()

        if params.search:
            search_args |= Q(ownerName1__icontains=params.search)
            search_args |= Q(ownerName2__icontains=params.search)
            search_args |= Q(argName1__icontains=params.search)
            search_args |= Q(reason__icontains=params.search)
            if is_number(params.search):
                search_args |= Q(amount__gte=params.search)
        if params.walletID:
            search_args &= Q(wallet=params.walletID)
        if params.entryTypeID:
            search_args &= Q(type=params.entryTypeID)
        # Add query amount
        if params.amount:
            comparator_map = {
                'gt': Q(amount__gt=params.amount),
                'lt': Q(amount__lt=params.amount),
                'gte': Q(amount__gte=params.amount),
                'lte': Q(amount__lte=params.amount),
                'eq': Q(amount=params.amount),
                'neq': Q(amount__lt=params.amount, amount__gt=params.amount),
            }
            search_args &= comparator_map[params.comparator]

        # Add query dates
        if params.from_date and params.to_date:
            # + 24 hours on the to date
            search_args &= Q(date__range=(params.from_date,
                                          params.to_date + timedelta(days=1)))

        query = query.filter(search_args)
        filtered_entries = query.count()
    else:
        total_entries = filtered_entries = query.count()

    query = query[params.first_id:params.last_id]
    entries = []

    # to improve performance
    try:
        corp = Corporation.objects.mine()
    except Corporation.DoesNotExist:
        corp = Corporation(corporationID=0)
    members = Member.objects.all()
    other_entries = JournalEntry.objects.select_related().all()

    for entry in query:

        try:
            owner1 = members.get(characterID=entry.ownerID1).permalink
        except Member.DoesNotExist:
            owner1 = entry.ownerName1
        try:
            owner2 = members.get(characterID=entry.ownerID2).permalink
        except Member.DoesNotExist:
            owner2 = entry.ownerName2

        if entry.type_id == EntryType.BOUNTY_PRIZES:
            rats = [s.split(':') for s in entry.reason.split(',') if ':' in s]
            rat_list = []
            for rat_id, rat_count in rats:
                rat_list.append(
                    '%s x%s' %
                    (Type.objects.get(typeID=rat_id).typeName, rat_count))
            reason = '|'.join(rat_list)
            if reason:
                reason = (u'Killed Rats in %s|' % entry.argName1) + reason
        elif entry.type_id == EntryType.PLAYER_DONATION:
            reason = entry.reason[len('DESC: '):]
            if reason:
                reason = u'Description|' + reason
        elif entry.type_id == EntryType.CORP_WITHDRAWAL:
            reason = entry.reason[len('DESC: '):].strip('\n\t\'" ')
            reason = (u'Cash transfer by %s|' % entry.argName1) + reason
            try:
                if int(entry.ownerID1) == corp.corporationID and int(
                        entry.ownerID2) == corp.corporationID:
                    related_entry = other_entries.filter(
                        refID=entry.refID).exclude(id=entry.id)[0]
                    owner2 = related_entry.wallet.corp_wallets.get(
                        corp=corp).name
            except:
                pass
        else:
            reason = entry.reason

        wallet_name = entry.wallet.corp_wallets.get(corp=corp).name

        entries.append([
            print_time_min(entry.date),
            wallet_name,
            entry.type.refTypeName,
            owner1,
            owner2,
            print_float(entry.amount, force_sign=True),
            print_float(entry.balance),
            reason,
        ])

    return datatable_ajax_data(entries, params.sEcho, total_entries,
                               filtered_entries)
Example #3
0
def journal_data(request):
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == "GET" else request.POST
        params.walletID = int(REQ.get("walletID", 0))
        params.entryTypeID = int(REQ.get("entryTypeID", 0))
        params.amount = request.GET.get("amount", None)
        params.comparator = request.GET.get("comparator", "gt")
        params.from_date = timezone.make_aware(
            datetime.strptime(REQ.get("from_date", None), DATE_PATTERN), timezone.get_current_timezone()
        )
        params.to_date = timezone.make_aware(
            datetime.strptime(REQ.get("to_date", None), DATE_PATTERN), timezone.get_current_timezone()
        )
    except:
        return HttpResponseBadRequest()

    orderBy = journal_cols[params.column]
    if not params.asc:
        orderBy = "-" + orderBy
    query = JournalEntry.objects.select_related(depth=1).all().order_by(orderBy)

    if params.search or params.walletID or params.entryTypeID or params.amount or (params.from_date and params.to_date):
        total_entries = query.count()
        search_args = Q()

        if params.search:
            search_args |= Q(ownerName1__icontains=params.search)
            search_args |= Q(ownerName2__icontains=params.search)
            search_args |= Q(argName1__icontains=params.search)
            search_args |= Q(reason__icontains=params.search)
            if is_number(params.search):
                search_args |= Q(amount__gte=params.search)
        if params.walletID:
            search_args &= Q(wallet=params.walletID)
        if params.entryTypeID:
            search_args &= Q(type=params.entryTypeID)
        # Add query amount
        if params.amount:
            comparator_map = {
                "gt": Q(amount__gt=params.amount),
                "lt": Q(amount__lt=params.amount),
                "gte": Q(amount__gte=params.amount),
                "lte": Q(amount__lte=params.amount),
                "eq": Q(amount=params.amount),
                "neq": Q(amount__lt=params.amount, amount__gt=params.amount),
            }
            search_args &= comparator_map[params.comparator]

        # Add query dates
        if params.from_date and params.to_date:
            # + 24 hours on the to date
            search_args &= Q(date__range=(params.from_date, params.to_date + timedelta(days=1)))

        query = query.filter(search_args)
        filtered_entries = query.count()
    else:
        total_entries = filtered_entries = query.count()

    query = query[params.first_id : params.last_id]
    entries = []

    # to improve performance
    try:
        corp = Corporation.objects.mine()
    except Corporation.DoesNotExist:
        corp = Corporation(corporationID=0)
    members = Member.objects.all()
    other_entries = JournalEntry.objects.select_related().all()

    for entry in query:

        try:
            owner1 = members.get(characterID=entry.ownerID1).permalink
        except Member.DoesNotExist:
            owner1 = entry.ownerName1
        try:
            owner2 = members.get(characterID=entry.ownerID2).permalink
        except Member.DoesNotExist:
            owner2 = entry.ownerName2

        if entry.type_id == EntryType.BOUNTY_PRIZES:
            rats = [s.split(":") for s in entry.reason.split(",") if ":" in s]
            rat_list = []
            for rat_id, rat_count in rats:
                rat_list.append("%s x%s" % (Type.objects.get(typeID=rat_id).typeName, rat_count))
            reason = "|".join(rat_list)
            if reason:
                reason = (u"Killed Rats in %s|" % entry.argName1) + reason
        elif entry.type_id == EntryType.PLAYER_DONATION:
            reason = entry.reason[len("DESC: ") :]
            if reason:
                reason = u"Description|" + reason
        elif entry.type_id == EntryType.CORP_WITHDRAWAL:
            reason = entry.reason[len("DESC: ") :].strip("\n\t'\" ")
            reason = (u"Cash transfer by %s|" % entry.argName1) + reason
            try:
                if int(entry.ownerID1) == corp.corporationID and int(entry.ownerID2) == corp.corporationID:
                    related_entry = other_entries.filter(refID=entry.refID).exclude(id=entry.id)[0]
                    owner2 = related_entry.wallet.corp_wallets.get(corp=corp).name
            except:
                pass
        else:
            reason = entry.reason

        wallet_name = entry.wallet.corp_wallets.get(corp=corp).name

        entries.append(
            [
                print_time_min(entry.date),
                wallet_name,
                entry.type.refTypeName,
                owner1,
                owner2,
                print_float(entry.amount, force_sign=True),
                print_float(entry.balance),
                reason,
            ]
        )

    return datatable_ajax_data(entries, params.sEcho, total_entries, filtered_entries)
Example #4
0
def journal_data(request):
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == 'GET' else request.POST
        params.walletID = int(REQ.get('walletID', 0))
        params.entryTypeID = int(REQ.get('entryTypeID', 0))
        params.amount = request.GET.get('amount',None)
        params.comparator = request.GET.get('comparator','gt')
        params.from_date   = timezone.make_aware(datetime.strptime(REQ.get('from_date', None), DATE_PATTERN), timezone.get_current_timezone())
        params.to_date     = timezone.make_aware(datetime.strptime(REQ.get('to_date', None), DATE_PATTERN), timezone.get_current_timezone())
    except:
        return HttpResponseBadRequest()

    query = JournalEntry.objects.select_related(depth=1).all().order_by('-date')

    if params.search or params.walletID or params.entryTypeID or params.amount or (params.from_date and params.to_date):
        total_entries = query.count()
        search_args = Q()

        if params.search:
            search_args |= Q(ownerName1__icontains=params.search)
            search_args |= Q(ownerName2__icontains=params.search)
            search_args |= Q(argName1__icontains=params.search)
            search_args |= Q(reason__icontains=params.search)
            if is_number(params.search):
                search_args |= Q(amount__gte=params.search)
        if params.walletID:
            search_args &= Q(wallet=params.walletID)
        if params.entryTypeID:
            search_args &= Q(type=params.entryTypeID)
        # Add query amount
        if params.amount:
            comparator_map = {
                              'gt':  Q(amount__gt=params.amount), 
                              'lt':  Q(amount__lt=params.amount), 
                              'gte': Q(amount__gte=params.amount),
                              'lte': Q(amount__lte=params.amount),
                              'eq': Q(amount=params.amount),
                              'neq': Q(amount__lt=params.amount, amount__gt=params.amount),
                              }
            search_args &= comparator_map[params.comparator]
            
        # Add query dates
        if params.from_date and params.to_date:
            # + 24 hours on the to date
            search_args &= Q(date__range=(params.from_date, params.to_date + timedelta(days=1)))
            
        query = query.filter(search_args)
        filtered_entries = query.count()
    else:
        total_entries = filtered_entries = query.count()

    query = query[params.first_id:params.last_id]
    entries = []

    # to improve performance
    try: 
        corp = Corporation.objects.mine()
    except Corporation.DoesNotExist: 
        corp = Corporation(corporationID=0)
    members = Member.objects.all()
    other_entries = JournalEntry.objects.select_related().all()

    for entry in query:

        try: owner1 = members.get(characterID=entry.ownerID1).permalink
        except Member.DoesNotExist: owner1 = entry.ownerName1
        try: owner2 = members.get(characterID=entry.ownerID2).permalink
        except Member.DoesNotExist: owner2 = entry.ownerName2

        if entry.type_id == EntryType.BOUNTY_PRIZES:
            rats = [ s.split(':') for s in entry.reason.split(',') if ':' in s ]
            rat_list = []
            for rat_id, rat_count in rats:
                rat_list.append('%s x%s' % (Type.objects.get(typeID=rat_id).typeName, rat_count))
            reason = '|'.join(rat_list)
            if reason:
                reason = (u'Killed Rats in %s|' % entry.argName1) + reason
        elif entry.type_id == EntryType.PLAYER_DONATION:
            reason = entry.reason[len('DESC: '):]
            if reason:
                reason = u'Description|' + reason
        elif entry.type_id == EntryType.CORP_WITHDRAWAL:
            reason = entry.reason[len('DESC: '):].strip('\n\t\'" ')
            reason = (u'Cash transfer by %s|' % entry.argName1) + reason
            try:
                if int(entry.ownerID1) == corp.corporationID and int(entry.ownerID2) == corp.corporationID:
                    related_entry = other_entries.filter(refID=entry.refID).exclude(id=entry.id)[0]
                    owner2 = related_entry.wallet.corp_wallets.get(corp=corp).name
            except:
                pass
        else:
            reason = entry.reason
        
        wallet_name = entry.wallet.corp_wallets.get(corp=corp).name
        
        entries.append([
            print_time_min(entry.date),
            wallet_name,
            entry.type.refTypeName,
            owner1,
            owner2,
            print_float(entry.amount, force_sign=True),
            print_float(entry.balance),
            reason,
        ])

    #json_data = {
    #    "sEcho" : params.sEcho,
    #    "iTotalRecords" : total_entries,
    #    "iTotalDisplayRecords" : filtered_entries,
    #    "aaData" : entries
    #}
    return datatable_ajax_data(entries, params.sEcho, total_entries, filtered_entries)
Example #5
0
def transactions_data(request):
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == "GET" else request.POST
        params.walletID = int(REQ.get("walletID", 0))
        params.entryTypeID = int(REQ.get("entryTypeID", -1))
        params.entryForID = int(REQ.get("entryForID", -1))
        params.amount = request.GET.get("amount", None)
        params.comparator = request.GET.get("comparator", "gt")
        params.from_date = timezone.make_aware(
            datetime.strptime(REQ.get("from_date", None), DATE_PATTERN), timezone.get_current_timezone()
        )
        params.to_date = timezone.make_aware(
            datetime.strptime(REQ.get("to_date", None), DATE_PATTERN), timezone.get_current_timezone()
        )
    except:
        return HttpResponseBadRequest()
    query = TransactionEntry.objects.select_related(depth=1).all().order_by("-date")

    if params.search or params.walletID or params.entryTypeID or params.amount or (params.from_date and params.to_date):
        total_entries = query.count()
        search_args = Q()

        if params.search:
            search_args |= Q(clientName__icontains=params.search)
            station_ids = list(
                CelestialObject.objects.filter(
                    itemName__icontains=params.search, group=constants.STATIONS_GROUPID
                ).values_list("itemID", flat=True)[:100]
            )
            item_ids = list(
                Type.objects.filter(typeName__icontains=params.search).values_list("typeID", flat=True)[:100]
            )
            search_args |= Q(stationID__in=station_ids)
            search_args |= Q(typeID__in=item_ids)
            if is_number(params.search):
                search_args |= Q(amount__gte=params.search)
        if params.walletID:
            search_args &= Q(wallet=params.walletID)
        if params.entryTypeID != -1:
            search_args &= Q(transactionType=params.entryTypeID)
        if params.entryForID != -1:
            search_args &= Q(transactionFor=params.entryForID)
        # Add query amount
        if params.amount:
            comparator_map = {
                "gt": Q(price__gt=params.amount),
                "lt": Q(price__lt=params.amount),
                "gte": Q(price__gte=params.amount),
                "lte": Q(price__lte=params.amount),
                "eq": Q(price=params.amount),
                "neq": Q(price__lt=params.amount, price__gt=params.amount),
            }
            search_args &= comparator_map[params.comparator]

        # Add query dates
        if params.from_date and params.to_date:
            # + 24 hours on the to date
            search_args &= Q(date__range=(params.from_date, params.to_date + timedelta(days=1)))

        query = query.filter(search_args)
        filtered_entries = query.count()
    else:
        total_entries = filtered_entries = query.count()

    query = query[params.first_id : params.last_id]
    entries = []

    my_corp = Corporation.objects.mine()

    for entry in query:
        try:
            amount = print_float(entry.journal.amount, force_sign=True)
        except AttributeError:
            amount = "0.0"
        try:
            balance = print_float(entry.journal.balance)
        except AttributeError:
            balance = ""

        entries.append(
            [
                print_time_min(entry.date),
                entry.typeName,
                entry.price,
                entry.quantity,
                amount,
                balance,
                truncate_words(entry.stationName, 6),
                entry.wallet.corp_wallets.get(corp=my_corp).name,
            ]
        )

    json_data = {
        "sEcho": params.sEcho,
        "iTotalRecords": total_entries,
        "iTotalDisplayRecords": filtered_entries,
        "aaData": entries,
    }

    return HttpResponse(json.dumps(json_data))