예제 #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))
예제 #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))
예제 #3
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!')