def handle(self, *args, **options): result = DepartmentService.remove_all() if not result: logger.error('init failed') return for department_info in ROOT_DEPARTMENT: self.create_root_department(department_info) print 'import department: %s(%s) done !' % ( department_info['department_name'], department_info['department_id']) accounts = Account.objects.filter(type=AccountType.TENANT, deleted=False) members = [account.user for account in accounts] DepartmentMemberService.join(members, 'dep-00000002') accounts = Account.objects.filter(type=AccountType.HANKOU, deleted=False) members = [account.user for account in accounts] DepartmentMemberService.join(members, 'dep-00000001')
def handle(self, *args, **options): company_name = raw_input('Create Department:\nInput company name: ') if 'clear' == options.get('clear').lower(): result = DepartmentService.remove_all() if not result: logger.error('clear failed') return department = Department(name=company_name, description=gen_description(), department_id=FIRST_DEPARTMENT_ID, path=FIRST_DEPARTMENT_ID, level=0) department.save() department.parent_department = department department.save() else: Department.objects.filter( department_id=FIRST_DEPARTMENT_ID).update(name=company_name) accounts = Account.objects.filter(deleted=False).exclude( name='system_image') members = [account.user for account in accounts] DepartmentMemberService.join(members, FIRST_DEPARTMENT_ID)