Beispiel #1
0
    def send_message(self, message):

        if message is None:
            return False

        if (not post_service_settings.ENABLE_MESSAGE_SENDER or
            (settings.get(post_service_settings.SETTINGS_ALLOWED_KEY) is None
             and message.handler.settings_type_uid not in settings.get(
                 post_service_settings.SETTINGS_FORCE_ALLOWED_KEY, ''))):
            self.logger.info('skip message %s' % message.uid)
            message.skip()
            return True

        self.logger.info('process message %s' % message.uid)

        message.process()

        if message.state.is_PROCESSED:
            self.logger.info('message %s status %s' %
                             (message.uid, message.state))
        else:
            self.logger.error('message %s status %s ' %
                              (message.uid, message.state))

        return True
Beispiel #2
0
    def process_no_cmd(self):

        # check if new real day started
        if (time.time() - float(settings.get(portal_settings.SETTINGS_PREV_REAL_DAY_STARTED_TIME_KEY, 0)) > 23.5*60*60 and
            datetime.datetime.now().hour >= portal_settings.REAL_DAY_STARTED_TIME):
            portal_signals.day_started.send(self.__class__)
            settings[portal_settings.SETTINGS_PREV_REAL_DAY_STARTED_TIME_KEY] = str(time.time())
            return

        # is cleaning run needed
        if (time.time() - float(settings.get(portal_settings.SETTINGS_PREV_CLEANING_RUN_TIME_KEY, 0)) > 23.5*60*60 and
            portal_settings.CLEANING_RUN_TIME <= datetime.datetime.now().hour <= portal_settings.CLEANING_RUN_TIME + 1):
            settings[portal_settings.SETTINGS_PREV_CLEANING_RUN_TIME_KEY] = str(time.time())
            self.run_cleaning()
            return

        # is statistics run needed
        if (time.time() - float(settings.get(portal_settings.SETTINGS_PREV_STATISTICS_RUN_TIME_KEY, 0)) > 23.5*60*60 and
            portal_settings.STATISTICS_RUN_TIME <= datetime.datetime.now().hour <= portal_settings.STATISTICS_RUN_TIME + 1):
            settings[portal_settings.SETTINGS_PREV_STATISTICS_RUN_TIME_KEY] = str(time.time())
            self.run_statistics()
            return

        # is rating sync needed
        if self._try_run_command_with_delay(cmd=self.run_recalculate_ratings,
                                            settings_key=portal_settings.SETTINGS_PREV_RATINGS_SYNC_TIME_KEY,
                                            delay=portal_settings.RATINGS_SYNC_DELAY):
            return

        # is might sync needed
        if self._try_run_command_with_delay(cmd=self.run_recalculate_might,
                                            settings_key=portal_settings.SETTINGS_PREV_MIGHT_SYNC_TIME_KEY,
                                            delay=portal_settings.MIGHT_SYNC_DELAY):
            return

        # is cdns refresh needed
        if self._try_run_command_with_delay(cmd=self.run_refresh_cdns,
                                            settings_key=portal_settings.SETTINGS_PREV_CDN_SYNC_TIME_KEY,
                                            delay=portal_settings.CDN_SYNC_DELAY):
            return

        # is remove expired access tokens refresh needed
        if self._try_run_command_with_delay(cmd=self.run_remove_expired_access_tokens,
                                            settings_key=portal_settings.SETTINGS_PREV_EXPIRE_ACCESS_TOKENS_SYNC_TIME_KEY,
                                            delay=portal_settings.EXPIRE_ACCESS_TOKENS_SYNC_DELAY):
            return

        # is linguistic cleaning needed
        if self._try_run_command_with_delay(cmd=self.run_clean_removed_templates,
                                            settings_key=portal_settings.SETTINGS_PREV_CLEAN_REMOVED_TEMPLATES_KEY,
                                            delay=portal_settings.EXPIRE_CLEAN_REMOVED_TEMPLATES):
            return
Beispiel #3
0
    def _try_run_command_with_delay(self, cmd, settings_key, delay):
        if time.time() - float(settings.get(settings_key, 0)) > delay:
            settings[settings_key] = str(time.time())
            cmd()
            return True

        return False
Beispiel #4
0
    def preprocess(self, context):
        real_payments_enabled = (
            settings.get(payments_settings.SETTINGS_ALLOWED_KEY)
            and (payments_settings.ENABLE_REAL_PAYMENTS or context.account.id
                 in payments_settings.ALWAYS_ALLOWED_ACCOUNTS))

        context.xsolla_enabled = real_payments_enabled and payments_settings.XSOLLA_ENABLED
Beispiel #5
0
    def _try_run_command_with_delay(self, cmd, settings_key, delay):
        if time.time() - float(settings.get(settings_key, 0)) > delay:
            settings[settings_key] = str(time.time())
            cmd()
            return True

        return False
Beispiel #6
0
    def refresh(self):
        self.clear()

        for forms in self._words_query().iterator():
            word = utg_words.Word.deserialize(s11n.from_json(forms))
            self._item.add_word(word)

        self._version = settings.get(self.SETTINGS_KEY)
Beispiel #7
0
    def refresh(self):
        self.clear()

        for forms in self._words_query().iterator():
            word = utg_words.Word.deserialize(s11n.from_json(forms))
            self._item.add_word(word)

        self._version = settings.get(self.SETTINGS_KEY)
Beispiel #8
0
    def sync(self, force=False):
        if self._version != settings.get(self.SETTINGS_KEY):
            self.refresh()
            return

        if force:
            self.refresh()
            return
Beispiel #9
0
    def refresh(self):
        self.clear()

        self._version = settings.get(self.SETTINGS_KEY)

        for model in self._get_all_query():
            item = self._construct_object(model)
            self.add_item(item.id, item)
Beispiel #10
0
    def process_no_cmd(self):

        # is send premium expired notifications needed
        if (time.time() - float(settings.get(accounts_settings.SETTINGS_PREV_PREIMIUM_EXPIRED_NOTIFICATION_RUN_TIME_KEY, 0)) > 23.5*60*60 and
            accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_RUN_TIME <= datetime.datetime.now().hour <= accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_RUN_TIME+1):
            settings[accounts_settings.SETTINGS_PREV_PREIMIUM_EXPIRED_NOTIFICATION_RUN_TIME_KEY] = str(time.time())
            self.run_send_premium_expired_notifications()
            return

        self.run_random_premium_requests_processing()
Beispiel #11
0
    def check_frozen_expired_invoices(self):

        if time.time() - float(settings.get(bank_settings.SETTINGS_LAST_FROZEN_EXPIRED_CHECK_KEY, 0)) < bank_settings.FROZEN_INVOICE_EXPIRED_CHECK_TIMEOUT:
            return

        settings[bank_settings.SETTINGS_LAST_FROZEN_EXPIRED_CHECK_KEY] = str(time.time())

        if not InvoicePrototype.check_frozen_expired_invoices():
            return

        self.logger.error('We have some expired frozen invoices. Please, check them and remove or find error.')
Beispiel #12
0
    def refresh(self):
        self.clear()

        for key, data in self._templates_query().iterator():
            data = s11n.from_json(data)
            template = utg_templates.Template.deserialize(data['template'])
            restrictions = frozenset(
                tuple(key) for key in data.get('restrictions', ()))
            self._item.add_template(key, template, restrictions=restrictions)

        self._version = settings.get(self.SETTINGS_KEY)
Beispiel #13
0
    def check_frozen_expired_invoices(self):

        if time.time() - float(settings.get(bank_settings.SETTINGS_LAST_FROZEN_EXPIRED_CHECK_KEY, 0)) < bank_settings.FROZEN_INVOICE_EXPIRED_CHECK_TIMEOUT:
            return

        settings[bank_settings.SETTINGS_LAST_FROZEN_EXPIRED_CHECK_KEY] = str(time.time())

        if not InvoicePrototype.check_frozen_expired_invoices():
            return

        self.logger.error('We have some expired frozen invoices. Please, check them and remove or find error.')
Beispiel #14
0
    def refresh(self):
        from the_tale.linguistics.lexicon.keys import LEXICON_KEY

        self.clear()

        for key, data in self._templates_query().iterator():
            data = s11n.from_json(data)
            template = utg_templates.Template.deserialize(data["template"])
            restrictions = frozenset(tuple(key) for key in data.get("restrictions", ()))
            self._item.add_template(LEXICON_KEY(key), template, restrictions=restrictions)

        self._version = settings.get(self.SETTINGS_KEY)
Beispiel #15
0
    def send_message(self, message):

        if message is None:
            return False

        if (not post_service_settings.ENABLE_MESSAGE_SENDER or
            (settings.get(post_service_settings.SETTINGS_ALLOWED_KEY) is None and
             message.handler.settings_type_uid not in settings.get(post_service_settings.SETTINGS_FORCE_ALLOWED_KEY, ''))):
            self.logger.info('skip message %s' % message.uid)
            message.skip()
            return True

        self.logger.info('process message %s' % message.uid)

        message.process()

        if message.state.is_PROCESSED:
            self.logger.info('message %s status %s' % (message.uid, message.state))
        else:
            self.logger.error('message %s status %s ' % (message.uid, message.state))

        return True
Beispiel #16
0
    def index(self):

        if portal_settings.ENABLE_FIRST_TIME_REDIRECT and accounts_logic.is_first_time_visit(self.request):
            return self.redirect(random.choice(portal_settings.FIRST_TIME_LANDING_URLS))

        news = news_logic.load_news_from_query(news_models.News.objects.all().order_by('-created_at')[:portal_settings.NEWS_ON_INDEX])

        bills = BillPrototype.get_recently_modified_bills(portal_settings.BILLS_ON_INDEX)

        account_of_the_day_id = settings.get(portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY)

        hero_of_the_day = None
        account_of_the_day = None
        clan_of_the_day = None

        if account_of_the_day_id is not None:
            hero_of_the_day = heroes_logic.load_hero(account_id=account_of_the_day_id)
            account_of_the_day = AccountPrototype.get_by_id(account_of_the_day_id)

            if account_of_the_day.clan_id is not None:
                clan_of_the_day = ClanPrototype.get_by_id(account_of_the_day.clan_id)

        forum_threads = ThreadPrototype.get_last_threads(account=self.account if self.account.is_authenticated() else None,
                                                         limit=portal_settings.FORUM_THREADS_ON_INDEX)

        blog_posts = [ BlogPostPrototype(blog_post_model)
                       for blog_post_model in BlogPost.objects.filter(state__in=[BLOG_POST_STATE.ACCEPTED, BLOG_POST_STATE.NOT_MODERATED],
                                                                      votes__gte=0).order_by('-created_at')[:portal_settings.BLOG_POSTS_ON_INDEX] ]

        map_info = map_info_storage.item

        chronicle_records = ChronicleRecordPrototype.get_last_records(portal_settings.CHRONICLE_RECORDS_ON_INDEX)

        chronicle_actors = RecordToActorPrototype.get_actors_for_records(chronicle_records)

        return self.template('portal/index.html',
                             {'news': news,
                              'forum_threads': forum_threads,
                              'bills': bills,
                              'hero_of_the_day': hero_of_the_day,
                              'account_of_the_day': account_of_the_day,
                              'clan_of_the_day': clan_of_the_day,
                              'map_info': map_info,
                              'blog_posts': blog_posts,
                              'TERRAIN': TERRAIN,
                              'MAP_STATISTICS': MAP_STATISTICS,
                              'chronicle_records': chronicle_records,
                              'chronicle_actors': chronicle_actors,
                              'RACE': RACE})
Beispiel #17
0
    def refresh(self):
        from the_tale.linguistics.lexicon.keys import LEXICON_KEY

        self.clear()

        for key, data in self._templates_query().iterator():
            data = s11n.from_json(data)
            template = utg_templates.Template.deserialize(data['template'])
            restrictions = frozenset(
                tuple(key) for key in data.get('restrictions', ()))
            self._item.add_template(LEXICON_KEY(key),
                                    template,
                                    restrictions=restrictions)

        self._version = settings.get(self.SETTINGS_KEY)
Beispiel #18
0
    def process_no_cmd(self):

        # is send premium expired notifications needed
        if (time.time() - float(
                settings.get(
                    accounts_settings.
                    SETTINGS_PREV_PREIMIUM_EXPIRED_NOTIFICATION_RUN_TIME_KEY,
                    0)) > 23.5 * 60 * 60
                and accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_RUN_TIME <=
                datetime.datetime.now().hour <=
                accounts_settings.PREMIUM_EXPIRED_NOTIFICATION_RUN_TIME + 1):
            settings[
                accounts_settings.
                SETTINGS_PREV_PREIMIUM_EXPIRED_NOTIFICATION_RUN_TIME_KEY] = str(
                    time.time())
            self.run_send_premium_expired_notifications()
            return

        self.run_random_premium_requests_processing()
Beispiel #19
0
    def process_init_invoice(self):

        invoice = InvoicePrototype.get_unprocessed_invoice()

        if invoice is None:
            return

        if (not bank_settings.ENABLE_BANK or
            settings.get(bank_settings.SETTINGS_ALLOWED_KEY) is None):
            self.logger.info('postpone invoice %d' % invoice.id)
            return

        self.logger.info('process invoice %s' % invoice.id)

        if invoice.state.is_REQUESTED:
            invoice.freeze()
        elif invoice.state.is_FORCED:
            invoice.force()
        else:
            raise BankException('unknown invoice %d state %s' % (invoice.id, invoice.state))

        self.logger.info('invoice %s status %s' % (invoice.id, invoice.state))
Beispiel #20
0
    def process_init_invoice(self):

        invoice = InvoicePrototype.get_unprocessed_invoice()

        if invoice is None:
            return

        if (not bank_settings.ENABLE_BANK or
            settings.get(bank_settings.SETTINGS_ALLOWED_KEY) is None):
            self.logger.info('postpone invoice %d' % invoice.id)
            return

        self.logger.info('process invoice %s' % invoice.id)

        if invoice.state.is_REQUESTED:
            invoice.freeze()
        elif invoice.state.is_FORCED:
            invoice.force()
        else:
            raise BankException('unknown invoice %d state %s' % (invoice.id, invoice.state))

        self.logger.info('invoice %s status %s' % (invoice.id, invoice.state))
Beispiel #21
0
    def handle(self, *args, **options):

        force_clear = options.get('force-clear')
        verbose = options.get('verbose')
        recalculate = options.get('recalculate-last')

        if recalculate:
            for MetricClass in METRICS:
                RecordPrototype._db_filter(date=MetricClass._last_datetime().date(),
                                           type=MetricClass.TYPE).delete()

        for MetricClass in METRICS:
            if force_clear or MetricClass.FULL_CLEAR_RECUIRED:
                if verbose:
                    print 'clear %s' % MetricClass.TYPE
                MetricClass.clear()

        for i, MetricClass in enumerate(METRICS):
            metric = MetricClass()
            if verbose:
                print '[%3d] calculate %s' % (i, metric.TYPE)

            metric.initialize()
            metric.complete_values()


        data_version = int(settings.get(statistics_settings.JS_DATA_FILE_VERSION_KEY, 0))
        data_version += 1
        output_file = statistics_settings.JS_DATA_FILE_LOCATION % data_version

        output_dir_name = os.path.dirname(output_file)
        if not os.path.exists(output_dir_name):
            os.makedirs(output_dir_name, 0755)

        with open(output_file, 'w') as f:
            f.write(jinja2.render('statistics/js_data.js',
                                  context={'data': s11n.to_json(RecordPrototype.get_js_data())}).encode('utf-8'))

        settings[statistics_settings.JS_DATA_FILE_VERSION_KEY] = str(data_version)
Beispiel #22
0
    def index(self):

        if portal_settings.ENABLE_FIRST_TIME_REDIRECT and accounts_logic.is_first_time_visit(
                self.request):
            return self.redirect(
                random.choice(portal_settings.FIRST_TIME_LANDING_URLS))

        news = news_logic.load_news_from_query(
            news_models.News.objects.all().order_by(
                '-created_at')[:portal_settings.NEWS_ON_INDEX])

        bills = BillPrototype.get_recently_modified_bills(
            portal_settings.BILLS_ON_INDEX)

        account_of_the_day_id = settings.get(
            portal_settings.SETTINGS_ACCOUNT_OF_THE_DAY_KEY)

        hero_of_the_day = None
        account_of_the_day = None
        clan_of_the_day = None

        if account_of_the_day_id is not None:
            hero_of_the_day = heroes_logic.load_hero(
                account_id=account_of_the_day_id)
            account_of_the_day = AccountPrototype.get_by_id(
                account_of_the_day_id)

            if account_of_the_day and account_of_the_day.clan_id is not None:
                clan_of_the_day = ClanPrototype.get_by_id(
                    account_of_the_day.clan_id)

        forum_threads = ThreadPrototype.get_last_threads(
            account=self.account if self.account.is_authenticated else None,
            limit=portal_settings.FORUM_THREADS_ON_INDEX)

        blog_posts = [
            BlogPostPrototype(blog_post_model)
            for blog_post_model in BlogPost.objects.filter(state__in=[
                BLOG_POST_STATE.ACCEPTED, BLOG_POST_STATE.NOT_MODERATED
            ],
                                                           votes__gte=0).
            order_by('-created_at')[:portal_settings.BLOG_POSTS_ON_INDEX]
        ]

        map_info = map_info_storage.item

        chronicle_records = ChronicleRecordPrototype.get_last_records(
            portal_settings.CHRONICLE_RECORDS_ON_INDEX)

        chronicle_actors = RecordToActorPrototype.get_actors_for_records(
            chronicle_records)

        return self.template(
            'portal/index.html', {
                'news': news,
                'forum_threads': forum_threads,
                'bills': bills,
                'hero_of_the_day': hero_of_the_day,
                'account_of_the_day': account_of_the_day,
                'clan_of_the_day': clan_of_the_day,
                'map_info': map_info,
                'blog_posts': blog_posts,
                'TERRAIN': TERRAIN,
                'MAP_STATISTICS': MAP_STATISTICS,
                'chronicle_records': chronicle_records,
                'chronicle_actors': chronicle_actors,
                'RACE': RACE
            })
Beispiel #23
0
    def show(self, page=1):  # pylint: disable=R0914

        ratings_updated_at_timestamp = settings.get(
            ratings_settings.SETTINGS_UPDATE_TIMESTEMP_KEY, None)

        ratings_query = RatingPlaces.objects.all().select_related()

        place_getter = None
        value_getter = None

        if self.rating_type.is_MIGHT:
            ratings_query = ratings_query.filter(
                account__ratingvalues__might__gt=0).order_by('might_place')
            place_getter = lambda places: places.might_place
            value_getter = lambda values: '%.2f' % values.might

        elif self.rating_type.is_BILLS:
            ratings_query = ratings_query.filter(
                account__ratingvalues__bills_count__gt=0).order_by(
                    'bills_count_place')
            place_getter = lambda places: places.bills_count_place
            value_getter = lambda values: values.bills_count

        elif self.rating_type.is_MAGIC_POWER:
            ratings_query = ratings_query.order_by('magic_power_place')
            place_getter = lambda places: places.magic_power_place
            value_getter = lambda values: values.magic_power

        elif self.rating_type.is_PHYSIC_POWER:
            ratings_query = ratings_query.order_by('physic_power_place')
            place_getter = lambda places: places.physic_power_place
            value_getter = lambda values: values.physic_power

        elif self.rating_type.is_LEVEL:
            ratings_query = ratings_query.order_by('level_place')
            place_getter = lambda places: places.level_place
            value_getter = lambda values: values.level

        elif self.rating_type.is_PHRASES:
            ratings_query = ratings_query.filter(
                account__ratingvalues__phrases_count__gt=0).order_by(
                    'phrases_count_place')
            place_getter = lambda places: places.phrases_count_place
            value_getter = lambda values: values.phrases_count

        elif self.rating_type.is_PVP_BATTLES_1x1_NUMBER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__pvp_battles_1x1_number__gt=0).order_by(
                    'pvp_battles_1x1_number_place')
            place_getter = lambda places: places.pvp_battles_1x1_number_place
            value_getter = lambda values: values.pvp_battles_1x1_number

        elif self.rating_type.is_PVP_BATTLES_1x1_VICTORIES:
            ratings_query = ratings_query.filter(
                account__ratingvalues__pvp_battles_1x1_victories__gt=0
            ).order_by('pvp_battles_1x1_victories_place')
            place_getter = lambda places: places.pvp_battles_1x1_victories_place
            value_getter = lambda values: '%.2f%%' % (
                values.pvp_battles_1x1_victories * 100)

        elif self.rating_type.is_REFERRALS_NUMBER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__referrals_number__gt=0).order_by(
                    'referrals_number_place')
            place_getter = lambda places: places.referrals_number_place
            value_getter = lambda values: values.referrals_number

        elif self.rating_type.is_ACHIEVEMENTS_POINTS:
            ratings_query = ratings_query.filter(
                account__ratingvalues__achievements_points__gt=0).order_by(
                    'achievements_points_place')
            place_getter = lambda places: places.achievements_points_place
            value_getter = lambda values: values.achievements_points

        elif self.rating_type.is_HELP_COUNT:
            ratings_query = ratings_query.order_by('help_count_place')
            place_getter = lambda places: places.help_count_place
            value_getter = lambda values: values.help_count

        elif self.rating_type.is_GIFTS_RETURNED:
            ratings_query = ratings_query.filter(
                account__ratingvalues__gifts_returned__gt=0).order_by(
                    'gifts_returned_place')
            place_getter = lambda places: places.gifts_returned_place
            value_getter = lambda values: values.gifts_returned

        elif self.rating_type.is_POLITICS_POWER:
            ratings_query = ratings_query.filter(
                account__ratingvalues__politics_power__gt=0).order_by(
                    'politics_power_place')
            place_getter = lambda places: places.politics_power_place
            value_getter = lambda values: '%.2f%%' % (values.politics_power *
                                                      100)

        ratings_count = ratings_query.count()

        page = int(page) - 1

        url_builder = UrlBuilder(reverse('game:ratings:show',
                                         args=[self.rating_type.value]),
                                 arguments={'page': page})

        paginator = Paginator(page, ratings_count,
                              ratings_settings.ACCOUNTS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        rating_from, rating_to = paginator.page_borders(page)

        ratings = [
            RatingPlacesPrototype(rating_model)
            for rating_model in ratings_query[rating_from:rating_to]
        ]

        accounts_ids = [rating.account_id for rating in ratings]
        clans_ids = set(
            AccountPrototype._db_filter(id__in=accounts_ids).exclude(
                clan_id=None).values_list('clan_id', flat=True))

        heroes = {
            hero.account_id: hero
            for hero in heroes_logic.load_heroes_by_account_ids(accounts_ids)
        }

        values = dict(
            (values_model.account_id, RatingValuesPrototype(values_model))
            for values_model in RatingValues.objects.filter(
                account_id__in=accounts_ids))

        clans = {
            clan.id: clan
            for clan in ClanPrototype.get_list_by_id(list(clans_ids))
        }

        return self.template(
            'ratings/show.html', {
                'ratings': ratings,
                'ratings_updated_at_timestamp': ratings_updated_at_timestamp,
                'heroes': heroes,
                'values': values,
                'clans': clans,
                'paginator': paginator,
                'place_getter': place_getter,
                'value_getter': value_getter,
                'rating_type': self.rating_type,
                'RATING_TYPE': RATING_TYPE,
                'rating_from': rating_from,
                'rating_to': rating_to
            })
Beispiel #24
0
    def show(self, page=1): # pylint: disable=R0914

        ratings_updated_at_timestamp = settings.get(ratings_settings.SETTINGS_UPDATE_TIMESTEMP_KEY, None)

        ratings_query = RatingPlaces.objects.all().select_related()

        place_getter = None
        value_getter = None

        if self.rating_type.is_MIGHT:
            ratings_query = ratings_query.filter(account__ratingvalues__might__gt=0).order_by('might_place')
            place_getter = lambda places: places.might_place
            value_getter = lambda values: '%.2f' % values.might

        elif self.rating_type.is_BILLS:
            ratings_query = ratings_query.filter(account__ratingvalues__bills_count__gt=0).order_by('bills_count_place')
            place_getter = lambda places: places.bills_count_place
            value_getter = lambda values: values.bills_count

        elif self.rating_type.is_MAGIC_POWER:
            ratings_query = ratings_query.order_by('magic_power_place')
            place_getter = lambda places: places.magic_power_place
            value_getter = lambda values: values.magic_power

        elif self.rating_type.is_PHYSIC_POWER:
            ratings_query = ratings_query.order_by('physic_power_place')
            place_getter = lambda places: places.physic_power_place
            value_getter = lambda values: values.physic_power

        elif self.rating_type.is_LEVEL:
            ratings_query = ratings_query.order_by('level_place')
            place_getter = lambda places: places.level_place
            value_getter = lambda values: values.level

        elif self.rating_type.is_PHRASES:
            ratings_query = ratings_query.filter(account__ratingvalues__phrases_count__gt=0).order_by('phrases_count_place')
            place_getter = lambda places: places.phrases_count_place
            value_getter = lambda values: values.phrases_count

        elif self.rating_type.is_PVP_BATTLES_1x1_NUMBER:
            ratings_query = ratings_query.filter(account__ratingvalues__pvp_battles_1x1_number__gt=0).order_by('pvp_battles_1x1_number_place')
            place_getter = lambda places: places.pvp_battles_1x1_number_place
            value_getter = lambda values: values.pvp_battles_1x1_number

        elif self.rating_type.is_PVP_BATTLES_1x1_VICTORIES:
            ratings_query = ratings_query.filter(account__ratingvalues__pvp_battles_1x1_victories__gt=0).order_by('pvp_battles_1x1_victories_place')
            place_getter = lambda places: places.pvp_battles_1x1_victories_place
            value_getter = lambda values: '%.2f%%' % (values.pvp_battles_1x1_victories * 100)

        elif self.rating_type.is_REFERRALS_NUMBER:
            ratings_query = ratings_query.filter(account__ratingvalues__referrals_number__gt=0).order_by('referrals_number_place')
            place_getter = lambda places: places.referrals_number_place
            value_getter = lambda values: values.referrals_number

        elif self.rating_type.is_ACHIEVEMENTS_POINTS:
            ratings_query = ratings_query.filter(account__ratingvalues__achievements_points__gt=0).order_by('achievements_points_place')
            place_getter = lambda places: places.achievements_points_place
            value_getter = lambda values: values.achievements_points

        elif self.rating_type.is_HELP_COUNT:
            ratings_query = ratings_query.order_by('help_count_place')
            place_getter = lambda places: places.help_count_place
            value_getter = lambda values: values.help_count

        elif self.rating_type.is_GIFTS_RETURNED:
            ratings_query = ratings_query.filter(account__ratingvalues__gifts_returned__gt=0).order_by('gifts_returned_place')
            place_getter = lambda places: places.gifts_returned_place
            value_getter = lambda values: values.gifts_returned

        elif self.rating_type.is_POLITICS_POWER:
            ratings_query = ratings_query.filter(account__ratingvalues__politics_power__gt=0).order_by('politics_power_place')
            place_getter = lambda places: places.politics_power_place
            value_getter = lambda values: '%.2f%%' % (values.politics_power * 100)

        ratings_count = ratings_query.count()

        page = int(page) - 1

        url_builder = UrlBuilder(reverse('game:ratings:show', args=[self.rating_type.value]), arguments={'page': page})

        paginator = Paginator(page, ratings_count, ratings_settings.ACCOUNTS_ON_PAGE, url_builder)

        if paginator.wrong_page_number:
            return self.redirect(paginator.last_page_url, permanent=False)

        rating_from, rating_to = paginator.page_borders(page)

        ratings = [ RatingPlacesPrototype(rating_model) for rating_model in ratings_query[rating_from:rating_to] ]

        accounts_ids = [rating.account_id for rating in ratings]
        clans_ids = set(AccountPrototype._db_filter(id__in=accounts_ids).exclude(clan_id=None).values_list('clan_id', flat=True))

        heroes = { hero.account_id: hero for hero in  heroes_logic.load_heroes_by_account_ids(accounts_ids)}

        values = dict( (values_model.account_id, RatingValuesPrototype(values_model)) for values_model in RatingValues.objects.filter(account_id__in=accounts_ids))

        clans = {clan.id:clan for clan in ClanPrototype.get_list_by_id(list(clans_ids))}

        return self.template('ratings/show.html',
                             {'ratings': ratings,
                              'ratings_updated_at_timestamp': ratings_updated_at_timestamp,
                              'heroes': heroes,
                              'values': values,
                              'clans': clans,
                              'paginator': paginator,
                              'place_getter': place_getter,
                              'value_getter': value_getter,
                              'rating_type': self.rating_type,
                              'RATING_TYPE': RATING_TYPE,
                              'rating_from': rating_from,
                              'rating_to': rating_to})
Beispiel #25
0
 def _get_state(cls):
     return relations.GAME_STATE.index_value[int(settings.get(game_settings.GAME_STATE_KEY, relations.GAME_STATE.STOPPED.value))]
Beispiel #26
0
def number():
    return int(settings.get(TURN_SETTINGS_KEY, 0))
Beispiel #27
0
 def _get_state(cls):
     return relations.GAME_STATE.index_value[int(settings.get(game_settings.GAME_STATE_KEY, relations.GAME_STATE.STOPPED.value))]
Beispiel #28
0
 def shop(self):
     return self.template('statistics/index.html',
                          {'RECORD_TYPE': relations.RECORD_TYPE,
                           'PLOTS_GROUPS': PLOTS_GROUPS,
                           'js_data_file': statistics_settings.JS_DATA_FILE_URL % settings.get(statistics_settings.JS_DATA_FILE_VERSION_KEY, 0)})
Beispiel #29
0
    def preprocess(self, context):
        real_payments_enabled = (settings.get(payments_settings.SETTINGS_ALLOWED_KEY) and
                                 (payments_settings.ENABLE_REAL_PAYMENTS or
                                  context.account.id in payments_settings.ALWAYS_ALLOWED_ACCOUNTS))

        context.xsolla_enabled = real_payments_enabled and payments_settings.XSOLLA_ENABLED
Beispiel #30
0
    def process_no_cmd(self):

        # check if new real day started
        if (time.time() - float(
                settings.get(
                    portal_settings.SETTINGS_PREV_REAL_DAY_STARTED_TIME_KEY,
                    0)) > 23.5 * 60 * 60 and datetime.datetime.now().hour >=
                portal_settings.REAL_DAY_STARTED_TIME):
            portal_signals.day_started.send(self.__class__)
            settings[
                portal_settings.SETTINGS_PREV_REAL_DAY_STARTED_TIME_KEY] = str(
                    time.time())
            return

        # is cleaning run needed
        if (time.time() - float(
                settings.get(
                    portal_settings.SETTINGS_PREV_CLEANING_RUN_TIME_KEY, 0)) >
                23.5 * 60 * 60 and portal_settings.CLEANING_RUN_TIME <=
                datetime.datetime.now().hour <=
                portal_settings.CLEANING_RUN_TIME + 1):
            settings[
                portal_settings.SETTINGS_PREV_CLEANING_RUN_TIME_KEY] = str(
                    time.time())
            self.run_cleaning()
            return

        # is statistics run needed
        if (time.time() - float(
                settings.get(
                    portal_settings.SETTINGS_PREV_STATISTICS_RUN_TIME_KEY, 0))
                > 23.5 * 60 * 60 and portal_settings.STATISTICS_RUN_TIME <=
                datetime.datetime.now().hour <=
                portal_settings.STATISTICS_RUN_TIME + 1):
            settings[
                portal_settings.SETTINGS_PREV_STATISTICS_RUN_TIME_KEY] = str(
                    time.time())
            self.run_statistics()
            return

        # is rating sync needed
        if self._try_run_command_with_delay(
                cmd=self.run_recalculate_ratings,
                settings_key=portal_settings.
                SETTINGS_PREV_RATINGS_SYNC_TIME_KEY,
                delay=portal_settings.RATINGS_SYNC_DELAY):
            return

        # is might sync needed
        if self._try_run_command_with_delay(
                cmd=self.run_recalculate_might,
                settings_key=portal_settings.SETTINGS_PREV_MIGHT_SYNC_TIME_KEY,
                delay=portal_settings.MIGHT_SYNC_DELAY):
            return

        # is cdns refresh needed
        if self._try_run_command_with_delay(
                cmd=self.run_refresh_cdns,
                settings_key=portal_settings.SETTINGS_PREV_CDN_SYNC_TIME_KEY,
                delay=portal_settings.CDN_SYNC_DELAY):
            return

        # is remove expired access tokens refresh needed
        if self._try_run_command_with_delay(
                cmd=self.run_remove_expired_access_tokens,
                settings_key=portal_settings.
                SETTINGS_PREV_EXPIRE_ACCESS_TOKENS_SYNC_TIME_KEY,
                delay=portal_settings.EXPIRE_ACCESS_TOKENS_SYNC_DELAY):
            return

        # is linguistic cleaning needed
        if self._try_run_command_with_delay(
                cmd=self.run_clean_removed_templates,
                settings_key=portal_settings.
                SETTINGS_PREV_CLEAN_REMOVED_TEMPLATES_KEY,
                delay=portal_settings.EXPIRE_CLEAN_REMOVED_TEMPLATES):
            return