Ejemplo n.º 1
0
def element43_settings(request):
    """
    Adds element43 specific settings and characters with certain permissions to the context.
    """

    # Wallet / Journal chars
    # Check if user is authenticated, if not - just use context without characters
    try:
        if request.user.is_authenticated:
            journal_chars = validate_characters(
                request.user,
                calculate_character_access_mask(['WalletJournal']))
            transaction_chars = validate_characters(
                request.user,
                calculate_character_access_mask(['WalletTransactions']))
    except TypeError:
        return {
            'IMAGE_SERVER': settings.IMAGE_SERVER,
            'GOOGLE_ANALYTICS_ENABLED': settings.GOOGLE_ANALYTICS_ENABLED,
            'GOOGLE_ANALYTICS_TRACKING_ID':
            settings.GOOGLE_ANALYTICS_TRACKING_ID,
            'GOOGLE_ANALYTICS_DOMAIN_NAME':
            settings.GOOGLE_ANALYTICS_DOMAIN_NAME
        }

    return {
        'IMAGE_SERVER': settings.IMAGE_SERVER,
        'GOOGLE_ANALYTICS_ENABLED': settings.GOOGLE_ANALYTICS_ENABLED,
        'GOOGLE_ANALYTICS_TRACKING_ID': settings.GOOGLE_ANALYTICS_TRACKING_ID,
        'GOOGLE_ANALYTICS_DOMAIN_NAME': settings.GOOGLE_ANALYTICS_DOMAIN_NAME,
        'characters_journal': journal_chars,
        'characters_transaction': transaction_chars
    }
Ejemplo n.º 2
0
def dashboard(request):
    """
    Shows basic information about you account so you can quickly get an overview.
    """

    # Sheet based data
    chars_sheet = validate_characters(request.user, calculate_character_access_mask(['CharacterSheet']))
    sheet_data = []

    for char in chars_sheet:
        sheet_data.append({'char': char, 'next_update': APITimer.objects.get(character_id=char.id,
                                                                              apisheet='CharacterSheet').nextupdate})

    # Get all WalletJournal/WalletTransactions Chars
    market_chars = validate_characters(request.user, calculate_character_access_mask(['WalletJournal', 'WalletTransactions']))

    # Collect stats
    month = calculate_profit_stats(market_chars, 30)
    week = calculate_profit_stats(market_chars, 7)
    day = calculate_profit_stats(market_chars, 1)

    last_ten_sales = MarketTransaction.objects.filter(character__in=market_chars, is_bid=False).extra(select={'value': "price * quantity"}).order_by('-date')[:10]

    rcontext = RequestContext(request, {'sheet_data': sheet_data,
                                        'month': month,
                                        'week': week,
                                        'day': day,
                                        'last_ten_sales': last_ten_sales})

    return render_to_response('dashboard.haml', rcontext)
Ejemplo n.º 3
0
def dashboard(request):
    """
    Shows basic information about you account so you can quickly get an overview.
    """

    # Get 10 latest news items
    news_items = FeedItem.objects.order_by('-published')[:10]

    # Sheet based data
    chars_sheet = validate_characters(
        request.user, calculate_character_access_mask(['CharacterSheet']))
    sheet_data = []

    for char in chars_sheet:
        sheet_data.append({
            'char':
            char,
            'next_update':
            APITimer.objects.get(character_id=char.id,
                                 apisheet='CharacterSheet').nextupdate
        })

    # Get all WalletJournal/WalletTransactions Chars
    market_chars = validate_characters(
        request.user,
        calculate_character_access_mask(
            ['WalletJournal', 'WalletTransactions']))

    # Collect stats
    month = calculate_profit_stats(market_chars, 30)
    week = calculate_profit_stats(market_chars, 7)
    day = calculate_profit_stats(market_chars, 1)

    last_ten_sales = MarketTransaction.objects.filter(
        character__in=market_chars,
        is_bid=False).extra(select={
            'value': "price * quantity"
        }).order_by('-date')[:10]

    rcontext = RequestContext(
        request, {
            'news_items': news_items,
            'sheet_data': sheet_data,
            'month': month,
            'week': week,
            'day': day,
            'last_ten_sales': last_ten_sales
        })

    return render_to_response('dashboard.haml', rcontext)
Ejemplo n.º 4
0
def journal_json(request):
    # Get all chars with journal permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['WalletJournal']))

    wallet_series = {}

    # Append wallet history of all characters to dict
    for char in chars:
        series = []
        journal = JournalEntry.objects.filter(character=char).order_by('date')

        for point in journal:
            series.append([int(time.mktime(point.date.timetuple())) * 1000, point.balance])

        # If there aren't any journal entries, catch the resulting AssertionError and return empty list
        try:
            # Add current balance in the end for a more consistent look
            series.append([(int(time.mktime(datetime.datetime.utcnow().timetuple())) * 999), journal[len(journal) - 1].balance])
        except AssertionError:
            series = []

        wallet_series[char.name] = series

    serialized = json.dumps(wallet_series)

    # Return JSON without using any template
    return HttpResponse(serialized, mimetype='application/json')
Ejemplo n.º 5
0
def wallet(request):

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['WalletJournal']))

    # Prepare lists
    orders_bid = []
    orders_ask = []
    transactions = {}
    journal = {}

    # Get the data
    for char in chars:
        orders_bid += MarketOrder.objects.filter(character=char,
                                                 id__is_bid=True).select_related('id').extra(select={'total_value': "price * volume_entered",
                                                                                                     'total_value_remaining': "price * volume_remaining"}).order_by('order_state')

        orders_ask += MarketOrder.objects.filter(character=char,
                                                 id__is_bid=False).select_related('id').extra(select={'total_value': "price * volume_entered",
                                                                                                      'total_value_remaining': "price * volume_remaining"}).order_by('order_state')

        transactions[char.id] = MarketTransaction.objects.filter(character=char).select_related('ref_type')
        journal[char.id] = JournalEntry.objects.filter(character=char)

    # Add data to context
    rcontext = RequestContext(request, {'orders_bid': orders_bid,
                                        'orders_ask': orders_ask,
                                        'transactions': transactions,
                                        'journal': journal})

    return render_to_response('wallet/wallet.haml', rcontext)
Ejemplo n.º 6
0
def wallet(request):

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['WalletJournal']))

    # Prepare lists
    orders_bid = []
    orders_ask = []
    transactions = {}
    journal = {}

    # Get the data
    for char in chars:
        orders_bid += MarketOrder.objects.filter(character=char,
                                                 id__is_bid=True).select_related('id').extra(select={'total_value': "price * volume_entered",
                                                                                                     'total_value_remaining': "price * volume_remaining"}).order_by('order_state')

        orders_ask += MarketOrder.objects.filter(character=char,
                                                 id__is_bid=False).select_related('id').extra(select={'total_value': "price * volume_entered",
                                                                                                      'total_value_remaining': "price * volume_remaining"}).order_by('order_state')

        transactions[char.id] = MarketTransaction.objects.filter(character=char).select_related('ref_type')
        journal[char.id] = JournalEntry.objects.filter(character=char)

    # Add data to context
    rcontext = RequestContext(request, {'orders_bid': orders_bid,
                                        'orders_ask': orders_ask,
                                        'transactions': transactions,
                                        'journal': journal})

    return render_to_response('wallet.haml', rcontext)
Ejemplo n.º 7
0
def archived_orders(request):

    # Get all characters with sufficient permissions
    chars = validate_characters(
        request.user, calculate_character_access_mask(['MarketOrders']))

    # Get all active orders ordered by station for later regrouping
    all_orders = MarketOrder.objects.filter(character__in=chars).exclude(
        order_state=0).select_related('id').order_by('-id__generated_at')

    # Pagination
    paginator = Paginator(all_orders, 25)

    page = request.GET.get('page')
    try:
        orders = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        orders = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        orders = paginator.page(paginator.num_pages)

    # Add data to context
    rcontext = RequestContext(request, {'orders': orders})
    return render_to_response('archived_orders.haml', rcontext)
Ejemplo n.º 8
0
def active_orders(request):

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['MarketOrders']))

    # Get all active orders ordered by station for later regrouping
    orders = MarketOrder.objects.filter(character__in=chars, order_state=0).select_related('id').extra(select={'total_value': "price * volume_entered",
                                                                                                               'volume_percent': "(volume_remaining / volume_entered::float) * 100"}).order_by('id__stastation')

    # Add data to context
    rcontext = RequestContext(request, {'orders': orders})
    return render_to_response('wallet/active_orders.haml', rcontext)
Ejemplo n.º 9
0
def active_orders(request):

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['MarketOrders']))

    # Get all active orders ordered by station for later regrouping
    orders = MarketOrder.objects.filter(character__in=chars, order_state=0).select_related('id').extra(select={'total_value': "price * volume_entered",
                                                                                                               'volume_percent': "(volume_remaining / volume_entered::float) * 100"}).order_by('id__stastation')

    # Add data to context
    rcontext = RequestContext(request, {'orders': orders})
    return render_to_response('active_orders.haml', rcontext)
Ejemplo n.º 10
0
def type(request, type_id):

    type_object = InvType.objects.get(id=type_id)

    # Get all characters with sufficient permissions
    chars = validate_characters(
        request.user, calculate_character_access_mask(['WalletTransactions']))

    all_transactions = MarketTransaction.objects.filter(
        character__in=chars,
        invtype_id=type_id).extra(select={
            'revenue': "price * quantity"
        }).order_by('-date')

    # Pagination
    paginator = Paginator(all_transactions, 25)

    page = request.GET.get('page')
    try:
        transactions = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        transactions = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        transactions = paginator.page(paginator.num_pages)

    # Calculate stats
    spent = 0
    income = 0
    profit = 0

    for transaction in all_transactions:
        if transaction.is_bid:
            spent += transaction.revenue
        else:
            income += transaction.revenue

    profit = income - spent

    # Add data to context
    rcontext = RequestContext(
        request, {
            'type': type_object,
            'spent': spent,
            'income': income,
            'profit': profit,
            'transactions': transactions
        })

    return render_to_response('type.haml', rcontext)
Ejemplo n.º 11
0
def type(request, type_id):

    type_object = InvType.objects.get(id=type_id)

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['WalletTransactions']))

    all_transactions = MarketTransaction.objects.filter(character__in=chars,
                                                        invtype_id=type_id).extra(select={'revenue': "price * quantity"}).order_by('-date')

    # Pagination
    paginator = Paginator(all_transactions, 25)

    page = request.GET.get('page')
    try:
        transactions = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        transactions = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        transactions = paginator.page(paginator.num_pages)

    # Calculate stats
    spent = 0
    income = 0
    profit = 0

    for transaction in all_transactions:
        if transaction.is_bid:
            spent += transaction.revenue
        else:
            income += transaction.revenue

    profit = income - spent

    # Add data to context
    rcontext = RequestContext(request, {'type': type_object,
                                        'spent': spent,
                                        'income': income,
                                        'profit': profit,
                                        'transactions': transactions})

    return render_to_response('wallet/type.haml', rcontext)
Ejemplo n.º 12
0
def station_scanner(request, station_id):

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['MarketOrders']))

    # Get types of active orders in that station from db
    types = []
    type_ids = []

    orders = MarketOrder.objects.filter(character__in=chars, order_state=0, id__stastation=station_id).distinct('id__invtype')

    for order in orders:
        type_ids.append(order.id.invtype.id)

    for type_object in types:
        type_ids.append(type_object.id)

    rcontext = RequestContext(request, {'type_ids': type_ids})

    return render_to_response('wallet/scanner.haml', rcontext)
Ejemplo n.º 13
0
def station_scanner(request, station_id):

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['MarketOrders']))

    # Get types of active orders in that station from db
    types = []
    type_ids = []

    orders = MarketOrder.objects.filter(character__in=chars, order_state=0, id__stastation=station_id).distinct('id__invtype')

    for order in orders:
        type_ids.append(order.id.invtype.id)

    for type_object in types:
        type_ids.append(type_object.id)

    rcontext = RequestContext(request, {'type_ids': type_ids})

    return render_to_response('scanner.haml', rcontext)
Ejemplo n.º 14
0
def archived_orders(request):

    # Get all characters with sufficient permissions
    chars = validate_characters(request.user, calculate_character_access_mask(['MarketOrders']))

    # Get all active orders ordered by station for later regrouping
    all_orders = MarketOrder.objects.filter(character__in=chars).exclude(order_state=0).select_related('id').order_by('-id__generated_at')

    # Pagination
    paginator = Paginator(all_orders, 25)

    page = request.GET.get('page')
    try:
        orders = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        orders = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        orders = paginator.page(paginator.num_pages)

    # Add data to context
    rcontext = RequestContext(request, {'orders': orders})
    return render_to_response('wallet/archived_orders.haml', rcontext)