Esempio n. 1
0
class Command(BaseCommand):

    help = 'Synchroniser les catégories CKAN avec IDGO.'

    def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)
        self.ckan = CkanManagerHandler()

    def handle(self, *args, **options):
        for category in Category.objects.all():
            if self.ckan.is_group_exists(category.slug):
                category.ckan_id = self.ckan.get_group(category.slug)['id']
                category.save()
                self.stdout.write("'{0}' updated".format(category.slug))
Esempio n. 2
0
class Command(BaseCommand):

    help = 'Synchroniser les catégories IDGO avec CKAN.'

    def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)
        self.ckan = CkanManagerHandler()

    def handle(self, *args, **options):
        for category in Category.objects.all():
            if self.ckan.is_group_exists(category.slug):
                self.stdout.write("'{0}' already exists".format(category.slug))
                continue
            self.ckan.add_group(category)
            self.stdout.write("'{0}' is created".format(category.slug))
class Command(BaseCommand):

    help = "Supprimer les organisations CKAN qui n'ont aucun jeu de données."

    def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)
        self.ckan = CkanManagerHandler()

    def handle(self, *args, **options):
        for instance in Organisation.objects.all():
            organisation = self.ckan.get_organisation(str(instance.ckan_id),
                                                      include_datasets=True)
            if not organisation:
                continue
            if len(organisation['packages']) > 0:
                continue
            self.ckan.purge_organisation(str(instance.ckan_id))
Esempio n. 4
0
    def merge_name(self, request, queryset):

        datasets = Dataset.objects.filter(keywords__in=queryset)
        if 'apply' in request.POST:
            form = NewKeywordForm(request.POST)
            if form.is_valid():

                # On met a jours les datasets et on retourne sur le listing
                # self.tags_update(new_name, datasets)
                new_tag, _ = Tag.objects.get_or_create(
                    name=form.cleaned_data.get('new_name'))
                for dataset in datasets:
                    dataset.keywords.add(new_tag)
                    # On synchronise CKAN
                    try:
                        ckan = CkanManagerHandler()
                        ckan.publish_dataset(
                            id=str(dataset.ckan_id),
                            tags=[{
                                'name': keyword.name
                            } for keyword in dataset.keywords.all()])
                    except CkanBaseError as err:
                        messages.error(request, err)

                # Le clean des vieux tags se fait en dernier
                # pour garder la selection de tous les datasets
                queryset.exclude(pk=new_tag.pk).delete()

                messages.info(request, "Mise à jour effectuée.")
                return HttpResponseRedirect(request.get_full_path())
        else:
            form = NewKeywordForm()

        context = {'form': form, 'tags': queryset, 'datasets': datasets}
        return render(request,
                      'admin/idgo_admin/taggit_merge_name.html',
                      context=context)
Esempio n. 5
0
class Command(BaseCommand):

    help = 'Synchroniser les tags IDGO avec CKAN.'

    def __init__(self, *args, **kwargs):
        super(Command, self).__init__(*args, **kwargs)
        self.ckan = CkanManagerHandler()

    def sync_tags(self, data, vocabulary_name):
        vocabulary = self.ckan.get_vocabulary(vocabulary_name)
        if not vocabulary:
            self.ckan.add_vocabulary(vocabulary,
                                     [entry.slug for entry in data])
            self.stdout.write("New vocabulary '{0}' created".format(
                entry.slug))
        else:
            for entry in data:
                if self.ckan.is_tag_exists(entry.name,
                                           vocabulary_id=vocabulary['id']):
                    self.stdout.write("'{0}' already sync".format(entry.name))
                    continue
                self.ckan.add_tag(entry.name, vocabulary_id=vocabulary['id'])
                self.stdout.write("'{0}' added".format(entry.name))

    def sync_group(self, queryset, group_type=None):
        for entry in queryset:
            if self.ckan.is_group_exists(entry.slug):
                self.stdout.write("'{0}' already exists".format(entry.slug))
                continue
            self.ckan.add_group(entry, type=group_type)
            self.stdout.write("'{0}' is created".format(entry.slug))

    def handle(self, *args, **options):
        self.sync_group(DataType.objects.all(), group_type='data_type')
        self.sync_group(Support.objects.all(), group_type='support')

        # self.sync_tags(DataType.objects.all(), 'data_type')
        # self.sync_tags(Support.objects.all(), 'support')

        self.stdout.write('Done!')
Esempio n. 6
0
 def __init__(self, *args, **kwargs):
     super(Command, self).__init__(*args, **kwargs)
     self.ckan = CkanManagerHandler()