def create(cls, owner, abbr, name, motto, description): forum_category = CategoryPrototype.get_by_slug(clans_settings.FORUM_CATEGORY_SLUG) subcategory_order = SubCategoryPrototype._db_filter(category=forum_category.id).aggregate(models.Max('order'))['order__max'] if subcategory_order is None: subcategory_order = 0 else: subcategory_order += 1 forum_subcategory = SubCategoryPrototype.create(category=forum_category, caption=cls.get_forum_subcategory_caption(name), order=subcategory_order, restricted=True) clan_model = cls._model_class.objects.create(name=name, abbr=abbr, motto=motto, description=description, members_number=1, forum_subcategory=forum_subcategory._model) clan = cls(clan_model) MembershipPrototype.create(owner, clan, role=MEMBER_ROLE.LEADER) owner.set_clan_id(clan.id) return clan
def create(cls, owner, abbr, name, motto, description): forum_category = CategoryPrototype.get_by_slug(clans_settings.FORUM_CATEGORY_SLUG) subcategory_order = SubCategoryPrototype._db_filter(category=forum_category.id).aggregate(models.Max('order'))['order__max'] if subcategory_order is None: subcategory_order = 0 else: subcategory_order += 1 forum_subcategory = SubCategoryPrototype.create(category=forum_category, caption=cls.get_forum_subcategory_caption(name), order=subcategory_order, restricted=True) clan_model = cls._model_class.objects.create(name=name, abbr=abbr, motto=motto, description=description, members_number=1, forum_subcategory=forum_subcategory._model) clan = cls(clan_model) MembershipPrototype.create(owner, clan, role=MEMBER_ROLE.LEADER) owner.set_clan_id(clan.id) return clan
def test_delete(self): category = CategoryPrototype.create(caption='cat-caption', slug='cat-slug', order=0) subcategory_1 = SubCategoryPrototype.create(category=category, caption='subcat-1-caption', order=2) subcategory_2 = SubCategoryPrototype.create(category=category, caption='subcat-2-caption', order=1) thread_1_1 = ThreadPrototype.create(subcategory_1, 'thread-1_1-caption', self.account, 'thread-1_1-text') thread_1_2 = ThreadPrototype.create(subcategory_1, 'thread-1_2-caption', self.account, 'thread-1_2-text') thread_2_1 = ThreadPrototype.create(subcategory_2, 'thread-2_1-caption', self.account, 'thread-2_1-text') subcategory_1.delete() self.assertFalse(ThreadPrototype._db_filter(id__in=(thread_1_1.id, thread_1_2.id)).exists()) self.assertTrue(ThreadPrototype._db_filter(id=thread_2_1.id).exists()) self.assertFalse(SubCategoryPrototype._db_filter(id=subcategory_1.id).exists()) self.assertTrue(SubCategoryPrototype._db_filter(id=subcategory_2.id).exists())