Esempio n. 1
0
    def index(self, page=None, place=None):

        records_query = Record.objects.all()

        if place is not None:
            records_query = records_query.filter(actors__place_id=place.id)

        url_builder = UrlBuilder(reverse('game:chronicle:'), arguments={'place': place.id if place else None})

        index_filter = IndexFilter(url_builder=url_builder, values={'place': place.id if place else None})

        records_count = records_query.count()

        if page is None:
            page = Paginator.get_page_numbers(records_count, chronicle_settings.RECORDS_ON_PAGE)
            if page == 0: page = 1
        page = int(page) - 1

        paginator = Paginator(page, records_count, chronicle_settings.RECORDS_ON_PAGE, url_builder, inverse=True)

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

        record_from, record_to = paginator.page_borders(page)

        records = [ RecordPrototype(record) for record in records_query.select_related().order_by('created_at', 'created_at_turn')[record_from:record_to]]

        records = list(reversed(records))

        return self.template('chronicle/index.html',
                             {'records': records,
                              'place': place,
                              'paginator': paginator,
                              'index_filter': index_filter,
                              'url_builder': url_builder} )
Esempio n. 2
0
 def test_place_chronicle(self):
     texts = [
         jinja2.escape(record.text)
         for record in ChronicleRecordPrototype.get_last_actor_records(
             self.place_1, 1000)
     ]
     self.check_html_ok(self.request_html(
         reverse('game:map:cell-info') +
         ('?x=%d&y=%d' % (self.place_1.x, self.place_1.y))),
                        texts=texts)
Esempio n. 3
0
    def test_get_actor_records_query(self):
        self.assertTrue(Record.objects.all().exists())

        records_ids = RecordPrototype.get_actor_records_query(self.place_1).values_list('id', flat=True)
        actor = Actor.objects.get(place_id=self.place_1.id)

        for record in Record.objects.all():
            if actor.id in record.actors.all().values_list('id', flat=True):
                self.assertTrue(record.id in records_ids)
            else:
                self.assertFalse(record.id in records_ids)
Esempio n. 4
0
    def test_get_actor_records_query(self):
        self.assertTrue(Record.objects.all().exists())

        records_ids = RecordPrototype.get_actor_records_query(
            self.place_1).values_list('id', flat=True)
        actor = Actor.objects.get(place_id=self.place_1.id)

        for record in Record.objects.all():
            if actor.id in record.actors.all().values_list('id', flat=True):
                self.assertTrue(record.id in records_ids)
            else:
                self.assertFalse(record.id in records_ids)
Esempio n. 5
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})
Esempio n. 6
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
            })
Esempio n. 7
0
 def test_get_last_actor_records(self):
     records = RecordPrototype.get_last_actor_records(self.place_1, 10000)
     self.assertTrue(len(records) < 10000)
     for i, record in enumerate(records[:-1]):
         self.assertTrue(
             record._model.created_at > records[i + 1]._model.created_at)
Esempio n. 8
0
 def create_record(self):
     return RecordPrototype.create(self)
Esempio n. 9
0
 def create_record(self):
     return RecordPrototype.create(self)
Esempio n. 10
0
 def test_get_last_actor_records(self):
     records = RecordPrototype.get_last_actor_records(self.place_1, 10000)
     self.assertTrue(len(records) < 10000)
     for i, record in enumerate(records[:-1]):
         self.assertTrue(record._model.created_at > records[i+1]._model.created_at)