예제 #1
0
 def handle(self, doab_ids, **options):
     for doab_id in doab_ids:
         doab.add_by_doab(doab_id)
예제 #2
0
 def handle(self, doab_id, **options):
     doab.add_by_doab(doab_id)
예제 #3
0
def get_edition_for_id(id_type, id_value, user=None):
    ''' the identifier is assumed to not be in database '''
    identifiers = {id_type: id_value}
    if id_type == 'http':
        # check for urls implying other identifiers
        identifiers.update(ids_from_urls(id_value))
        for new_id_type in identifiers.keys():
            idents = models.Identifier.objects.filter(
                type=new_id_type,
                value=identifiers[new_id_type],
            )
            if idents:
                ident = idents[0]
                return ident.edition if ident.edition else ident.work.preferred_edition

    #need to make a new edition
    if identifiers.has_key('goog'):
        edition = add_by_googlebooks_id(identifiers['goog'])
        if edition:

            return user_edition(edition, user)

    if identifiers.has_key('isbn'):
        edition = add_by_isbn(identifiers['isbn'])
        if edition:
            return user_edition(edition, user)

    if identifiers.has_key('doab'):
        edition = add_by_doab(identifiers['doab'])
        if edition:
            return user_edition(edition, user)

    if identifiers.has_key('oclc'):
        edition = add_by_oclc(identifiers['oclc'])
        if edition:
            return user_edition(edition, user)

    if identifiers.has_key('glue'):
        try:
            work = models.safe_get_work(identifiers['glue'])
            return work.preferred_edition
        except:
            pass

    if identifiers.has_key('http'):
        edition = add_by_webpage(identifiers['http'], user=user)
        return user_edition(edition, user)

    # return a dummy edition and identifier

    title = '!!! missing title !!!'
    work = models.Work.objects.create(title=title)
    edition = models.Edition.objects.create(title='!!! missing title !!!',
                                            work=work)
    for key in identifiers.keys():
        if key == 'glue':
            id_value = work.id
        if key not in ('http', 'goog', 'oclc', 'isbn'):
            if key in WORK_IDENTIFIERS:
                edid = str(edition.id)
                models.Identifier.objects.create(type='edid',
                                                 value=edid,
                                                 work=work,
                                                 edition=edition)
                models.Identifier.objects.create(type=key,
                                                 value=id_value,
                                                 work=work,
                                                 edition=None)
            else:
                models.Identifier.objects.create(type=key,
                                                 value=id_value,
                                                 work=work,
                                                 edition=edition)
    return user_edition(edition, user)