Ejemplo n.º 1
0
def read_vampire(v, user, date_hint):
    vampire = {}
    previous_entry = None

    current_vampire = create_base_vampire(v.attrib, user, date_hint=date_hint)

    for tl in v.findall('traitlist'):
        read_traitlist_properties(tl.attrib, current_vampire)
        order = 0
        for t in tl.findall('trait'):
            order += 1
            read_trait(t.attrib, tl.attrib, current_vampire, order)

    exp = v.find('experience')
    for ee in exp.findall('entry'):
        previous_entry = read_experience_entry(ee.attrib, current_vampire, previous_entry, date_hint=date_hint)

    biography = v.find('biography')
    if biography is not None:
        current_vampire.biography = unescape(biography.text).strip()

    notes = v.find('notes')
    if notes is not None:
        current_vampire.notes = unescape(notes.text).strip()

    current_vampire.update_experience_total()
    current_vampire.save()
    current_vampire.add_default_traitlist_properties()
    return current_vampire
Ejemplo n.º 2
0
def handle_sheet_upload(uploaded_file, user):
    creatures = base_read(uploaded_file)

    class BinUploadResponse(object):
        pass

    ret = BinUploadResponse()
    ret.vampires = {}
    for c in creatures:
        # Stuck on vampies for now
        current_vampire = create_base_vampire(c["attrs"], user)
        previous_entry = None
        for ee in c["experience_entries"]:
            previous_entry = read_experience_entry(ee, current_vampire, previous_entry)

        for tl in c["trait_lists"]:
            traits = tl["list"]
            del tl["list"]
            read_traitlist_properties(tl, current_vampire)
            for i, t in enumerate(traits):
                read_trait(t, tl, current_vampire, i)

        current_vampire.biography = c["biography"]
        current_vampire.notes = c["notes"]
        current_vampire.update_experience_total()
        current_vampire.last_modified = datetime.datetime.now()
        current_vampire.save()
        ret.vampires[current_vampire.name] = current_vampire
    return ret