Ejemplo n.º 1
0
    def process(self):
        from the_tale.accounts.personal_messages.prototypes import MessagePrototype as PersonalMessagePrototype

        message = PersonalMessagePrototype.get_by_id(self.message_id)

        if message is None:
            return True # message can be removed by admins or with removed thread

        account = message.recipient

        if not account.personal_messages_subscription:
            return True

        if account.id == get_system_user().id or account.is_bot:
            return True

        if not account.email:
            return True

        subject = '«Сказка»: личное сообщение'

        context = {'message': message}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Ejemplo n.º 2
0
    def process(self):
        from the_tale.accounts.personal_messages import tt_api as pm_tt_api

        message = pm_tt_api.get_message(self.account_id, message_id=self.message_id)

        if message is None:
            return True # message can be removed by admins or with removed thread

        account = AccountPrototype.get_by_id(self.account_id)

        if not account.personal_messages_subscription:
            return True

        if account.id == get_system_user().id or account.is_bot:
            return True

        if not account.email:
            return True

        subject = '«Сказка»: личное сообщение'

        context = {'message': message,
                   'sender': AccountPrototype.get_by_id(message.sender_id)}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Ejemplo n.º 3
0
    def process(self):
        from the_tale.accounts.personal_messages.prototypes import MessagePrototype as PersonalMessagePrototype

        message = PersonalMessagePrototype.get_by_id(self.message_id)

        if message is None:
            return True  # message can be removed by admins or with removed thread

        account = message.recipient

        if not account.personal_messages_subscription:
            return True

        if account.id == get_system_user().id or account.is_bot:
            return True

        if not account.email:
            return True

        subject = u'«Сказка»: личное сообщение'

        context = {'message': message}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Ejemplo n.º 4
0
    def process(self):
        account = AccountPrototype.get_by_id(self.account_id)

        if account.id == get_system_user().id or account.is_bot:
            return True

        subject = '«Сказка»: сброс пароля'

        context = {'account': account, 'task_uuid': self.task_uuid}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Ejemplo n.º 5
0
    def process(self):

        subject = '«Сказка»: подтвердите email'

        task = ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

        if task.account.id == get_system_user().id or task.account.is_bot:
            return True

        context = {'task': task}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([(task.account, task.new_email)], subject, text_content, html_content)
Ejemplo n.º 6
0
    def process(self):

        subject = '«Сказка»: подтвердите email'

        task = ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

        if task.account.id == get_system_user().id or task.account.is_bot:
            return True

        context = {'task': task}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([(task.account, task.new_email)], subject, text_content, html_content)
Ejemplo n.º 7
0
    def process(self):
        account = AccountPrototype.get_by_id(self.account_id)

        if account.id == get_system_user().id or account.is_bot:
            return True

        subject = '«Сказка»: сброс пароля'

        context = {'account': account,
                   'task_uuid': self.task_uuid}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([account], subject, text_content, html_content)
Ejemplo n.º 8
0
 def format_output(self, rendered_widgets):
     return jinja2.Markup(
         dext_jinja2.render('companions/abilities/abilities_field.html',
                            context={
                                'widgets': rendered_widgets,
                                'FIELDS': relations.FIELDS
                            }))
Ejemplo n.º 9
0
    def handle(self, *args, **options):

        LINGUISTICS_FORMATTERS = {key.value: linguistics_logic.ui_format(key.ui_text)
                                  for key in linguistics_keys.LEXICON_KEY.records
                                  if key.ui_text is not None}

        with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f:
            f.write(jinja2.render('game/js_constants.js',
                                  context={'actor_type': s11n.to_json({a.name: a.value for a in ACTOR_TYPE.records}),
                                           'gender_to_text': s11n.to_json(dict(GENDER.select('value', 'text'))),
                                           'gender_to_str': s11n.to_json(dict(GENDER.select('value', 'name'))),
                                           'person_type_to_text': s11n.to_json(dict(PERSON_TYPE.select('value', 'text'))),
                                           'race_to_text': s11n.to_json(dict(RACE.select('value', 'text'))),
                                           'race_to_str': s11n.to_json(dict(RACE.select('value', 'name'))),
                                           'game_state': s11n.to_json(dict(GAME_STATE.select('name', 'value'))),
                                           'ARTIFACT_TYPE': artifacts_relations.ARTIFACT_TYPE,
                                           'NO_EFFECT': artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT,
                                           'EFFECTS': EFFECTS,
                                           'ARTIFACT_RARITY': artifacts_relations.RARITY,
                                           'CARD_RARITY': cards_relations.RARITY,
                                           'CARDS_EFFECTS': cards_effects.EFFECTS,
                                           'ABILITY_TYPE': ABILITY_TYPE,
                                           'SPRITES': SPRITES,
                                           'CELL_SIZE': map_settings.CELL_SIZE,
                                           'LINGUISTICS_FORMATTERS': LINGUISTICS_FORMATTERS
                                          }))
Ejemplo n.º 10
0
    def format_output(self, rendered_widgets):
        from the_tale.linguistics.relations import WORD_BLOCK_BASE
        from the_tale.linguistics.word_drawer import Leaf
        from the_tale.linguistics.word_drawer import FormFieldDrawer

        fields = get_fields(self.word_type)
        keys = {key: i for i, key in enumerate(sorted(fields.keys()))}

        leaf = Leaf(type=self.word_type,
                    base=WORD_BLOCK_BASE.C,
                    key={
                        utg_relations.NUMBER: utg_relations.NUMBER.SINGULAR,
                        utg_relations.NOUN_FORM: utg_relations.NOUN_FORM.NORMAL
                    })

        widgets = {key: rendered_widgets[keys[key]] for key in keys}

        drawer = FormFieldDrawer(type=self.word_type,
                                 widgets=widgets,
                                 skip_markers=self.skip_markers,
                                 show_properties=self.show_properties)
        return jinja2.Markup(
            dext_jinja2.render('linguistics/words/simple_noun_field.html',
                               context={
                                   'drawer': drawer,
                                   'leaf': leaf
                               }))
Ejemplo n.º 11
0
    def process(self):
        from the_tale.cms.news import logic as news_logic

        news = news_logic.load_news(self.news_id)

        if news is None:
            return True

        accounts = (AccountPrototype(model=account_model) for account_model in AccountPrototype._db_filter(news_subscription=True).iterator())

        subject = '«Сказка»::Новости: %s' % news.caption

        context = {'news': news}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Ejemplo n.º 12
0
    def process(self):
        from the_tale.forum.prototypes import PostPrototype, SubscriptionPrototype

        post = PostPrototype.get_by_id(self.post_id)

        if post is None:
            return True # post can be removed by admins or with removed thread

        accounts = SubscriptionPrototype.get_accounts_for_thread(post.thread)

        subject = '«Сказка»: %s' % post.thread.caption

        context = {'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Ejemplo n.º 13
0
    def process(self):
        from the_tale.forum.prototypes import PostPrototype, SubscriptionPrototype

        post = PostPrototype.get_by_id(self.post_id)

        if post is None:
            return True # post can be removed by admins or with removed thread

        accounts = SubscriptionPrototype.get_accounts_for_thread(post.thread)

        subject = '«Сказка»: %s' % post.thread.caption

        context = {'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Ejemplo n.º 14
0
    def process(self):
        from the_tale.news import logic as news_logic

        news = news_logic.load_news(self.news_id)

        if news is None:
            return True

        accounts = (AccountPrototype(model=account_model) for account_model in AccountPrototype._db_filter(news_subscription=True).iterator())

        subject = '«Сказка»::Новости: %s' % news.caption

        context = {'news': news}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Ejemplo n.º 15
0
    def format_output(self, rendered_widgets):
        from the_tale.linguistics.word_drawer import FormFieldDrawer

        fields = get_fields(self.word_type)
        keys = {key: i for i, key in enumerate(sorted(fields.keys()))}

        widgets = {key: rendered_widgets[keys[key]] for key in keys}

        drawer = FormFieldDrawer(type=self.word_type, widgets=widgets, skip_markers=self.skip_markers, show_properties=self.show_properties)

        return jinja2.Markup(dext_jinja2.render('linguistics/words/field.html', context={'drawer': drawer}))
Ejemplo n.º 16
0
    def process(self):
        from the_tale.forum.prototypes import ThreadPrototype, SubscriptionPrototype

        thread = ThreadPrototype.get_by_id(self.thread_id)

        if thread is None:
            return True # thread can be removed by admins or with removed thread

        post = thread.get_first_post()

        accounts = SubscriptionPrototype.get_accounts_for_subcategory(thread.subcategory)

        subject = '«Сказка»: новая тема на форуме'

        context = {'thread': thread,
                   'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Ejemplo n.º 17
0
    def process(self):
        from the_tale.forum.prototypes import ThreadPrototype, SubscriptionPrototype

        thread = ThreadPrototype.get_by_id(self.thread_id)

        if thread is None:
            return True # thread can be removed by admins or with removed thread

        post = thread.get_first_post()

        accounts = SubscriptionPrototype.get_accounts_for_subcategory(thread.subcategory)

        subject = '«Сказка»: новая тема на форуме'

        context = {'thread': thread,
                   'post': post}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail(accounts, subject, text_content, html_content)
Ejemplo n.º 18
0
    def template(self, template_name, context={}, status_code=200, charset='utf-8', mimetype='text/html'):
        full_context = {'resource': self}
        full_context.update(context)

        response_class = HttpResponse

        if status_code == 404:
            response_class = HttpResponseNotFound

        content_type = '%s; charset=%s' % (mimetype, charset)

        text = jinja2.render(template_name, context=full_context, request=self.request)

        return response_class(text, content_type=content_type)
Ejemplo n.º 19
0
    def handle(self, *args, **options):

        with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f:
            f.write(
                jinja2.render(
                    'game/js_constants.js',
                    context={
                        'actor_type':
                        s11n.to_json(
                            {a.name: a.value
                             for a in ACTOR_TYPE.records}),
                        'gender_to_text':
                        s11n.to_json(dict(GENDER.select('value', 'text'))),
                        'gender_to_str':
                        s11n.to_json(dict(GENDER.select('value', 'name'))),
                        'person_type_to_text':
                        s11n.to_json(dict(PERSON_TYPE.select('value',
                                                             'text'))),
                        'race_to_text':
                        s11n.to_json(dict(RACE.select('value', 'text'))),
                        'race_to_str':
                        s11n.to_json(dict(RACE.select('value', 'name'))),
                        'game_state':
                        s11n.to_json(dict(GAME_STATE.select('name', 'value'))),
                        'ARTIFACT_TYPE':
                        artifacts_relations.ARTIFACT_TYPE,
                        'NO_EFFECT':
                        artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT,
                        'EFFECTS':
                        EFFECTS,
                        'ARTIFACT_RARITY':
                        artifacts_relations.RARITY,
                        'CARD_RARITY':
                        cards_relations.RARITY,
                        'CARDS_EFFECTS':
                        cards_effects.EFFECTS,
                        'ABILITY_TYPE':
                        ABILITY_TYPE,
                        'SPRITES':
                        SPRITES,
                        'CELL_SIZE':
                        map_settings.CELL_SIZE
                    }).encode('utf-8'))
Ejemplo n.º 20
0
def account_sidebar(user_account, page_account, page_caption, page_type, can_moderate=False):
    from the_tale.forum.models import Thread
    from the_tale.game.bills.prototypes import BillPrototype
    from the_tale.linguistics.prototypes import ContributionPrototype
    from the_tale.linguistics.relations import CONTRIBUTION_TYPE
    from the_tale.accounts.friends.prototypes import FriendshipPrototype
    from the_tale.accounts.clans.logic import ClanInfo
    from the_tale.blogs.models import Post as BlogPost, POST_STATE as BLOG_POST_STATE

    bills_count = BillPrototype.accepted_bills_count(page_account.id)

    threads_count = Thread.objects.filter(author=page_account._model).count()

    threads_with_posts = Thread.objects.filter(post__author=page_account._model).distinct().count()

    templates_count = ContributionPrototype._db_filter(account_id=page_account.id,
                                                       type=CONTRIBUTION_TYPE.TEMPLATE).count()

    words_count = ContributionPrototype._db_filter(account_id=page_account.id,
                                                   type=CONTRIBUTION_TYPE.WORD).count()

    folclor_posts_count = BlogPost.objects.filter(author=page_account._model, state=BLOG_POST_STATE.ACCEPTED).count()

    friendship = FriendshipPrototype.get_for_bidirectional(user_account, page_account)

    return jinja2.Markup(jinja2.render('accounts/sidebar.html',
                                            context={'user_account': user_account,
                                                     'page_account': page_account,
                                                     'page_caption': page_caption,
                                                     'master_clan_info': ClanInfo(page_account),
                                                     'own_clan_info': ClanInfo(user_account),
                                                     'friendship': friendship,
                                                     'bills_count': bills_count,
                                                     'templates_count': templates_count,
                                                     'words_count': words_count,
                                                     'folclor_posts_count': folclor_posts_count,
                                                     'threads_count': threads_count,
                                                     'threads_with_posts': threads_with_posts,
                                                     'can_moderate': can_moderate,
                                                     'page_type': page_type,
                                                     'commission': conf.accounts_settings.MONEY_SEND_COMMISSION}))
Ejemplo n.º 21
0
    def handle(self, *args, **options):

        with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f:
            f.write(jinja2.render('game/js_constants.js',
                                  context={'actor_type': s11n.to_json({a.name: a.value for a in ACTOR_TYPE.records}),
                                           'gender_to_text': s11n.to_json(dict(GENDER.select('value', 'text'))),
                                           'gender_to_str': s11n.to_json(dict(GENDER.select('value', 'name'))),
                                           'person_type_to_text': s11n.to_json(dict(PERSON_TYPE.select('value', 'text'))),
                                           'race_to_text': s11n.to_json(dict(RACE.select('value', 'text'))),
                                           'race_to_str': s11n.to_json(dict(RACE.select('value', 'name'))),
                                           'game_state': s11n.to_json(dict(GAME_STATE.select('name', 'value'))),
                                           'ARTIFACT_TYPE': artifacts_relations.ARTIFACT_TYPE,
                                           'NO_EFFECT': artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT,
                                           'EFFECTS': EFFECTS,
                                           'ARTIFACT_RARITY': artifacts_relations.RARITY,
                                           'CARD_RARITY': cards_relations.RARITY,
                                           'CARDS_EFFECTS': cards_effects.EFFECTS,
                                           'ABILITY_TYPE': ABILITY_TYPE,
                                           'SPRITES': SPRITES,
                                           'CELL_SIZE': map_settings.CELL_SIZE
                                          }).encode('utf-8'))
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
 def item_html(self, item):
     return jinja2.render(self.item_template, context={'item': item})
Ejemplo n.º 24
0
 def complete(self, context):
     self.content["context"] = context
     self.content = jinja2.render(self.template, context=self.content, request=context.django_request)
     return super(Page, self).complete(context)
Ejemplo n.º 25
0
def account_sidebar(user_account,
                    page_account,
                    page_caption,
                    page_type,
                    can_moderate=False):
    from the_tale.forum.models import Thread
    from the_tale.game.bills.prototypes import BillPrototype
    from the_tale.linguistics.prototypes import ContributionPrototype
    from the_tale.linguistics.relations import CONTRIBUTION_TYPE
    from the_tale.accounts.friends.prototypes import FriendshipPrototype
    from the_tale.accounts.clans.logic import ClanInfo
    from the_tale.blogs.models import Post as BlogPost, POST_STATE as BLOG_POST_STATE

    bills_count = BillPrototype.accepted_bills_count(page_account.id)

    threads_count = Thread.objects.filter(author=page_account._model).count()

    threads_with_posts = Thread.objects.filter(
        post__author=page_account._model).distinct().count()

    templates_count = ContributionPrototype._db_filter(
        account_id=page_account.id, type=CONTRIBUTION_TYPE.TEMPLATE).count()

    words_count = ContributionPrototype._db_filter(
        account_id=page_account.id, type=CONTRIBUTION_TYPE.WORD).count()

    folclor_posts_count = BlogPost.objects.filter(
        author=page_account._model, state=BLOG_POST_STATE.ACCEPTED).count()

    friendship = FriendshipPrototype.get_for_bidirectional(
        user_account, page_account)

    return jinja2.Markup(
        jinja2.render('accounts/sidebar.html',
                      context={
                          'user_account':
                          user_account,
                          'page_account':
                          page_account,
                          'page_caption':
                          page_caption,
                          'master_clan_info':
                          ClanInfo(page_account),
                          'own_clan_info':
                          ClanInfo(user_account),
                          'friendship':
                          friendship,
                          'bills_count':
                          bills_count,
                          'templates_count':
                          templates_count,
                          'words_count':
                          words_count,
                          'folclor_posts_count':
                          folclor_posts_count,
                          'threads_count':
                          threads_count,
                          'threads_with_posts':
                          threads_with_posts,
                          'can_moderate':
                          can_moderate,
                          'page_type':
                          page_type,
                          'commission':
                          conf.accounts_settings.MONEY_SEND_COMMISSION
                      }))
Ejemplo n.º 26
0
 def format_output(self, rendered_widgets):
     return jinja2.Markup(dext_jinja2.render('companions/abilities/abilities_field.html', context={'widgets': rendered_widgets,
                                                                                                   'FIELDS': relations.FIELDS}))
Ejemplo n.º 27
0
    def handle(self, *args, **options):

        LINGUISTICS_FORMATTERS = {
            key.value: linguistics_logic.ui_format(key.ui_text)
            for key in linguistics_keys.LEXICON_KEY.records
            if key.ui_text is not None
        }

        race_to_text = {}
        for race in RACE.records:
            race_to_text[race.value] = {
                'male': race.male_text,
                'female': race.female_text
            }

        personality_practical_to_text = {}
        for personality in persons_relations.PERSONALITY_PRACTICAL.records:
            personality_practical_to_text[personality.value] = {
                'male': personality.male_text,
                'female': personality.female_text
            }

        personality_cosmetic_to_text = {}
        for personality in persons_relations.PERSONALITY_COSMETIC.records:
            personality_cosmetic_to_text[personality.value] = {
                'male': personality.male_text,
                'female': personality.female_text
            }

        with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f:
            f.write(
                jinja2.render(
                    'game/js_constants.js',
                    context={
                        'actor_type':
                        s11n.to_json(
                            {a.name: a.value
                             for a in ACTOR_TYPE.records}),
                        'gender_to_text':
                        s11n.to_json(dict(GENDER.select('value', 'text'))),
                        'gender_to_str':
                        s11n.to_json(dict(GENDER.select('value', 'name'))),
                        'person_type_to_text':
                        s11n.to_json(
                            dict(
                                persons_relations.PERSON_TYPE.select(
                                    'value', 'text'))),
                        'race_to_text':
                        s11n.to_json(race_to_text),
                        'game_state':
                        s11n.to_json(dict(GAME_STATE.select('name', 'value'))),
                        'ARTIFACT_TYPE':
                        artifacts_relations.ARTIFACT_TYPE,
                        'NO_EFFECT':
                        artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT,
                        'EFFECTS':
                        EFFECTS,
                        'ARTIFACT_RARITY':
                        artifacts_relations.RARITY,
                        'CARD_RARITY':
                        cards_relations.RARITY,
                        'CARD':
                        cards.CARD,
                        'ABILITY_TYPE':
                        ABILITY_TYPE,
                        'SPRITES':
                        SPRITES,
                        'CELL_SIZE':
                        map_settings.CELL_SIZE,
                        'LINGUISTICS_FORMATTERS':
                        LINGUISTICS_FORMATTERS,
                        'personality_practical_to_text':
                        personality_practical_to_text,
                        'personality_cosmetic_to_text':
                        personality_cosmetic_to_text
                    }))
Ejemplo n.º 28
0
 def item_html(self, item):
     return jinja2.render(self.item_template, context={'item': item})