

def generate_transitions(self):
    self.stdout.write('Generating Transitions')

    def add_transition(content_type, name, source, target, actions):
        (transition, _) = Transition.objects.get_or_create(model=TransitionModel.objects.get(content_type=content_type), name=name, source=source, target=target)
        for action in actions:
            transition.actions.add(Action.objects.get(name=action, content_type=content_type))
    report = Report.objects.create(name='release')
    language = ReportLanguage.objects.create(name='en', default=True)
    report_template = ReportTemplate.objects.create(language=language, default=True, report=report)
    with open(os.path.join(settings.BASE_DIR, 'data_importer/data/release.odt'), 'rb') as f:
        report_template.template.save('release.odt', File(f))
    bo_content_type = ContentType.objects.get_for_model(BackOfficeAsset)
    add_transition(bo_content_type, 'Deploy', [BackOfficeAssetStatus.new.id, BackOfficeAssetStatus.in_progress.id, BackOfficeAssetStatus.waiting_for_release.id, BackOfficeAssetStatus.used.id, BackOfficeAssetStatus.loan.id, BackOfficeAssetStatus.damaged.id, BackOfficeAssetStatus.in_service.id, BackOfficeAssetStatus.installed.id, BackOfficeAssetStatus.free.id, BackOfficeAssetStatus.reserved.id], BackOfficeAssetStatus.in_progress.id, ['assign_licence', 'assign_user', 'assign_owner'])
    add_transition(bo_content_type, 'Release asset', [BackOfficeAssetStatus.new.id, BackOfficeAssetStatus.in_progress.id, BackOfficeAssetStatus.waiting_for_release.id, BackOfficeAssetStatus.free.id, BackOfficeAssetStatus.reserved.id], BackOfficeAssetStatus.used.id, ['assign_user', 'assign_owner', 'assign_warehouse', 'release_report'])
    add_transition(bo_content_type, 'Loan asset', [BackOfficeAssetStatus.new.id, BackOfficeAssetStatus.in_progress.id, BackOfficeAssetStatus.waiting_for_release.id, BackOfficeAssetStatus.free.id, BackOfficeAssetStatus.reserved.id], BackOfficeAssetStatus.loan.id, ['assign_loan_end_date', 'assign_user', 'assign_owner', 'assign_warehouse', 'assign_task_url'])
    add_transition(bo_content_type, 'Buyout', [i[0] for i in BackOfficeAssetStatus()], BackOfficeAssetStatus.liquidated.id, ['assign_task_url', 'assign_warehouse', 'assign_warehouse', 'unassign_licences', 'unassign_loan_end_date', 'unassign_owner'])
    dc_content_type = ContentType.objects.get_for_model(DataCenterAsset)
    add_transition(dc_content_type, 'Change rack', [DataCenterAssetStatus.free.id, DataCenterAssetStatus.new.id, DataCenterAssetStatus.to_deploy.id], DataCenterAssetStatus.used.id, ['change_rack'])

dataset/ETHPy150Open allegro/ralph/src/ralph/data_importer/management/commands/demodata.py Command.generate_transitions/original