Ejemplo n.º 1
0
def vcf(ctx, vcf_file):
    """Import VCF Card"""

    config = ctx.obj['config']
    directory = Directory(config.path('data:path', 'directory.json'))

    vcf = VCFParser(photo_dir=config.path('data:path', 'photos'))
    data = vcf.parse(vcf_file)

    print("----- %s - %s -----" % (data['last_name'], data['address']))

    family = directory.get(data['last_name'])
    family = Prompt.choose_from_list(family, "Which Family")
    if family:
        person = family.get(data['name'])
        if person:
            print("%s already exists." % (data['name']))
        else:
            new_person = Person(**data)
            family.add(new_person)
            directory.save()
    else:
        new_family = Family(name=data['last_name'],
                            address=data['address'],
                            city=data['city'],
                            state=data['state'],
                            zip=data['zip'],
                            members=[data])
        directory.add(new_family)
        directory.save()
Ejemplo n.º 2
0
def edit(ctx, name):
    """ Edit a Family's Data """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))
    family = directory.get(name)

    family = Prompt.choose_from_list(family, "Which Family? ")

    need_to_save = False
    fam_data = family.to_json()
    fields = sorted(fam_data.keys())
    for name in fields:
        if name in ('id', 'name', 'members'):
            continue

        # TODO: what if notes already exist?
        if name == 'notes':
            new_value = Prompt.notes()
        else:
            old_value = fam_data[name]
            new_value = Prompt.input("%s (%s): " % (name, old_value))

        if new_value:
            need_to_save = True
            setattr(family, name, new_value)

    if need_to_save:
        directory.save()
Ejemplo n.º 3
0
def add_member(ctx, name):
    """ Add a Family Member """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))

    family = directory.get(name)
    __add_members(family)

    directory.save()
Ejemplo n.º 4
0
def view(ctx, name):
    """ View a Family """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))
    family = directory.get(name)

    family = Prompt.choose_from_list(family, "Which Family? ")

    print(repr(family))
Ejemplo n.º 5
0
def delete(ctx, name):
    """ Delete a Family from the Directory """
    directory = Directory(ctx.obj['config'].path('data:path',
                                                 'directory.json'))
    family = directory.get(name)

    family = Prompt.choose_from_list(family, "Which Family? ")

    choice = Prompt.input("Confirm Delete: %s - %s (yes|no)? " %
                          (family.name, family.address))
    if choice == 'yes':
        directory.delete(family)
        directory.save()
    else:
        print("Not Deleting Family: %s - %s" % (family.name, family.address))