コード例 #1
0
ファイル: update_canons.py プロジェクト: JoeGermuska/crowdata
    def import_canons(self, csv_file_path):
         with open(csv_file_path, 'rb') as csv_file:
            reader = csv.reader(csv_file, delimiter=',', quotechar='|')
            for row in reader:
              old_value = row[0]
              value = row[1]
              document_set_id = row[2]
              form_field_id = row[3]
              try:
                document_set = DocumentSet.objects.get(pk=int(document_set_id))
                form_field = DocumentSetFormField.objects.get(pk=int(form_field_id))

                canon = CanonicalFieldEntryLabel\
                        .objects.get(value=old_value,form_field=form_field, document_set=document_set)
                canon.value = value
                canon.save()

                print >>self.stdout,"Successfully updated canon %s" % value

              except CanonicalFieldEntryLabel.DoesNotExist:
                if not CanonicalFieldEntryLabel.objects.filter(value=value):
                  canon = CanonicalFieldEntryLabel(value=value, form_field=form_field, document_set=document_set)
                  canon.save()

                  print >>self.stdout,"Successfully created canon %s" % value
              except DocumentSet.DoesNotExist:
                raise CommandError('Document Set "%s" does not exist' % document_set_id)
              except DocumentSetFormField.DoesNotExist:
                raise CommandError('Form Field "%s" does not exist' % form_field_id)
コード例 #2
0
ファイル: normalize.py プロジェクト: JoeGermuska/crowdata
    def update_entries(self, csv_file_path):
         with open(csv_file_path, 'rb') as csv_file:
            reader = csv.reader(csv_file, delimiter=';',quotechar='|')
            for row in reader:
              entry_id = row[0]
              field_id = row[1]
              canonical_label_id = row[4]
              canonical_label_value = row[5]
              try:
                entry = DocumentSetFieldEntry.objects.get(pk=int(entry_id))
                if canonical_label_id == '':
                  # crear canonico y asociarlo
                  canon = CanonicalFieldEntryLabel(value  = canonical_label_value, document_set=entry.entry.document.document_set, form_field=DocumentSetFormField.objects.get(pk=field_id))
                  canon.save()
                  entry.canonical_label = canon
                  entry.save_without_setting_canon()
                else:
                  canon = CanonicalFieldEntryLabel.objects.get(pk=int(canonical_label_id))
                  canon.value = canonical_label_value
                  canon.save()
                  if entry.canonical_label_id != canonical_label_id:
                    # buscar canonico
                    entry.canonical_label = canon
                    entry.save_without_setting_canon()

                print >>self.stdout,"Successfully updated entry %s with canon value %s." % (entry_id, canonical_label_value)
              except DocumentSetFieldEntry.DoesNotExist:
                print >>self.stdout,"There is no entry with the id %s" % entry_id
              except CanonicalFieldEntryLabel.DoesNotExist:
                print >>self.stdout,"There is no canon with the id %s" % canonical_label_id
コード例 #3
0
    def import_canons(self, csv_file_path):
        with open(csv_file_path, 'rb') as csv_file:
            reader = csv.reader(csv_file, delimiter=',', quotechar='|')
            for row in reader:
                old_value = row[0]
                value = row[1]
                document_set_id = row[2]
                form_field_id = row[3]
                try:
                    document_set = DocumentSet.objects.get(
                        pk=int(document_set_id))
                    form_field = DocumentSetFormField.objects.get(
                        pk=int(form_field_id))

                    canon = CanonicalFieldEntryLabel\
                            .objects.get(value=old_value,form_field=form_field, document_set=document_set)
                    canon.value = value
                    canon.save()

                    print >> self.stdout, "Successfully updated canon %s" % value

                except CanonicalFieldEntryLabel.DoesNotExist:
                    if not CanonicalFieldEntryLabel.objects.filter(
                            value=value):
                        canon = CanonicalFieldEntryLabel(
                            value=value,
                            form_field=form_field,
                            document_set=document_set)
                        canon.save()

                        print >> self.stdout, "Successfully created canon %s" % value
                except DocumentSet.DoesNotExist:
                    raise CommandError('Document Set "%s" does not exist' %
                                       document_set_id)
                except DocumentSetFormField.DoesNotExist:
                    raise CommandError('Form Field "%s" does not exist' %
                                       form_field_id)
コード例 #4
0
    def update_entries(self, csv_file_path):
        with open(csv_file_path, 'rb') as csv_file:
            reader = csv.reader(csv_file, delimiter=';', quotechar='|')
            for row in reader:
                entry_id = row[0]
                field_id = row[1]
                canonical_label_id = row[4]
                canonical_label_value = row[5]
                try:
                    entry = DocumentSetFieldEntry.objects.get(pk=int(entry_id))
                    if canonical_label_id == '':
                        # crear canonico y asociarlo
                        canon = CanonicalFieldEntryLabel(
                            value=canonical_label_value,
                            document_set=entry.entry.document.document_set,
                            form_field=DocumentSetFormField.objects.get(
                                pk=field_id))
                        canon.save()
                        entry.canonical_label = canon
                        entry.save_without_setting_canon()
                    else:
                        canon = CanonicalFieldEntryLabel.objects.get(
                            pk=int(canonical_label_id))
                        canon.value = canonical_label_value
                        canon.save()
                        if entry.canonical_label_id != canonical_label_id:
                            # buscar canonico
                            entry.canonical_label = canon
                            entry.save_without_setting_canon()

                    print >> self.stdout, "Successfully updated entry %s with canon value %s." % (
                        entry_id, canonical_label_value)
                except DocumentSetFieldEntry.DoesNotExist:
                    print >> self.stdout, "There is no entry with the id %s" % entry_id
                except CanonicalFieldEntryLabel.DoesNotExist:
                    print >> self.stdout, "There is no canon with the id %s" % canonical_label_id