Exemple #1
0
def feed(context):
    feed = feedgenerator.Atom1Feed(
        u'Сказка: Новости',
        context.django_request.build_absolute_uri('/'),
        u'Новости мморпг «Сказка»',
        language=u'ru',
        feed_url=context.django_request.build_absolute_uri(url('news:feed')))

    news = logic.load_news_from_query(
        models.News.objects.order_by('-created_at')
        [:conf.settings.FEED_ITEMS_NUMBER])

    for news_item in news:

        if datetime.datetime.now() - news_item.created_at < datetime.timedelta(
                seconds=conf.settings.FEED_ITEMS_DELAY):
            continue

        feed.add_item(
            title=news_item.caption,
            link=context.django_request.build_absolute_uri(
                url('news:show', news_item.id)),
            description=news_item.html_content,
            pubdate=news_item.created_at,
            comments=url('forum:threads:show', news_item.forum_thread_id)
            if news_item.forum_thread_id else None,
            unique_id=str(news_item.id))

    return dext_views.Atom(feed)
Exemple #2
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})
Exemple #3
0
def index(context):

    url_builder = UrlBuilder(url('news:'), arguments={'page': context.page})

    news_count = models.News.objects.all().count()

    paginator = Paginator(context.page, news_count, conf.settings.NEWS_ON_PAGE, url_builder)

    if paginator.wrong_page_number:
        return dext_views.Redirect(paginator.last_page_url)

    news_from, news_to = paginator.page_borders(context.page)

    news = logic.load_news_from_query(models.News.objects.all().order_by('-created_at')[news_from:news_to])

    return dext_views.Page('news/index.html',
                           content={'news': news,
                                    'paginator': paginator,
                                    'resource': context.resource} )
Exemple #4
0
def feed(context):
    feed = feedgenerator.Atom1Feed('Сказка: Новости',
                                   context.django_request.build_absolute_uri('/'),
                                   'Новости мморпг «Сказка»',
                                   language='ru',
                                   feed_url=context.django_request.build_absolute_uri(url('news:feed')))

    news = logic.load_news_from_query(models.News.objects.order_by('-created_at')[:conf.settings.FEED_ITEMS_NUMBER])

    for news_item in news:

        if datetime.datetime.now() - news_item.created_at < datetime.timedelta(seconds=conf.settings.FEED_ITEMS_DELAY):
            continue

        feed.add_item(title=news_item.caption,
                      link=context.django_request.build_absolute_uri(url('news:show', news_item.id)),
                      description=news_item.html_content,
                      pubdate=news_item.created_at,
                      comments=url('forum:threads:show', news_item.forum_thread_id) if news_item.forum_thread_id else None,
                      unique_id=str(news_item.id))

    return dext_views.Atom(feed)
Exemple #5
0
def index(context):

    url_builder = UrlBuilder(url('news:'), arguments={'page': context.page})

    news_count = models.News.objects.all().count()

    paginator = Paginator(context.page, news_count, conf.settings.NEWS_ON_PAGE,
                          url_builder)

    if paginator.wrong_page_number:
        return dext_views.Redirect(paginator.last_page_url)

    news_from, news_to = paginator.page_borders(context.page)

    news = logic.load_news_from_query(
        models.News.objects.all().order_by('-created_at')[news_from:news_to])

    return dext_views.Page('news/index.html',
                           content={
                               'news': news,
                               'paginator': paginator,
                               'resource': context.resource
                           })
Exemple #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 = HeroPrototype.get_by_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
            })