def test_add_items(self): GiveItemTaskPrototype.create(account_id=self.account_1.id, item_id=self.item_2_1.id) self.assertFalse(self.account_1_items.has_item(self.item_2_1)) self.worker.add_items() self.account_1_items.reload() self.assertTrue(self.account_1_items.has_item(self.item_2_1)) self.assertEqual(GiveItemTaskPrototype._db_count(), 0)
def handle(self, *args, **options): for achievements in models.AccountAchievements.objects.all().iterator(): prototype = prototypes.AccountAchievementsPrototype(achievements) collection = AccountItemsPrototype.get_by_account_id(prototype.account_id) for achievement_id in prototype.achievements.achievements_ids(): for item in storage.achievements_storage[achievement_id].rewards: if not collection.has_item(item): GiveItemTaskPrototype.create(prototype.account_id, item.id)
def handle(self, *args, **options): for achievements in models.AccountAchievements.objects.all().iterator( ): prototype = prototypes.AccountAchievementsPrototype(achievements) collection = AccountItemsPrototype.get_by_account_id( prototype.account_id) for achievement_id in prototype.achievements.achievements_ids(): for item in storage.achievements_storage[ achievement_id].rewards: if not collection.has_item(item): GiveItemTaskPrototype.create(prototype.account_id, item.id)
def add_achievement(self, achievement, notify): from the_tale.collections.prototypes import GiveItemTaskPrototype from the_tale.accounts.personal_messages import tt_api as pm_tt_api from the_tale.accounts.logic import get_system_user already_had_achievement = self.achievements.has_achievement( achievement) self.achievements.add_achievement(achievement) self._model.points = self.achievements.get_points() rewards = achievement.rewards approved_rewards = achievement.approved_rewards for item in rewards: GiveItemTaskPrototype.create(self.account_id, item.id) if not notify or already_had_achievement: return rewards_message = '' if approved_rewards: reward_texts = [] for item in approved_rewards: reward_texts.append('[url=%s#k%d]%s[/url]' % (full_url( 'http', 'collections:collections:show', item.kit.collection.id), item.kit.id, item.caption)) rewards_message = 'Награды: %s' % ', '.join(reward_texts) message = ( 'Вы заработали достижение «%(achievement)s» — %(description)s. %(rewards_message)s' % { 'achievement': '[url=%s#a%d]%s[/url]' % (full_url('http', 'accounts:achievements:group', achievement. group.slug), achievement.id, achievement.caption), 'description': achievement.description, 'rewards_message': rewards_message }) pm_tt_api.send_message(get_system_user().id, [self.account.id], message, async=True)
def add_achievement(self, achievement, notify): from the_tale.collections.prototypes import GiveItemTaskPrototype from the_tale.accounts.personal_messages.prototypes import MessagePrototype from the_tale.accounts.logic import get_system_user already_had_achievement = self.achievements.has_achievement(achievement) self.achievements.add_achievement(achievement) self._model.points = self.achievements.get_points() rewards = achievement.rewards approved_rewards = achievement.approved_rewards for item in rewards: GiveItemTaskPrototype.create(self.account_id, item.id) if not notify or already_had_achievement: return rewards_message = '' if approved_rewards: reward_texts = [] for item in approved_rewards: reward_texts.append( '[url=%s#k%d]%s[/url]' % (full_url('http', 'collections:collections:show', item.kit.collection.id), item.kit.id, item.caption)) rewards_message = 'Награды: %s' % ', '.join(reward_texts) message = ('Вы заработали достижение «%(achievement)s» — %(description)s. %(rewards_message)s' % {'achievement': '[url=%s#a%d]%s[/url]' % (full_url('http', 'accounts:achievements:group', achievement.group.slug), achievement.id, achievement.caption), 'description': achievement.description, 'rewards_message': rewards_message}) MessagePrototype.create(get_system_user(), self.account, message)