def update(self, instance, validated_data): lcycle = DatasetLifeCycleManager(self.context['request'].user, dataset_id=instance['dataset_id']) if 'file_data' in validated_data and len(validated_data) == 5: #file and status, impl_type, collect_type, language return self.getDao(lcycle.update_file(**validated_data)) else: instance.update(validated_data) if 'impl_details' in instance: instance.pop('impl_details') return self.getDao(lcycle.edit(changed_fields=validated_data.keys(), **instance))
def update(self, instance, validated_data): lcycle = DatasetLifeCycleManager(self.context['request'].user, dataset_id=instance['dataset_id']) if 'file_data' in validated_data and len(validated_data) == 5: #file and status, impl_type, collect_type, language return self.getDao(lcycle.update_file(**validated_data)) else: instance.update(validated_data) if 'impl_details' in instance: instance.pop('impl_details') return self.getDao(lcycle.edit(changed_fields=validated_data.keys(), **instance))
def update(self, instance, validated_data): lcycle = DatasetLifeCycleManager(self.context["request"].user, dataset_id=instance["dataset_id"]) if ( "file_data" in validated_data and len(validated_data) == 5 ): # file and status, impl_type, collect_type, language return self.getDao(lcycle.update_file(**validated_data)) else: instance.update(validated_data) if "impl_details" in instance: instance.pop("impl_details") return self.getDao(lcycle.edit(changed_fields=validated_data.keys(), **instance))
def handle(self, *args, **options): # Creates dummy Datasets if options['create_dummy']: end_point = 'www.example.com' try: create_count = int(options['create_dummy']) except: raise CommandError('Create dummy datasets must provide a number of datasets to create.') if 'user' not in options.keys() or not options['user']: raise CommandError('Create dummy datasets must provide a user (--user=username) to assign datasets') try: user = User.objects.get(nick=options['user']) except: raise CommandError('Can not found User with username {}.'.format(options['user'])) try: category = Category.objects.filter(account_id=user.account.id).order_by('-id')[0] except: raise CommandError('Can not found Categories for user {}.'.format(user)) life_cycle = DatasetLifeCycleManager(user=user) collect_type = CollectTypeChoices.SELF_PUBLISH source_type = SourceImplementationChoices.HTML for x in range(0, create_count): dataset_revision = life_cycle.create( title='Dummy Dataset', collect_type=collect_type, description="Descripcion del dataset", end_point=end_point, notes='', category=category.id, impl_type=source_type, file_name='' ) if options['with_revisions']: lifecycle = DatasetLifeCycleManager(user=user, language=user.language, dataset_revision_id=dataset_revision.id) lifecycle.send_to_review() lifecycle.accept() lifecycle.publish() # Edito el recurso lifecycle.edit(collect_type=collect_type, changed_fields=['title'], language=user.language, title='Nuevo titulo', category=category.id, file_name='', end_point=end_point, impl_type=source_type, file_size=0, license_url='', spatial='', frequency='monthly', mbox='', impl_details='', description='Nueva descripcion', notes='', tags=[], sources=[], status=StatusChoices.PUBLISHED) # Edito el recurso lifecycle.edit(collect_type=collect_type, changed_fields=['title'], language=user.language, title='Nuevo titulo 1', category=category.id, file_name='', end_point=end_point, impl_type=source_type, file_size=0, license_url='', spatial='', frequency='monthly', mbox='', impl_details='', description='Nueva descripcion', notes='', tags=[], sources=[], status=StatusChoices.PUBLISHED) # Edito el recurso lifecycle.edit(collect_type=collect_type, changed_fields=['title'], language=user.language, title='Nuevo titulo 2', category=category.id, file_name='', end_point=end_point, impl_type=source_type, file_size=0, license_url='', spatial='', frequency='monthly', mbox='', impl_details='', description='Nueva descripcion', notes='', tags=[], sources=[], status=StatusChoices.PUBLISHED) self.stdout.write('Datasets created successfully')