def start_import(params):
    ctx = ImportContext()

    fileobj = params.get('file', None)
    if fileobj is None or not fileobj.filename:
        return ctx.set_error('No file supplied')

    collname = unicode(params.get('collection', u''))
    if not collname:
        return ctx.set_error('No collection specified') 

    try:
        coll = Collection.objects.get(collname)
    except KeyError:
        return ctx.set_error('Collection specified not found') 

    ctx.setup(fileobj=fileobj, collname=collname,
              idprefix=collname.lower().replace(' ', '_') + '_',
             )

    # FIXME - do this in a background thread.
    do_import(ctx)
    return ctx
Esempio n. 2
0
def start_import(params):
    ctx = ImportContext()

    fileobj = params.get('file', None)
    if fileobj is None or not fileobj.filename:
        return ctx.set_error('No file supplied')

    title = unicode(params.get('collection', u''))
    if not title:
        return ctx.set_error('No collection specified') 

    colls = Collection.find_by_title(title)
    if len(colls) == 0:
        return ctx.set_error('Collection specified not found') 
    if len(colls) > 1:
        return ctx.set_error('Collection name specified maps to multiple collections') 
    coll = colls[0]

    type_mapping = {
        u'title': u'title',
        u'note': u'text',
        u'clip': u'text',
        u'caption': u'text',
        u'text': u'text',
        u'medium': u'tag',
        u'keywords': u'tag',
        u'date': u'date',
        u'img': u'file',
        u'imgthumb': u'file',
        u'musref': u'file',
        u'film': u'file',
        u'sound': u'file',
        u'collection': u'group',
        u'collection/person': u'tag',
        u'collection/date': u'date',
        u'collection/form': u'date',
        u'collection/location': u'location',
        u'collection/ethnicgroup': u'tag',
        u'collection/note': u'tag',
        u'collection/refnum': u'tag',
        u'production': u'group',
        u'production/person': u'tag',
        u'production/date': u'date',
        u'production/location': u'location',
        u'production/form': u'tag',
        u'production/note': u'text',
        u'production/refnum': u'tag',
        u'production/ethnicgroup': u'tag',
        u'acquirer': u'group',
        u'acquirer/date': u'date',
        u'acquirer/person': u'tag',
        u'acquirer/form': u'tag',
        u'acquirer/refnum': u'tag',
        u'acquirer/note': u'tag',
        u'size': u'number',
        u'person': u'tag',
        u'ethnicgroup': u'tag',
        u'location': u'location',

        u'refnext': u'refnext',
        u'refprev': u'refprev',
        u'seealso': u'seealso',
    }

    # HACK!
    known_locations = {}
#    for line in open('locations.txt').readlines():
#        line = line.strip()
#        line = line.split(':', 1)
#        if len(line) < 2: continue
#        if not line[1]:
#            continue
#        known_locations[line[0].strip()] = line[1].strip()
#
#    for k in sorted(known_locations):
#        print k, known_locations[k]

    ctx.setup(fileobj=fileobj, collid=coll.id,
              type_mapping=type_mapping, known_locations=known_locations)

    # FIXME - do this in a background thread.
    do_import(ctx)
    return ctx