예제 #1
0
def create_source(record, publisher):
    source = None
    source_created = False
    isnum = ''
    title = ''
    if record.isnumber:
        isnum = is_number_normalize(record.isnumber)

    if record.source:
        if record.source.isupper():
            title = record.source.title()
        else:
            title = record.source

    if record.istype:
        source, source_created = Source.objects.get_or_create(
            is_number=isnum,
            defaults={
                'name': title,
                'publication_type': record.publication_type,
                'is_type': record.istype
            })

    elif record.source:
        if record.isnumber:
            source, source_created = Source.objects.get_or_create(
                is_number=isnum,
                defaults={
                    'name': title,
                    'publication_type': record.publication_type
                })
        else:
            try:
                source, source_created = Source.objects.get_or_create(
                    name=title,
                    defaults={'publication_type': record.publication_type})
            except MultipleObjectsReturned:
                source = Source.objects.filter(name=title)[0]

    if source:
        modified = False
        if record.source and not source.name:
            source.name = title
            modified = True
        if record.publication_type and not source.publication_type:
            source.publication_type = record.publication_type
            modified = True
        if record.istype and not source.is_type:
            source.is_type = record.istype
            modified = True
        if record.esnumber and not source.es_number:
            source.es_number = is_number_normalize(record.esnumber)
            modified = True
        if modified:
            source.save()
    return source
예제 #2
0
def create_source(record, publisher):
    source = None
    source_created = False
    isnum = ''
    title = ''
    if record.isnumber:
        isnum = is_number_normalize(record.isnumber)
        
    if record.source:
        if record.source.isupper():
            title = record.source.title()
        else:
            title = record.source
        

    if record.istype:
        source, source_created = Source.objects.get_or_create(is_number=isnum,
                                                defaults={'name':title,
                                                          'publication_type':record.publication_type,
                                                          'is_type':record.istype})

    elif record.source:
        if record.isnumber:
            source, source_created = Source.objects.get_or_create(is_number=isnum,
                                                    defaults={'name':title,
                                                              'publication_type':record.publication_type})
        else:
            try:
                source, source_created = Source.objects.get_or_create(name=title,
                                                                      defaults={'publication_type':record.publication_type})
            except MultipleObjectsReturned:
                source = Source.objects.filter(name=title)[0]
            

    if source:
        modified = False
        if record.source and not source.name:
            source.name = title
            modified = True
        if record.publication_type and not source.publication_type:
            source.publication_type = record.publication_type
            modified = True
        if record.istype and not source.is_type:
            source.is_type = record.istype
            modified = True
        if record.esnumber and not source.es_number:
            source.es_number = is_number_normalize(record.esnumber)
            modified = True
        if modified:
            source.save()
    return source
예제 #3
0
 def save(self, force_insert=False, force_update=False):
     if self.is_number:
         self.is_number = is_number_normalize(self.is_number)
     if self.es_number:
         self.es_number = is_number_normalize(self.es_number)
     super(Source, self).save(force_insert, force_update)
예제 #4
0
 def save(self, force_insert=False, force_update=False):
     if self.is_number:
         self.is_number = is_number_normalize(self.is_number)
     if self.es_number:
         self.es_number = is_number_normalize(self.es_number)
     super(Source, self).save(force_insert, force_update)