Ejemplo n.º 1
0
def create_test_datasets(request, quantity=10):
    from core.lifecycle.datasets import DatasetLifeCycleManager
    quantity = int(quantity)
    info = '<h2>Creating %d datasets</h2>' % quantity
    #define any existent category
    account_id = request.auth_manager.account_id
    category = Category.objects.filter(
        account_id=account_id).order_by('-id')[0]
    category_id = category.id

    logger = logging.getLogger(__name__)
    logger.error("Categoy %d" % category_id)
    user = User.objects.get(pk=request.user.id)

    for x in range(0, quantity):
        dt = DatasetLifeCycleManager(user=user)
        typec = choices.CollectTypeChoices.SELF_PUBLISH
        typefile = choices.SourceImplementationChoices.CSV
        newdataset = dt.create(title='Datset %d' % x,
                               collect_type=typec,
                               description="Descripcion del dataset %d" % x,
                               end_point="/home/junar/Downloads/file-%d.csv" %
                               x,
                               notes='',
                               file_name="resource-%d.csv" % x,
                               category=category_id,
                               impl_type=typefile)
        info += '<br />Created Dataset %d' % x
    return HttpResponse(info)
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
 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))
Ejemplo n.º 4
0
 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))
Ejemplo n.º 5
0
    def test_publish_dataset_as_editor(self):
        """
        [Lifecycle] Test de publicacion de dataset como usuario editor
        """
        dataset, rev = self.create_dataset(user=self.user_editor)

        life = DatasetLifeCycleManager(self.user_editor, dataset_revision_id=rev.id)
        life.publish()

        new_dataset = Dataset.objects.get(id=dataset.id)

        self.assertEqual(new_dataset.last_revision, DatasetRevision.objects.get(dataset=new_dataset))
        self.assertEqual(new_dataset.last_published_revision, DatasetRevision.objects.get(dataset=new_dataset))
Ejemplo n.º 6
0
    def create_dataset(self, status=StatusChoices.DRAFT, user=None):
        life_cycle = DatasetLifeCycleManager(user=user, language=user.language)

        dataset_rev = life_cycle.create(title='Test Dataset',
                                        collect_type=self.collect_type,
                                        description="Descripcion del dataset",
                                        end_point=self.end_point,
                                        notes='Test notes',
                                        category=self.category.id,
                                        impl_type=self.source_type,
                                        file_name='',
                                        status=status)

        dataset = dataset_rev.dataset
        return dataset, dataset_rev
Ejemplo n.º 7
0
    def create(self, validated_data):
        if 'file_data' not in validated_data and 'end_point' not in validated_data:
            raise exceptions.ValidationError({'description': 'O end_point o file. No puede estar ambas vacias.'})

        return self.getDao(
            DatasetLifeCycleManager(self.context['request'].user).create(**validated_data)
        )
Ejemplo n.º 8
0
    def test_publish_dataset_as_editor(self):
        """
        [Lifecycle] Test de publicacion de dataset como usuario editor
        """
        dataset, rev = self.create_dataset(user=self.user_editor)

        life = DatasetLifeCycleManager(self.user_editor,
                                       dataset_revision_id=rev.id)
        life.publish()

        new_dataset = Dataset.objects.get(id=dataset.id)

        self.assertEqual(new_dataset.last_revision,
                         DatasetRevision.objects.get(dataset=new_dataset))
        self.assertEqual(new_dataset.last_published_revision,
                         DatasetRevision.objects.get(dataset=new_dataset))
Ejemplo n.º 9
0
    def create_dataset(self, status=StatusChoices.DRAFT, user=None):
        life_cycle = DatasetLifeCycleManager(user=user, language=user.language)

        dataset_rev = life_cycle.create(
            title="Test Dataset",
            collect_type=self.collect_type,
            description="Descripcion del dataset",
            end_point=self.end_point,
            notes="Test notes",
            category=self.category.id,
            impl_type=self.source_type,
            file_name="",
            status=status,
        )

        dataset = dataset_rev.dataset
        return dataset, dataset_rev
Ejemplo n.º 10
0
    def handle(self, *args, **options):
        # OH SI, Hardcodeo el idioma
        # en realidad deberia cambiar el loc

        for dataset_rev in DatasetRevision.objects.all():
            try:
                translation.activate(dataset_rev.user.language)
                lifecycle = DatasetLifeCycleManager(
                    dataset_rev.user, dataset_revision_id=dataset_rev.id)
                lifecycle._log_activity(ActionStreams.CREATE)
            except:
                pass
            finally:
                translation.deactivate()

        for datastream_rev in DataStreamRevision.objects.all():
            try:
                translation.activate(datastream_rev.user.language)
                lifecycle = DatastreamLifeCycleManager(
                    datastream_rev.user,
                    datastream_revision_id=datastream_rev.id)
                lifecycle._log_activity(ActionStreams.CREATE)
            except:
                pass
            finally:
                translation.deactivate()
Ejemplo n.º 11
0
def create_test_datasets(request, quantity=10):
    from core.lifecycle.datasets import DatasetLifeCycleManager
    quantity = int(quantity)
    info = '<h2>Creating %d datasets</h2>' % quantity
    #define any existent category
    account_id = request.auth_manager.account_id
    category = Category.objects.filter(account_id = account_id).order_by('-id')[0]
    category_id = category.id
    
    logger = logging.getLogger(__name__)
    logger.error("Categoy %d" % category_id)
    user = User.objects.get(pk=request.user.id)

    for x in range(0, quantity):
        dt = DatasetLifeCycleManager(user=user)
        typec = choices.CollectTypeChoices.SELF_PUBLISH
        typefile = choices.SourceImplementationChoices.CSV
        newdataset = dt.create(title='Datset %d' % x, collect_type=typec, description="Descripcion del dataset %d" % x,
                               end_point="/home/junar/Downloads/file-%d.csv" % x, notes='',
                               file_name="resource-%d.csv" % x, category=category_id, impl_type=typefile)
        info += '<br />Created Dataset %d' % x
    return HttpResponse(info)
Ejemplo n.º 12
0
        def _wrapped_view(request, *args, **kwargs):
            # check for new status
            if request.POST.get('status', StatusChoices.DRAFT) == StatusChoices.PUBLISHED:
                # new status is published the check the related resource
                if request.POST.get('dataset_revision_id', False):
                    dataset_revision_id=request.POST['dataset_revision_id']
                    resource = DatasetLifeCycleManager(user = request.user.id, dataset_revision_id=dataset_revision_id)
                    if resource.dataset_revision.status != StatusChoices.PUBLISHED:
                        raise DatastreamParentNotPublishedException(resource.dataset_revision)
                elif request.POST.get('datastream_revision_id', False):
                    datastream_revision_id=request.POST['datastream_revision_id']
                    resource = DatastreamLifeCycleManager(user = request.user.id, resource_revision_id=datastream_revision_id)
                    if resource.dataset_revision.status != StatusChoices.PUBLISHED:
                        raise VisualizationParentNotPublishedException(resource.dataset_revision)
                else:
                    raise ParentNotPublishedException()

            return view_func(request, *args, **kwargs)
Ejemplo n.º 13
0
    def test_unpublish_dataset_as_admin(self):
        """
        [Lifecycle] Test de despublicar de dataset como usuario administrador
        """
        dataset, rev = self.create_dataset(user=self.user_admin)

        life = DatasetLifeCycleManager(self.user_admin,
                                       dataset_revision_id=rev.id)
        life.publish()

        new_dataset = Dataset.objects.get(id=dataset.id)

        life = DatasetLifeCycleManager(self.user_admin,
                                       dataset_id=new_dataset.id)
        life.unpublish()

        new_dataset = Dataset.objects.get(id=dataset.id)

        self.assertEqual(new_dataset.last_revision,
                         DatasetRevision.objects.get(dataset=new_dataset))
        self.assertIsNone(new_dataset.last_published_revision)
Ejemplo n.º 14
0
    def handle(self, *args, **options):
        # OH SI, Hardcodeo el idioma
        # en realidad deberia cambiar el loc


        for dataset_rev in DatasetRevision.objects.all():
            translation.activate(dataset_rev.user.language)
            lifecycle = DatasetLifeCycleManager(dataset_rev.user, dataset_revision_id=dataset_rev.id)
            lifecycle._log_activity(ActionStreams.CREATE)
            translation.deactivate()

        for datastream_rev in DataStreamRevision.objects.all():
            translation.activate(datastream_rev.user.language)
            lifecycle = DatastreamLifeCycleManager(datastream_rev.user, datastream_revision_id=datastream_rev.id)
            lifecycle._log_activity(ActionStreams.CREATE)
            translation.deactivate()
Ejemplo n.º 15
0
    def test_unpublish_dataset_as_admin(self):
        """
        [Lifecycle] Test de despublicar de dataset como usuario administrador
        """
        dataset, rev = self.create_dataset(user=self.user_admin)

        life = DatasetLifeCycleManager(self.user_admin, dataset_revision_id=rev.id)
        life.publish()

        new_dataset = Dataset.objects.get(id=dataset.id)

        life = DatasetLifeCycleManager(self.user_admin, dataset_id=new_dataset.id)
        life.unpublish()

        new_dataset = Dataset.objects.get(id=dataset.id)

        self.assertEqual(new_dataset.last_revision, DatasetRevision.objects.get(dataset=new_dataset))
        self.assertIsNone(new_dataset.last_published_revision)
Ejemplo n.º 16
0
    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')