Example #1
0
def show(context):
    accounts_short_infos = game_short_info.get_accounts_accounts_info(
        list(context.place.politic_power.inner_accounts_ids()))

    return dext_views.Page(
        'places/show.html',
        content={
            'place':
            context.place,
            'place_bills':
            info.place_info_bills(context.place),
            'place_chronicle':
            chronicle_prototypes.chronicle_info(
                context.place, conf.settings.CHRONICLE_RECORDS_NUMBER),
            'accounts_short_infos':
            accounts_short_infos,
            'HABIT_TYPE':
            game_relations.HABIT_TYPE,
            'place_meta_object':
            meta_relations.Place.create_from_object(context.place),
            'hero':
            heroes_logic.load_hero(
                account_id=context.account.id) if context.account else None,
            'resource':
            context.resource
        })
Example #2
0
def show(context):
    place_info = logic.place_info(context.place)
    return dext_views.Page(
        'places/show.html',
        content={
            'place_info':
            place_info,
            'place_meta_object':
            meta_relations.Place.create_from_object(context.place),
            'RACE':
            game_relations.RACE,
            'GENDER':
            game_relations.GENDER,
            'PERSON_TYPE':
            persons_relations.PERSON_TYPE,
            'CONNECTION_TYPE':
            persons_relations.SOCIAL_CONNECTION_TYPE,
            'hero':
            HeroPrototype.get_by_account_id(context.account.id)
            if context.account else None,
            'persons_storage':
            persons_storage.persons_storage,
            'resource':
            context.resource
        })
Example #3
0
def game_page(context):

    battle = Battle1x1Prototype.get_by_account_id(context.account.id)

    if battle and battle.state.is_PROCESSING:
        return dext_views.Redirect(url('game:pvp:'))

    clan = None
    if context.account.clan_id is not None:
        clan = ClanPrototype.get_by_id(context.account.clan_id)

    cards = sorted(CARD.records, key=lambda r: (r.rarity.value, r.text))

    return dext_views.Page('game/game_page.html',
                           content={
                               'map_settings': map_settings,
                               'game_settings': game_settings,
                               'EQUIPMENT_SLOT': EQUIPMENT_SLOT,
                               'current_map_version': map_info_storage.version,
                               'clan': clan,
                               'CARDS': cards,
                               'resource': context.resource,
                               'hero': context.account_hero,
                               'ABILITY_TYPE': ABILITY_TYPE
                           })
Example #4
0
def transfer_money_dialog(context):
    if context.account.id == context.master_account.id:
        raise dext_views.ViewError(code='own_account', message=u'Нельзя переводить печеньки самому себе')

    return dext_views.Page('accounts/transfer_money.html',
                           content={'commission': conf.accounts_settings.MONEY_SEND_COMMISSION,
                                    'form': forms.SendMoneyForm()} )
Example #5
0
def show(context):

    accounts_short_infos = game_short_info.get_accounts_accounts_info(
        list(context.person.politic_power.inner_accounts_ids()))

    return dext_views.Page(
        'persons/show.html',
        content={
            'person':
            context.person,
            'person_meta_object':
            meta_relations.Person.create_from_object(context.person),
            'accounts_short_infos':
            accounts_short_infos,
            'hero':
            heroes_logic.load_hero(
                account_id=context.account.id) if context.account else None,
            'social_connections':
            storage.social_connections.get_connected_persons(context.person),
            'master_chronicle':
            chronicle_prototypes.chronicle_info(
                context.person, conf.settings.CHRONICLE_RECORDS_NUMBER),
            'resource':
            context.resource
        })
Example #6
0
def show(context):
    from the_tale.forum.views import ThreadPageData

    thread_data = None

    if context.news.forum_thread_id is not None:
        thread_data = ThreadPageData()
        thread_data.initialize(
            account=context.account,
            thread=forum_prototypes.ThreadPrototype.get_by_id(
                context.news.forum_thread_id),
            page=1,
            inline=True)

    return dext_views.Page('news/show.html',
                           content={
                               'news':
                               context.news,
                               'thread_data':
                               thread_data,
                               'news_meta_object':
                               meta_relations.News.create_from_object(
                                   context.news),
                               'resource':
                               context.resource
                           })
Example #7
0
def new(context):
    text = u''

    if context.answer_to:
        if context.answer_to.recipient_id != context.account.id:
            raise dext_views.ViewError(
                code='no_permissions_to_answer_to',
                message=u'Вы пытаетесь ответить на чужое сообщение')

        text = u'[quote]\n%s\n[/quote]\n' % context.answer_to.text

    check_recipients(context.form)

    form = forms.NewMessageForm(
        initial={
            'text':
            text,
            'recipients':
            ','.join(
                str(recipient_id)
                for recipient_id in context.form.c.recipients)
        })

    return dext_views.Page(
        'personal_messages/new.html',
        content={
            'recipients':
            accounts_prototypes.AccountPrototype.get_list_by_id(
                context.form.c.recipients),
            'form':
            form,
            'resource':
            context.resource
        })
Example #8
0
def show(context):
    from the_tale.game.ratings import relations as ratings_relations
    from the_tale.game.ratings import conf as ratings_conf

    friendship = FriendshipPrototype.get_for_bidirectional(
        context.account, context.master_account)

    master_hero = heroes_logic.load_hero(account_id=context.master_account.id)

    return dext_views.Page(
        'accounts/show.html',
        content={
            'master_hero':
            master_hero,
            'account_meta_object':
            meta_relations.Account.create_from_object(context.master_account),
            'account_info':
            logic.get_account_info(context.master_account, master_hero),
            'master_account':
            context.master_account,
            'accounts_settings':
            conf.accounts_settings,
            'RATING_TYPE':
            ratings_relations.RATING_TYPE,
            'resource':
            context.resource,
            'ratings_on_page':
            ratings_conf.ratings_settings.ACCOUNTS_ON_PAGE,
            'informer_link':
            conf.accounts_settings.INFORMER_LINK % {
                'account_id': context.master_account.id
            },
            'friendship':
            friendship
        })
Example #9
0
def new(context):
    text = ''

    if context.answer_to:
        text = '[quote]\n%s\n[/quote]\n' % context.answer_to.body

    check_recipients(context.form)

    form = forms.NewMessageForm(
        initial={
            'text':
            text,
            'recipients':
            ','.join(
                str(recipient_id)
                for recipient_id in context.form.c.recipients)
        })

    return dext_views.Page(
        'personal_messages/new.html',
        content={
            'recipients':
            accounts_prototypes.AccountPrototype.get_list_by_id(
                context.form.c.recipients),
            'form':
            form,
            'resource':
            context.resource
        })
Example #10
0
def hero_history_status(context):

    properties = itertools.product(
        relations.GENDER.records, relations.RACE.records, [
            relations.HABIT_HONOR_INTERVAL.LEFT_1,
            relations.HABIT_HONOR_INTERVAL.RIGHT_1
        ], [
            relations.HABIT_PEACEFULNESS_INTERVAL.LEFT_1,
            relations.HABIT_PEACEFULNESS_INTERVAL.RIGHT_1
        ], relations.ARCHETYPE.records, beings_relations.UPBRINGING.records,
        beings_relations.FIRST_DEATH.records, beings_relations.AGE.records)

    misses = [[], [], []]

    for property_vector in properties:
        texts = game_logic.generate_history(['test'] * 6, *property_vector)

        for i, text in enumerate(texts):
            if text is None:
                misses[i].append(', '.join(
                    [property.text for property in property_vector]))

    return dext_views.Page('game/hero_history_status.html',
                           content={
                               'resource': context.resource,
                               'misses': misses
                           })
Example #11
0
def new(context):
    form = forms.CompanionRecordForm()
    return dext_views.Page('companions/new.html',
                           content={'context': context,
                                    'resource': context.resource,
                                    'section': 'companions',
                                    'form': form})
Example #12
0
def market_history(context):

    cards_info = cards_logic.get_cards_info_by_full_types()

    page, total_records, records = tt_api.history(page=context.page+1, records_on_page=conf.payments_settings.MARKET_HISTORY_RECORDS_ON_PAGE)

    page -= 1

    url_builder = UrlBuilder(reverse('shop:market-history'), arguments={'page': context.page})

    history_paginator = pagination.Paginator(page,
                                             total_records,
                                             conf.payments_settings.MARKET_HISTORY_RECORDS_ON_PAGE,
                                             url_builder)

    return dext_views.Page('shop/market_history.html',
                           content={'SUBSCRIPTIONS': price_list.SUBSCRIPTIONS,
                                    'CARD_RARITY': cards_relations.RARITY,
                                    'page_type': 'market-history',
                                    'payments_settings': conf.payments_settings,
                                    'permanent_purchases': sorted(context.account.permanent_purchases, key=lambda r: r.text),
                                    'account': context.account,
                                    'records': records,
                                    'resource': context.resource,
                                    'paginator': history_paginator,
                                    'cards_info': cards_info})
Example #13
0
def show(context):

    if context.companion.state.is_DISABLED and not (
            context.companions_can_edit or context.companions_can_moderate):
        raise dext_views.ViewError(
            code='no_rights',
            message='Вы не можете просматривать информацию по данному спутнику.'
        )

    template_restriction, ingame_companion_phrases = logic.required_templates_count(
        context.companion)

    return dext_views.Page('companions/show.html',
                           content={
                               'context':
                               context,
                               'companion_meta_object':
                               meta_relations.Companion.create_from_object(
                                   context.companion),
                               'resource':
                               context.resource,
                               'companion':
                               context.companion,
                               'ingame_companion_phrases':
                               ingame_companion_phrases,
                               'template_restriction':
                               template_restriction,
                               'section':
                               'companions'
                           })
Example #14
0
def admin(context):
    from the_tale.finances.shop.forms import GMForm
    return dext_views.Page('accounts/admin.html',
                           content={'master_account': context.master_account,
                                    'give_award_form': forms.GiveAwardForm(),
                                    'resource': context.resource,
                                    'give_money_form': GMForm(),
                                    'ban_form': forms.BanForm()} )
Example #15
0
def edit(context):
    form = forms.CompanionRecordForm(initial=forms.CompanionRecordForm.get_initials(context.companion))
    return dext_views.Page('companions/edit.html',
                           content={'context': context,
                                    'resource': context.resource,
                                    'companion': context.companion,
                                    'section': 'companions',
                                    'form': form})
Example #16
0
def new(context):
    return dext_views.Page('market/new.html',
                           content={
                               'context': context,
                               'page_type': 'new',
                               'resource': context.resource,
                               'commission': conf.settings.COMMISSION
                           })
Example #17
0
def use_dialog(context):
    return dext_views.Page('cards/use_dialog.html',
                           content={
                               'hero': context.account_hero,
                               'card': context.account_card,
                               'form': context.account_card.type.form(),
                               'resource': context.resource
                           })
Example #18
0
def show_dialog(context):

    if context.companion.state.is_DISABLED and not (context.companions_can_edit or context.companions_can_moderate):
        raise dext_views.ViewError(code='no_rights', message=u'Вы не можете просматривать информацию по данному спутнику.')

    return dext_views.Page('companions/info.html',
                           content={'companion': context.companion,
                                    'companion_meta_object': meta_relations.Companion.create_from_object(context.companion),
                                    'resource': context.resource})
Example #19
0
def create_hero_view(context):

    # if context.account.is_authenticated:
    #     raise dext_views.ViewError(code='accounts.create_hero.already_registered',
    #                                message='Вы уже зарегистрированы')

    return dext_views.Page('accounts/create_hero.html',
                           content={'resource': context.resource,
                                    'create_hero': create_hero})
Example #20
0
def show(context):

    accounts_short_infos = game_short_info.get_accounts_accounts_info(list(context.person.politic_power.inner_accounts_ids()))

    return dext_views.Page('persons/show.html',
                           content={'person': context.person,
                                    'person_meta_object': meta_relations.Person.create_from_object(context.person),
                                    'accounts_short_infos': accounts_short_infos,
                                    'hero': heroes_logic.load_hero(account_id=context.account.id) if context.account else None,
                                    'resource': context.resource})
Example #21
0
def combine_dialog(context):
    cards = sorted(effects.EFFECTS.values(),
                   key=lambda x: (x.TYPE.rarity.value, x.TYPE.text))

    return dext_views.Page('cards/combine_dialog.html',
                           content={
                               'CARDS': cards,
                               'hero': context.account_hero,
                               'resource': context.resource
                           })
Example #22
0
def edit(context):
    return dext_views.Page(
        'news/edit.html',
        content={
            'resource':
            context.resource,
            'form':
            forms.NewNewsForm(
                initial=forms.NewNewsForm.get_initials(context.news))
        })
Example #23
0
def index(context):
    from the_tale.game.cards.relations import RARITY

    cards = effects.EFFECTS.values()

    if context.cards_availability:
        cards = [
            card for card in cards
            if card.TYPE.availability == context.cards_availability
        ]

    if context.cards_rarity:
        cards = [
            card for card in cards if card.TYPE.rarity == context.cards_rarity
        ]

    if context.cards_order_by.is_RARITY:
        cards = sorted(cards, key=lambda c: (c.TYPE.rarity.value, c.TYPE.text))
    elif context.cards_order_by.is_NAME:
        cards = sorted(cards, key=lambda c: (c.TYPE.text, c.TYPE.rarity.value))

    url_builder = UrlBuilder(
        url('guide:cards:'),
        arguments={
            'rarity':
            context.cards_rarity.value if context.cards_rarity else None,
            'availability':
            context.cards_availability.value
            if context.cards_availability else None,
            'order_by':
            context.cards_order_by.value
        })

    index_filter = CardsFilter(
        url_builder=url_builder,
        values={
            'rarity':
            context.cards_rarity.value if context.cards_rarity else None,
            'availability':
            context.cards_availability.value
            if context.cards_availability else None,
            'order_by':
            context.cards_order_by.value if context.cards_order_by else None
        })

    return dext_views.Page('cards/index.html',
                           content={
                               'section': 'cards',
                               'CARDS': cards,
                               'index_filter': index_filter,
                               'CARD_RARITY': RARITY,
                               'resource': context.resource
                           })
Example #24
0
def shop(context):
    hero = heroes_logic.load_hero(account_id=context.account.id)

    if context.account.is_premium:
        featured_group = relations.GOODS_GROUP.CHEST
    else:
        featured_group = relations.GOODS_GROUP.PREMIUM

    price_types = [group.type for group in price_list.PRICE_GROUPS]

    def _cmp(x, y):
        choices = {
            (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.CHEST, False):
            -1,
            (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.CHEST, True):
            1,
            (relations.GOODS_GROUP.CHEST, relations.GOODS_GROUP.PREMIUM, False):
            1,
            (relations.GOODS_GROUP.CHEST, relations.GOODS_GROUP.PREMIUM, True):
            -1,
            (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.ENERGY, False):
            -1,
            (relations.GOODS_GROUP.PREMIUM, relations.GOODS_GROUP.ENERGY, True):
            1,
            (relations.GOODS_GROUP.ENERGY, relations.GOODS_GROUP.PREMIUM, False):
            1,
            (relations.GOODS_GROUP.ENERGY, relations.GOODS_GROUP.PREMIUM, True):
            -1
        }

        if price_types.index(x.type) < price_types.index(y.type):
            default = -1
        elif price_types.index(x.type) > price_types.index(y.type):
            default = 1
        else:
            default = 0

        return choices.get((x.type, y.type, context.account.is_premium),
                           default)

    price_groups = sorted(price_list.PRICE_GROUPS,
                          key=functools.cmp_to_key(_cmp))

    return dext_views.Page('shop/shop.html',
                           content={
                               'PRICE_GROUPS': price_groups,
                               'hero': hero,
                               'payments_settings': payments_settings,
                               'account': context.account,
                               'featured_group': featured_group,
                               'page_type': 'shop',
                               'resource': context.resource
                           })
Example #25
0
def history(context):
    history = context.account.bank_account.get_history_list()

    return dext_views.Page('shop/history.html',
                           content={'SUBSCRIPTIONS': price_list.SUBSCRIPTIONS,
                                    'CARD_RARITY': cards_relations.RARITY,
                                    'page_type': 'shop-history',
                                    'payments_settings': conf.payments_settings,
                                    'permanent_purchases': sorted(context.account.permanent_purchases, key=lambda r: r.text),
                                    'account': context.account,
                                    'history': history,
                                    'resource': context.resource})
Example #26
0
def conversation(context):

    contacts_ids = tt_api.get_contacts(context.account.id)

    messages_count, messages = tt_api.get_conversation(context.account.id,
                                                      context.contact.id,
                                                      text=context.filter,
                                                      offset=context.page*conf.settings.MESSAGES_ON_PAGE,
                                                      limit=conf.settings.MESSAGES_ON_PAGE)

    class Filter(list_filter.ListFilter):
        ELEMENTS = [list_filter.reset_element(),
                    list_filter.filter_element('поиск:', attribute='filter', default_value=None),
                    list_filter.static_element('количество:', attribute='count', default_value=0) ]

    url_builder = UrlBuilder(url('accounts:messages:conversation'), arguments={'page': context.page,
                                                                               'contact': context.contact.id,
                                                                               'filter': context.filter})

    index_filter = Filter(url_builder=url_builder, values={'contact': context.contact.id,
                                                           'filter': context.filter,
                                                           'count': messages_count})

    paginator = Paginator(context.page, messages_count, conf.settings.MESSAGES_ON_PAGE, url_builder)

    if paginator.wrong_page_number:
        return dext_views.Redirect(paginator.last_page_url, permanent=False)

    accounts_ids = set(contacts_ids)

    for message in messages:
        accounts_ids.add(message.sender_id)
        accounts_ids.update(message.recipients_ids)

    accounts = {account.id: account for account in accounts_prototypes.AccountPrototype.get_list_by_id(list(accounts_ids))}

    contacts = [accounts[contact_id] for contact_id in contacts_ids]
    contacts.sort(key=lambda account: account.nick_verbose)

    return dext_views.Page('personal_messages/index.html',
                           content= {'messages': messages,
                                     'paginator': paginator,
                                     'page': 'contacts',
                                     'contacts': contacts,
                                     'accounts': accounts,
                                     'master_account': context.account,
                                     'index_filter': index_filter,
                                     'contact': context.contact,
                                     'resource': context.resource})
Example #27
0
def new_dialog(context):
    if logic.has_lot(context.account.id, context.good.uid):
        raise dext_utils_exceptions.ViewError(
            code='lot_exists',
            message=u'Вы уже выставили этот предмет на продажу')

    return dext_views.Page(
        'market/new_dialog.html',
        content={
            'context': context,
            'form':
            forms.PriceForm(initial={'price': conf.settings.MINIMUM_PRICE}),
            'resource': context.resource,
            'commission': conf.settings.COMMISSION
        })
Example #28
0
def index(context):

    accounts_query = AccountPrototype.live_query()

    if context.prefix:
        accounts_query = accounts_query.filter(
            nick__istartswith=context.prefix)

    accounts_count = accounts_query.count()

    url_builder = UrlBuilder(reverse('accounts:'),
                             arguments={
                                 'page': context.page,
                                 'prefix': context.prefix
                             })

    paginator = Paginator(context.page, accounts_count,
                          conf.accounts_settings.ACCOUNTS_ON_PAGE, url_builder)

    if paginator.wrong_page_number:
        return dext_views.Redirect(paginator.last_page_url, permanent=False)

    account_from, account_to = paginator.page_borders(context.page)

    accounts_models = accounts_query.select_related().order_by(
        'nick')[account_from:account_to]

    accounts = [AccountPrototype(model) for model in accounts_models]

    accounts_ids = [model.id for model in accounts_models]
    clans_ids = [model.clan_id for model in accounts_models]

    heroes = dict(
        (model.account_id, heroes_logic.load_hero(hero_model=model))
        for model in Hero.objects.filter(account_id__in=accounts_ids))

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

    return dext_views.Page('accounts/index.html',
                           content={
                               'heroes': heroes,
                               'prefix': context.prefix,
                               'accounts': accounts,
                               'clans': clans,
                               'resource': context.resource,
                               'current_page_number': context.page,
                               'paginator': paginator
                           })
Example #29
0
def render_index(context, lots_query, page_mode, base_url):
    if context.filter is not None:
        lots_query = lots_query.filter(name__icontains=context.filter)

    if context.goods_group is not None:
        lots_query = lots_query.filter(type=context.goods_group.type.uid,
                                       group_id=context.goods_group.id)

    lots_query = lots_query.order_by(context.order_by.db_order)

    lots_count = lots_query.count()

    url_builder = UrlBuilder(
        base_url,
        arguments={
            'filter': context.filter,
            'order_by': context.order_by.value,
            'group': context.goods_group.uid if context.goods_group else None
        })

    index_filter = LotsIndexFilter(
        url_builder=url_builder,
        values={
            'filter': context.filter,
            'order_by': context.order_by.value,
            'count': lots_count,
            'group': context.goods_group.uid if context.goods_group else None
        })

    paginator = pagination.Paginator(context.page, lots_count,
                                     conf.settings.LOTS_ON_PAGE, url_builder)

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

    lots_from, lots_to = paginator.page_borders(context.page)

    lots = logic.load_lots_from_query(lots_query[lots_from:lots_to])

    return dext_views.Page('market/index.html',
                           content={
                               'context': context,
                               'index_filter': index_filter,
                               'paginator': paginator,
                               'lots': lots,
                               'page_type': page_mode.page,
                               'resource': context.resource
                           })
Example #30
0
def show(context):

    inner_circle = politic_power_logic.get_inner_circle(
        place_id=context.place.id)

    accounts_short_infos = game_short_info.get_accounts_accounts_info(
        inner_circle.heroes_ids())

    job_power = politic_power_logic.get_job_power(place_id=context.place.id)

    persons_inner_circles = {
        person.id: politic_power_logic.get_inner_circle(person_id=person.id)
        for person in context.place.persons
    }

    return dext_views.Page(
        'places/show.html',
        content={
            'place':
            context.place,
            'place_bills':
            info.place_info_bills(context.place),
            'place_chronicle':
            chronicle_prototypes.RecordPrototype.get_last_actor_records(
                context.place, conf.settings.CHRONICLE_RECORDS_NUMBER),
            'accounts_short_infos':
            accounts_short_infos,
            'inner_circle':
            inner_circle,
            'persons_inner_circles':
            persons_inner_circles,
            'HABIT_TYPE':
            game_relations.HABIT_TYPE,
            'place_meta_object':
            meta_relations.Place.create_from_object(context.place),
            'hero':
            heroes_logic.load_hero(
                account_id=context.account.id) if context.account else None,
            'places_power_storage':
            politic_power_storage.places,
            'persons_power_storage':
            politic_power_storage.persons,
            'job_power':
            job_power,
            'resource':
            context.resource
        })