Example #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)
Example #2
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
Example #3
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
Example #4
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)
Example #5
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')