Exemple #1
0
 def test_get_for_or_create__create(self):
     AccountPrototype.get_for_or_create(entity_type=ENTITY_TYPE.GAME_LOGIC,
                                        entity_id=self.entity_id,
                                        currency=CURRENCY_TYPE.PREMIUM)
     self.assertEqual(
         AccountPrototype._model_class.objects.filter(
             entity_id=self.entity_id).count(), 2)
Exemple #2
0
    def test_freeze__for_noninfinite_both(self):
        recipient = AccountPrototype.create(
            entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=self.recipient_id, currency=CURRENCY_TYPE.PREMIUM
        )
        recipient.amount = 100
        recipient.save()

        sender = AccountPrototype.create(
            entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=self.sender_id, currency=CURRENCY_TYPE.PREMIUM
        )
        sender.amount = 100
        sender.save()

        self.check_freeze(
            recipient_type=ENTITY_TYPE.GAME_ACCOUNT,
            sender_type=ENTITY_TYPE.GAME_ACCOUNT,
            amount=100,
            initial_accounts_number=2,
            recipient_amount=100,
            sender_amount=100,
        )

        self.check_freeze(
            recipient_type=ENTITY_TYPE.GAME_ACCOUNT,
            sender_type=ENTITY_TYPE.GAME_ACCOUNT,
            amount=-50,
            initial_accounts_number=2,
            recipient_amount=100,
            sender_amount=100,
        )
Exemple #3
0
    def check_confirm(self, recipient_type, sender_type, initial_recipient_amount, initial_sender_amount, amount, result_recipient_amount, result_sender_amount):
        recipient = AccountPrototype.get_for_or_create(entity_type=recipient_type, entity_id=self.recipient_id, currency=CURRENCY_TYPE.PREMIUM)
        recipient.amount = initial_recipient_amount
        recipient.save()

        sender = AccountPrototype.get_for_or_create(entity_type=sender_type, entity_id=self.sender_id, currency=CURRENCY_TYPE.PREMIUM)
        sender.amount = initial_sender_amount
        sender.save()

        invoice = self.create_invoice(recipient_type=recipient_type,
                                      recipient_id=self.recipient_id,
                                      sender_type=sender_type,
                                      sender_id=self.sender_id,
                                      amount=amount)
        invoice.freeze()
        self.assertTrue(invoice.state.is_FROZEN)

        recipient.reload()
        sender.reload()

        self.assertEqual(recipient.amount, initial_recipient_amount)
        self.assertEqual(sender.amount, initial_sender_amount)

        invoice.confirm()

        recipient.reload()
        sender.reload()

        self.assertEqual(recipient.amount, result_recipient_amount)
        self.assertEqual(sender.amount, result_sender_amount)

        self.assertTrue(invoice.state.is_CONFIRMED)
Exemple #4
0
 def test_account_with_different_currency(self):
     AccountPrototype.create(entity_type=ENTITY_TYPE.GAME_ACCOUNT,
                             entity_id=self.entity_id,
                             currency=CURRENCY_TYPE.NORMAL)
     self.assertEqual(
         AccountPrototype._model_class.objects.filter(
             entity_id=self.entity_id).count(), 2)
Exemple #5
0
    def check_freeze(self,
                     recipient_type,
                     sender_type,
                     amount,
                     initial_accounts_number=0,
                     recipient_amount=0,
                     sender_amount=0):
        self.assertEqual(AccountPrototype._model_class.objects.all().count(),
                         initial_accounts_number)

        invoice = self.create_invoice(recipient_type=recipient_type,
                                      sender_type=sender_type,
                                      amount=amount)
        invoice.freeze()
        self.assertTrue(invoice.state.is_FROZEN)

        self.assertEqual(AccountPrototype._model_class.objects.all().count(),
                         2)

        recipient = AccountPrototype(model=AccountPrototype._model_class.
                                     objects.all().order_by('created_at')[0])
        self.assertEqual(recipient.amount, recipient_amount)
        self.assertEqual(recipient.entity_type, recipient_type)
        self.assertEqual(recipient.entity_id, self.recipient_id)
        self.assertTrue(recipient.currency.is_PREMIUM)

        sender = AccountPrototype(model=AccountPrototype._model_class.objects.
                                  all().order_by('created_at')[1])
        self.assertEqual(sender.amount, sender_amount)
        self.assertEqual(sender.entity_type, sender_type)
        self.assertEqual(sender.entity_id, self.sender_id)
        self.assertTrue(sender.currency.is_PREMIUM)
Exemple #6
0
    def test_freeze__for_noninfinite_both(self):
        recipient = AccountPrototype.create(
            entity_type=ENTITY_TYPE.GAME_ACCOUNT,
            entity_id=self.recipient_id,
            currency=CURRENCY_TYPE.PREMIUM)
        recipient.amount = 100
        recipient.save()

        sender = AccountPrototype.create(entity_type=ENTITY_TYPE.GAME_ACCOUNT,
                                         entity_id=self.sender_id,
                                         currency=CURRENCY_TYPE.PREMIUM)
        sender.amount = 100
        sender.save()

        self.check_freeze(recipient_type=ENTITY_TYPE.GAME_ACCOUNT,
                          sender_type=ENTITY_TYPE.GAME_ACCOUNT,
                          amount=100,
                          initial_accounts_number=2,
                          recipient_amount=100,
                          sender_amount=100)

        self.check_freeze(recipient_type=ENTITY_TYPE.GAME_ACCOUNT,
                          sender_type=ENTITY_TYPE.GAME_ACCOUNT,
                          amount=-50,
                          initial_accounts_number=2,
                          recipient_amount=100,
                          sender_amount=100)
Exemple #7
0
    def index(self):

        registration_attemps_number = AccountPrototype._model_class.objects.all().aggregate(models.Max('id'))['id__max']
        accounts_total = AccountPrototype._model_class.objects.all().count()
        accounts_bots = AccountPrototype._model_class.objects.filter(is_bot=True).count()
        accounts_registered = AccountPrototype.live_query().count()
        accounts_active = AccountPrototype.live_query().filter(active_end_at__gt=datetime.datetime.now()).count()
        accounts_premium = AccountPrototype.live_query().filter(premium_end_at__gt=datetime.datetime.now()).count()
        accounts_active_and_premium = AccountPrototype.live_query().filter(active_end_at__gt=datetime.datetime.now(),
                                                                           premium_end_at__gt=datetime.datetime.now()).count()

        accounts_referrals = AccountPrototype.live_query().exclude(referral_of=None).count()
        accounts_referrals_and_premium = AccountPrototype.live_query().exclude(referral_of=None).filter(premium_end_at__gt=datetime.datetime.now()).count()
        accounts_referrals_and_active = AccountPrototype.live_query().exclude(referral_of=None).filter(active_end_at__gt=datetime.datetime.now(),
                                                                                                       premium_end_at__gt=datetime.datetime.now()).count()

        gold = {}
        gold_total_spent = 0
        gold_total_received = 0
        real_gold_total_spent = 0
        real_gold_total_received = 0

        for record in BANK_ENTITY_TYPE.records:
            spent = -BankAccountPrototype._money_spent(from_type=record)
            received = BankAccountPrototype._money_received(from_type=record)
            gold[record.text] = {'spent': spent, 'received': received}

            gold_total_spent += spent
            gold_total_received += received

            if record.is_real:
                real_gold_total_spent += spent
                real_gold_total_received += received

        gold_in_game = gold_total_received - gold_total_spent
        real_gold_in_game = real_gold_total_received - real_gold_total_spent

        return self.template('developers_info/index.html',
                             {'registration_attemps_number': registration_attemps_number,
                              'accounts_total': accounts_total,
                              'accounts_bots': accounts_bots,
                              'accounts_registered': accounts_registered,
                              'accounts_active': accounts_active,
                              'accounts_premium': accounts_premium,
                              'accounts_active_and_premium': accounts_active_and_premium,
                              'accounts_referrals': accounts_referrals,
                              'accounts_referrals_and_premium': accounts_referrals_and_premium,
                              'accounts_referrals_and_active': accounts_referrals_and_active,
                              'gold': gold,
                              'gold_total_spent': gold_total_spent,
                              'gold_total_received': gold_total_received,
                              'gold_in_game': gold_in_game,
                              'real_gold_in_game': real_gold_in_game,
                              'referers_statistics': get_referers_statistics(),
                              'invoice_statistics': get_invoice_statistics(),
                              'invoice_count': InvoiceQuery.count(),
                              'repeatable_payments_statistics': get_repeatable_payments_statistics(),
                              'PAYMENT_GROUPS': PAYMENT_GROUPS,
                              'PREMIUM_DAYS_FOR_HERO_OF_THE_DAY': portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY,
                              'page_type': 'index'})
Exemple #8
0
    def setUp(self):
        super(_BaseBuyPosponedTaskTests, self).setUp()

        create_test_map()

        self.initial_amount = 500
        self.amount = 130

        self.account = self.accounts_factory.create_account()

        self.bank_account = BankAccountPrototype.create(
            entity_type=ENTITY_TYPE.GAME_ACCOUNT,
            entity_id=self.account.id,
            currency=CURRENCY_TYPE.PREMIUM)
        self.bank_account.amount = self.initial_amount
        self.bank_account.save()

        self.invoice = InvoicePrototype.create(
            recipient_type=ENTITY_TYPE.GAME_ACCOUNT,
            recipient_id=self.account.id,
            sender_type=ENTITY_TYPE.GAME_LOGIC,
            sender_id=0,
            currency=CURRENCY_TYPE.PREMIUM,
            amount=-self.amount,
            description_for_sender='transaction-description-for-sender',
            description_for_recipient='transaction-description-for-recipient',
            operation_uid='transaction-operation-ui')

        self.transaction = Transaction(self.invoice.id)

        self.task = None
        self.storage = None
        self.cmd_update_with_account_data__call_count = 1
        self.accounts_manages_worker = True
        self.supervisor_worker = False
Exemple #9
0
 def setUp(self):
     super(AccountPrototypeTests, self).setUp()
     self.entity_id = 2
     self.account = AccountPrototype.create(
         entity_type=ENTITY_TYPE.GAME_ACCOUNT,
         entity_id=self.entity_id,
         currency=CURRENCY_TYPE.PREMIUM)
Exemple #10
0
    def create_bank_account(self, entity_id, amount=0):
        account = AccountPrototype.create(entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=entity_id, currency=CURRENCY_TYPE.PREMIUM)

        account.amount = amount
        account.save()

        return account
Exemple #11
0
    def setUp(self):
        super(_BaseBuyPosponedTaskTests, self).setUp()

        create_test_map()

        self.initial_amount = 500
        self.amount = 130

        result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
        self.account = AccountPrototype.get_by_id(account_id)

        self.bank_account = BankAccountPrototype.create(entity_type=ENTITY_TYPE.GAME_ACCOUNT,
                                                        entity_id=self.account.id,
                                                        currency=CURRENCY_TYPE.PREMIUM)
        self.bank_account.amount = self.initial_amount
        self.bank_account.save()

        self.invoice = InvoicePrototype.create(recipient_type=ENTITY_TYPE.GAME_ACCOUNT,
                                               recipient_id=self.account.id,
                                               sender_type=ENTITY_TYPE.GAME_LOGIC,
                                               sender_id=0,
                                               currency=CURRENCY_TYPE.PREMIUM,
                                               amount=-self.amount,
                                               description_for_sender='transaction-description-for-sender',
                                               description_for_recipient='transaction-description-for-recipient',
                                               operation_uid='transaction-operation-ui')

        self.transaction = Transaction(self.invoice.id)

        self.task = None
        self.storage = None
        self.cmd_update_with_account_data__call_count = 1
        self.accounts_manages_worker = True
        self.supervisor_worker = False
Exemple #12
0
    def setUp(self):
        super(_BaseBuyPosponedTaskTests, self).setUp()

        create_test_map()

        self.initial_amount = 500
        self.amount = 130

        self.account = self.accounts_factory.create_account()

        self.bank_account = BankAccountPrototype.create(
            entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=self.account.id, currency=CURRENCY_TYPE.PREMIUM
        )
        self.bank_account.amount = self.initial_amount
        self.bank_account.save()

        self.invoice = InvoicePrototype.create(
            recipient_type=ENTITY_TYPE.GAME_ACCOUNT,
            recipient_id=self.account.id,
            sender_type=ENTITY_TYPE.GAME_LOGIC,
            sender_id=0,
            currency=CURRENCY_TYPE.PREMIUM,
            amount=-self.amount,
            description_for_sender="transaction-description-for-sender",
            description_for_recipient="transaction-description-for-recipient",
            operation_uid="transaction-operation-ui",
        )

        self.transaction = Transaction(self.invoice.id)

        self.task = None
        self.storage = None
        self.cmd_update_with_account_data__call_count = 1
        self.accounts_manages_worker = True
        self.supervisor_worker = False
Exemple #13
0
    def test_amount__infinit_account(self):
        self.assertTrue(ENTITY_TYPE.GAME_LOGIC.is_infinite)
        account = AccountPrototype.create(entity_type=ENTITY_TYPE.GAME_LOGIC, entity_id=self.entity_id, currency=CURRENCY_TYPE.PREMIUM)
        old_amount = account.amount

        account.amount += 100
        account.amount -= 10

        self.assertEqual(account.amount, old_amount)
Exemple #14
0
    def create_bank_account(self, entity_id, amount=0):
        account = AccountPrototype.create(entity_type=ENTITY_TYPE.GAME_ACCOUNT,
                                          entity_id=entity_id,
                                          currency=CURRENCY_TYPE.PREMIUM)

        account.amount = amount
        account.save()

        return account
Exemple #15
0
    def bank_account(self):
        from the_tale.finances.bank.prototypes import AccountPrototype as BankAccountPrototype
        from the_tale.finances.bank.relations import ENTITY_TYPE, CURRENCY_TYPE

        bank_account = BankAccountPrototype.get_for(entity_type=ENTITY_TYPE.GAME_ACCOUNT,
                                                    entity_id=self.id,
                                                    currency=CURRENCY_TYPE.PREMIUM,
                                                    null_object=True)

        return bank_account
Exemple #16
0
    def bank_account(self):
        from the_tale.finances.bank.prototypes import AccountPrototype as BankAccountPrototype
        from the_tale.finances.bank.relations import ENTITY_TYPE, CURRENCY_TYPE

        bank_account = BankAccountPrototype.get_for(entity_type=ENTITY_TYPE.GAME_ACCOUNT,
                                                    entity_id=self.id,
                                                    currency=CURRENCY_TYPE.PREMIUM,
                                                    null_object=True)

        return bank_account
Exemple #17
0
    def test_amount__infinit_account(self):
        self.assertTrue(ENTITY_TYPE.GAME_LOGIC.is_infinite)
        account = AccountPrototype.create(entity_type=ENTITY_TYPE.GAME_LOGIC,
                                          entity_id=self.entity_id,
                                          currency=CURRENCY_TYPE.PREMIUM)
        old_amount = account.amount

        account.amount += 100
        account.amount -= 10

        self.assertEqual(account.amount, old_amount)
Exemple #18
0
    def check_confirm(self, recipient_type, sender_type,
                      initial_recipient_amount, initial_sender_amount, amount,
                      result_recipient_amount, result_sender_amount):
        recipient = AccountPrototype.get_for_or_create(
            entity_type=recipient_type,
            entity_id=self.recipient_id,
            currency=CURRENCY_TYPE.PREMIUM)
        recipient.amount = initial_recipient_amount
        recipient.save()

        sender = AccountPrototype.get_for_or_create(
            entity_type=sender_type,
            entity_id=self.sender_id,
            currency=CURRENCY_TYPE.PREMIUM)
        sender.amount = initial_sender_amount
        sender.save()

        invoice = self.create_invoice(recipient_type=recipient_type,
                                      recipient_id=self.recipient_id,
                                      sender_type=sender_type,
                                      sender_id=self.sender_id,
                                      amount=amount)
        invoice.freeze()
        self.assertTrue(invoice.state.is_FROZEN)

        recipient.reload()
        sender.reload()

        self.assertEqual(recipient.amount, initial_recipient_amount)
        self.assertEqual(sender.amount, initial_sender_amount)

        invoice.confirm()

        recipient.reload()
        sender.reload()

        self.assertEqual(recipient.amount, result_recipient_amount)
        self.assertEqual(sender.amount, result_sender_amount)

        self.assertTrue(invoice.state.is_CONFIRMED)
Exemple #19
0
    def check_force(self, recipient_type, sender_type, initial_recipient_amount, initial_sender_amount, amount, result_recipient_amount, result_sender_amount):

        invoice = self.create_invoice(recipient_type=recipient_type, sender_type=sender_type, amount=amount)
        invoice.freeze()
        self.assertTrue(invoice.state.is_FROZEN)

        self.assertEqual(AccountPrototype._model_class.objects.all().count(), 2)

        recipient = AccountPrototype(model=AccountPrototype._model_class.objects.all().order_by('created_at')[0])
        self.assertEqual(recipient.amount, initial_recipient_amount)
        self.assertEqual(recipient.entity_type, recipient_type)
        self.assertEqual(recipient.entity_id, self.recipient_id)
        self.assertTrue(recipient.currency.is_PREMIUM)

        sender = AccountPrototype(model=AccountPrototype._model_class.objects.all().order_by('created_at')[1])
        self.assertEqual(sender.amount, initial_sender_amount)
        self.assertEqual(sender.entity_type, sender_type)
        self.assertEqual(sender.entity_id, self.sender_id)
        self.assertTrue(sender.currency.is_PREMIUM)

        invoice = self.create_invoice(recipient_type=recipient_type,
                                      recipient_id=self.recipient_id,
                                      sender_type=sender_type,
                                      sender_id=self.sender_id,
                                      amount=amount,
                                      force=True)
        invoice.force()
        self.assertTrue(invoice.state.is_CONFIRMED)

        recipient.reload()
        sender.reload()

        self.assertEqual(recipient.amount, result_recipient_amount)
        self.assertEqual(sender.amount, result_sender_amount)
Exemple #20
0
def get_referers_statistics():

    raw_statistics = AccountPrototype.live_query().values(
        'referer_domain').order_by().annotate(models.Count('referer_domain'))

    statistics = {}

    for s in raw_statistics:
        domain = s['referer_domain']

        count = s['referer_domain__count']

        query = AccountPrototype.live_query().filter(referer_domain=domain)

        if domain is None:
            count = query.count()

        target_domain = domain

        if target_domain and target_domain.endswith(
                'livejournal.com'
        ):  # hide all domains username.livejournal.com (to hide there payment info)
            target_domain = 'livejournal.com'

        st = RefererStatistics(
            domain=target_domain,
            count=count,
            active_accounts=query.filter(
                active_end_at__gt=datetime.datetime.now()).count(),
            premium_accounts=query.filter(
                premium_end_at__gt=datetime.datetime.now()).count(),
            active_and_premium=query.filter(
                active_end_at__gt=datetime.datetime.now(),
                premium_end_at__gt=datetime.datetime.now()).count(),
            premium_currency=BankAccountPrototype._money_received(
                from_type=BANK_ENTITY_TYPE.XSOLLA,
                accounts_ids=query.values_list('id', flat=True)))

        if st.domain in statistics:
            statistics[st.domain] = statistics[st.domain] + st
        else:
            statistics[st.domain] = st

    statistics = sorted(statistics.values(), key=lambda s: -s.count)

    return statistics
Exemple #21
0
def get_referers_statistics():

    raw_statistics = (
        AccountPrototype.live_query().values("referer_domain").order_by().annotate(models.Count("referer_domain"))
    )

    statistics = {}

    for s in raw_statistics:
        domain = s["referer_domain"]

        count = s["referer_domain__count"]

        query = AccountPrototype.live_query().filter(referer_domain=domain)

        if domain is None:
            count = query.count()

        target_domain = domain

        if target_domain and target_domain.endswith(
            "livejournal.com"
        ):  # hide all domains username.livejournal.com (to hide there payment info)
            target_domain = "livejournal.com"

        st = RefererStatistics(
            domain=target_domain,
            count=count,
            active_accounts=query.filter(active_end_at__gt=datetime.datetime.now()).count(),
            premium_accounts=query.filter(premium_end_at__gt=datetime.datetime.now()).count(),
            active_and_premium=query.filter(
                active_end_at__gt=datetime.datetime.now(), premium_end_at__gt=datetime.datetime.now()
            ).count(),
            premium_currency=BankAccountPrototype._money_received(
                from_type=BANK_ENTITY_TYPE.XSOLLA, accounts_ids=query.values_list("id", flat=True)
            ),
        )

        if st.domain in statistics:
            statistics[st.domain] = statistics[st.domain] + st
        else:
            statistics[st.domain] = st

    statistics = sorted(list(statistics.values()), key=lambda s: -s.count)

    return statistics
Exemple #22
0
    def check_force(self, recipient_type, sender_type,
                    initial_recipient_amount, initial_sender_amount, amount,
                    result_recipient_amount, result_sender_amount):

        invoice = self.create_invoice(recipient_type=recipient_type,
                                      sender_type=sender_type,
                                      amount=amount)
        invoice.freeze()
        self.assertTrue(invoice.state.is_FROZEN)

        self.assertEqual(AccountPrototype._model_class.objects.all().count(),
                         2)

        recipient = AccountPrototype(model=AccountPrototype._model_class.
                                     objects.all().order_by('created_at')[0])
        self.assertEqual(recipient.amount, initial_recipient_amount)
        self.assertEqual(recipient.entity_type, recipient_type)
        self.assertEqual(recipient.entity_id, self.recipient_id)
        self.assertTrue(recipient.currency.is_PREMIUM)

        sender = AccountPrototype(model=AccountPrototype._model_class.objects.
                                  all().order_by('created_at')[1])
        self.assertEqual(sender.amount, initial_sender_amount)
        self.assertEqual(sender.entity_type, sender_type)
        self.assertEqual(sender.entity_id, self.sender_id)
        self.assertTrue(sender.currency.is_PREMIUM)

        invoice = self.create_invoice(recipient_type=recipient_type,
                                      recipient_id=self.recipient_id,
                                      sender_type=sender_type,
                                      sender_id=self.sender_id,
                                      amount=amount,
                                      force=True)
        invoice.force()
        self.assertTrue(invoice.state.is_CONFIRMED)

        recipient.reload()
        sender.reload()

        self.assertEqual(recipient.amount, result_recipient_amount)
        self.assertEqual(sender.amount, result_sender_amount)
Exemple #23
0
 def test_get_for_or_create__get(self):
     AccountPrototype.get_for_or_create(
         entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=self.entity_id, currency=CURRENCY_TYPE.PREMIUM
     )
     self.assertEqual(AccountPrototype._model_class.objects.filter(entity_id=self.entity_id).count(), 1)
Exemple #24
0
 def test_account_with_different_entity_type(self):
     AccountPrototype.create(
         entity_type=ENTITY_TYPE.GAME_LOGIC, entity_id=self.entity_id, currency=CURRENCY_TYPE.PREMIUM
     )
     self.assertEqual(AccountPrototype._model_class.objects.filter(entity_id=self.entity_id).count(), 2)
Exemple #25
0
 def test_account_with_different_currency(self):
     AccountPrototype.create(
         entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=self.entity_id, currency=CURRENCY_TYPE.NORMAL
     )
     self.assertEqual(AccountPrototype._model_class.objects.filter(entity_id=self.entity_id).count(), 2)
Exemple #26
0
 def setUp(self):
     super(AccountPrototypeTests, self).setUp()
     self.entity_id = 2
     self.account = AccountPrototype.create(
         entity_type=ENTITY_TYPE.GAME_ACCOUNT, entity_id=self.entity_id, currency=CURRENCY_TYPE.PREMIUM
     )
Exemple #27
0
    def index(self):

        registration_attemps_number = AccountPrototype._model_class.objects.all(
        ).aggregate(models.Max('id'))['id__max']
        accounts_total = AccountPrototype._model_class.objects.all().count()
        accounts_bots = AccountPrototype._model_class.objects.filter(
            is_bot=True).count()
        accounts_registered = AccountPrototype.live_query().count()
        accounts_active = AccountPrototype.live_query().filter(
            active_end_at__gt=datetime.datetime.now()).count()
        accounts_premium = AccountPrototype.live_query().filter(
            premium_end_at__gt=datetime.datetime.now()).count()
        accounts_active_and_premium = AccountPrototype.live_query().filter(
            active_end_at__gt=datetime.datetime.now(),
            premium_end_at__gt=datetime.datetime.now()).count()

        accounts_referrals = AccountPrototype.live_query().exclude(
            referral_of=None).count()
        accounts_referrals_and_premium = AccountPrototype.live_query().exclude(
            referral_of=None).filter(
                premium_end_at__gt=datetime.datetime.now()).count()
        accounts_referrals_and_active = AccountPrototype.live_query().exclude(
            referral_of=None).filter(
                active_end_at__gt=datetime.datetime.now(),
                premium_end_at__gt=datetime.datetime.now()).count()

        gold = {}
        gold_total_spent = 0
        gold_total_received = 0
        real_gold_total_spent = 0
        real_gold_total_received = 0

        for record in BANK_ENTITY_TYPE.records:
            spent = -BankAccountPrototype._money_spent(from_type=record)
            received = BankAccountPrototype._money_received(from_type=record)
            gold[record.text] = {'spent': spent, 'received': received}

            gold_total_spent += spent
            gold_total_received += received

            if record.is_real:
                real_gold_total_spent += spent
                real_gold_total_received += received

        gold_in_game = gold_total_received - gold_total_spent
        real_gold_in_game = real_gold_total_received - real_gold_total_spent

        return self.template(
            'developers_info/index.html', {
                'registration_attemps_number':
                registration_attemps_number,
                'accounts_total':
                accounts_total,
                'accounts_bots':
                accounts_bots,
                'accounts_registered':
                accounts_registered,
                'accounts_active':
                accounts_active,
                'accounts_premium':
                accounts_premium,
                'accounts_active_and_premium':
                accounts_active_and_premium,
                'accounts_referrals':
                accounts_referrals,
                'accounts_referrals_and_premium':
                accounts_referrals_and_premium,
                'accounts_referrals_and_active':
                accounts_referrals_and_active,
                'gold':
                gold,
                'gold_total_spent':
                gold_total_spent,
                'gold_total_received':
                gold_total_received,
                'gold_in_game':
                gold_in_game,
                'real_gold_in_game':
                real_gold_in_game,
                'referers_statistics':
                get_referers_statistics(),
                'invoice_statistics':
                get_invoice_statistics(),
                'invoice_count':
                InvoiceQuery.count(),
                'repeatable_payments_statistics':
                get_repeatable_payments_statistics(),
                'PAYMENT_GROUPS':
                PAYMENT_GROUPS,
                'PREMIUM_DAYS_FOR_HERO_OF_THE_DAY':
                portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY,
                'page_type':
                'index'
            })
Exemple #28
0
    def index(self):

        registration_attemps_number = AccountPrototype._model_class.objects.all().aggregate(models.Max("id"))["id__max"]
        accounts_total = AccountPrototype._model_class.objects.all().count()
        accounts_bots = AccountPrototype._model_class.objects.filter(is_bot=True).count()
        accounts_registered = AccountPrototype.live_query().count()
        accounts_active = AccountPrototype.live_query().filter(active_end_at__gt=datetime.datetime.now()).count()
        accounts_premium = AccountPrototype.live_query().filter(premium_end_at__gt=datetime.datetime.now()).count()
        accounts_active_and_premium = (
            AccountPrototype.live_query()
            .filter(active_end_at__gt=datetime.datetime.now(), premium_end_at__gt=datetime.datetime.now())
            .count()
        )

        accounts_referrals = AccountPrototype.live_query().exclude(referral_of=None).count()
        accounts_referrals_and_premium = (
            AccountPrototype.live_query()
            .exclude(referral_of=None)
            .filter(premium_end_at__gt=datetime.datetime.now())
            .count()
        )
        accounts_referrals_and_active = (
            AccountPrototype.live_query()
            .exclude(referral_of=None)
            .filter(active_end_at__gt=datetime.datetime.now(), premium_end_at__gt=datetime.datetime.now())
            .count()
        )

        gold = {}
        gold_total_spent = 0
        gold_total_received = 0
        real_gold_total_spent = 0
        real_gold_total_received = 0

        for record in BANK_ENTITY_TYPE.records:
            spent = -BankAccountPrototype._money_spent(from_type=record)
            received = BankAccountPrototype._money_received(from_type=record)
            gold[record.text] = {"spent": spent, "received": received}

            gold_total_spent += spent
            gold_total_received += received

            if record.is_real:
                real_gold_total_spent += spent
                real_gold_total_received += received

        gold_in_game = gold_total_received - gold_total_spent
        real_gold_in_game = real_gold_total_received - real_gold_total_spent

        return self.template(
            "developers_info/index.html",
            {
                "registration_attemps_number": registration_attemps_number,
                "accounts_total": accounts_total,
                "accounts_bots": accounts_bots,
                "accounts_registered": accounts_registered,
                "accounts_active": accounts_active,
                "accounts_premium": accounts_premium,
                "accounts_active_and_premium": accounts_active_and_premium,
                "accounts_referrals": accounts_referrals,
                "accounts_referrals_and_premium": accounts_referrals_and_premium,
                "accounts_referrals_and_active": accounts_referrals_and_active,
                "gold": gold,
                "gold_total_spent": gold_total_spent,
                "gold_total_received": gold_total_received,
                "gold_in_game": gold_in_game,
                "real_gold_in_game": real_gold_in_game,
                "referers_statistics": get_referers_statistics(),
                "invoice_statistics": get_invoice_statistics(),
                "invoice_count": InvoiceQuery.count(),
                "repeatable_payments_statistics": get_repeatable_payments_statistics(),
                "PAYMENT_GROUPS": PAYMENT_GROUPS,
                "PREMIUM_DAYS_FOR_HERO_OF_THE_DAY": portal_settings.PREMIUM_DAYS_FOR_HERO_OF_THE_DAY,
                "page_type": "index",
            },
        )