Ejemplo n.º 1
0
def familytree_primitives_data():
    filter_surnames = set(
        x for x in request.values.get('surname', '').lower().split(',') if x)

    # only show given individual
    single_person = request.values.get('single_person')
    if single_person:
        people = [Person.get(single_person)]
    else:
        people = sorted(Person.find(), key=lambda p: p.group_name)

    relatives_of = request.values.get('relatives_of')
    if relatives_of:
        central_person = Person.get(relatives_of)
        people = central_person.related_people

    # only find ancestors of given person
    ancestors, descendants = None, None
    ancestors_of = request.values.get('ancestors_of')
    if ancestors_of:
        central_person = Person.get(ancestors_of)
        ancestors = central_person.find_ancestors()

    descendants_of = request.values.get('descendants_of')
    if descendants_of:
        central_person = Person.get(descendants_of)
        descendants = central_person.find_descendants()

    if ancestors_of or descendants_of:
        people = set(list(ancestors or [])) | set(list(descendants or []))

    def _prepare_item(person):
        names_lowercase = (n.lower() for n in person.group_names)
        if filter_surnames:
            intersects = filter_surnames & set(names_lowercase)
            if not intersects:
                return

        # ethical reasons
        if person.death.year:
            tmpl = '{born} — {dead}'
        else:
            tmpl = '{born}'
        description = tmpl.format(born=person.birth.year_formatted or '?',
                                  dead=person.death.year_formatted or '?')
        return {
            'id': person.id,
            'title': person.name,
            'parents': [p.id for p in person.get_parents()],
            'spouses': [p.id for p in person.get_partners()],
            'description': description,
            'gender': person.gender,
        }

    prepared = (_prepare_item(p) for p in people)
    filtered = (p for p in prepared if p)
    return json.dumps(list(filtered))
Ejemplo n.º 2
0
    def GET(self, place, id):
        person = Person.find(place_id=place.id, id=id)
        if not person:
            raise web.notfound()

        user = account.get_current_user()
        if user.role not in ['admin', 'coordinator'] and person.id != int(id):
            return render.access_restricted()
        form = forms.AddPeopleForm(person)
        return render.person(person, form, show_role=self.can_change_role(user))
Ejemplo n.º 3
0
def familytree_primitives_data():
    filter_surnames = set(x for x in request.values.get('surname', '').lower().split(',') if x)

    # only show given individual
    single_person = request.values.get('single_person')
    if single_person:
        people = [Person.get(single_person)]
    else:
        people = sorted(Person.find(), key=lambda p: p.group_name)

    relatives_of = request.values.get('relatives_of')
    if relatives_of:
        central_person = Person.get(relatives_of)
        people = central_person.related_people

    # only find ancestors of given person
    ancestors, descendants = None, None
    ancestors_of = request.values.get('ancestors_of')
    if ancestors_of:
        central_person = Person.get(ancestors_of)
        ancestors = central_person.find_ancestors()

    descendants_of = request.values.get('descendants_of')
    if descendants_of:
        central_person = Person.get(descendants_of)
        descendants = central_person.find_descendants()

    if ancestors_of or descendants_of:
        people = set(list(ancestors or [])) | set(list(descendants or []))

    def _prepare_item(person):
        names_lowercase = (n.lower() for n in person.group_names)
        if filter_surnames:
            intersects = filter_surnames & set(names_lowercase)
            if not intersects:
                return

        # ethical reasons
        if person.death.year:
            tmpl = '{born} — {dead}'
        else:
            tmpl = '{born}'
        description = tmpl.format(born=person.birth.year_formatted or '?',
                                  dead=person.death.year_formatted or '?')
        return {
            'id': person.id,
            'title': person.name,
            'parents': [p.id for p in person.get_parents()],
            'spouses': [p.id for p in person.get_partners()],
            'description': description,
            'gender': person.gender,
        }
    prepared = (_prepare_item(p) for p in people)
    filtered = (p for p in prepared if p)
    return json.dumps(list(filtered))
Ejemplo n.º 4
0
 def POST(self):
     i = web.input(email="")
     person = Person.find(email=i.email)
     if person:
         token = person.generate_reset_token()
         msg = render_template("email_password_reset", token=token)
         utils.send_email(to_addr=person.email, message=msg)
         #TODO: send email
         return render.reset_password(email=i.email, success=True)
     else:
         return render.reset_password(email=i.email, error=True)
Ejemplo n.º 5
0
def orgchart_data():
    def _prep_row(person):
        parent_families = list(person.get_parent_families())
        if parent_families:
            # XXX ideally we should link to all members of all families
            parent = parent_families[0].father or parent_families[0].mother
            parent_id = parent.id
        else:
            parent_id = None
        # TODO use url_for
        name_format = '<a name="id{id}"></a><a href="/person/{id}">{name}</a><br><small>{birth}<br>{death}</small>{spouses}'
        tooltip_format = '{birth}'
        birth_str = '☀{}'.format(person.birth) if person.birth else ''
        death_str = '✝{}'.format(person.death) if person.death else ''

        def _compress_life_str(s):
            return (s.replace('estimated ',
                              'cca').replace('calculated ', 'calc').replace(
                                  'about ',
                                  '~').replace('before ',
                                               '<').replace('after ', '>'))

        birth_str = _compress_life_str(birth_str)
        death_str = _compress_life_str(death_str)

        spouses = []
        for f in person.get_families():
            for x in (f.father, f.mother):
                if x and x.id != person.id:
                    spouses.append(x)
        if spouses:
            # TODO use url_for
            spouses_str = ', '.join(
                '⚭ <a href="/person/{0.id}">{0.name}</a><a href="#id{0.id}">#</a>'
                .format(s) for s in spouses)
        else:
            spouses_str = ''

        formatted_name = name_format.format(id=person.id,
                                            name=person.name,
                                            birth=birth_str,
                                            death=death_str,
                                            spouses=spouses_str)
        tooltip = tooltip_format.format(birth=person.birth)
        return [
            {
                'v': person.id,
                'f': formatted_name,
            },
            parent_id,
            tooltip,
        ]

    return json.dumps([_prep_row(p) for p in Person.find()])
Ejemplo n.º 6
0
def orgchart_data():
    def _prep_row(person):
        parent_families = list(person.get_parent_families())
        if parent_families:
            # XXX ideally we should link to all members of all families
            parent = parent_families[0].father or parent_families[0].mother
            parent_id = parent.id
        else:
            parent_id = None
        # TODO use url_for
        name_format = '<a name="id{id}"></a><a href="/person/{id}">{name}</a><br><small>{birth}<br>{death}</small>{spouses}'
        tooltip_format = '{birth}'
        birth_str = '☀{}'.format(person.birth) if person.birth else ''
        death_str = '✝{}'.format(person.death) if person.death else ''
        def _compress_life_str(s):
            return (s.replace('estimated ', 'cca')
                     .replace('calculated ', 'calc')
                     .replace('about ', '~')
                     .replace('before ', '<')
                     .replace('after ', '>'))
        birth_str = _compress_life_str(birth_str)
        death_str = _compress_life_str(death_str)

        spouses = []
        for f in person.get_families():
            for x in (f.father, f.mother):
                if x and x.id != person.id:
                    spouses.append(x)
        if spouses:
            # TODO use url_for
            spouses_str = ', '.join(
                '⚭ <a href="/person/{0.id}">{0.name}</a><a href="#id{0.id}">#</a>'.format(s) for s in spouses)
        else:
            spouses_str = ''

        formatted_name = name_format.format(
            id=person.id,
            name=person.name,
            birth=birth_str,
            death=death_str,
            spouses=spouses_str)
        tooltip = tooltip_format.format(birth=person.birth)
        return [
            {
                'v': person.id,
                'f': formatted_name,
            },
            parent_id,
            tooltip,
        ]
    return json.dumps([_prep_row(p) for p in Person.find()])
Ejemplo n.º 7
0
    def POST(self, place, id):
        person = Person.find(place_id=place.id, id=id)
        if not person:
            raise web.notfound()

        user = account.get_current_user()
        if user.role not in ['admin', 'coordinator'] and person.id != int(id):
            return render.access_restricted()

        i = web.input()
        if i.action == "save":
            d = dict(name=i.name, email=i.email, phone=i.phone, voterid=i.voterid)
            if self.can_change_role(user):
                d['role'] = i.role
            person.update(d)
            if person.role == 'pb_agent':
                person.populate_voterid_info()
                if person.get_voterid_info():
                    utils.sendmail_voterid_added(person)
                else:
                    utils.sendmail_voterid_pending(person)
            flash.add_flash_message("success", "Thanks for updating!")            
        elif i.action == "delete" and self.can_change_role(user): # don't allow self deletes
            person.delete()
            flash.add_flash_message("success", "Delete the volunteer successfully.")            
        elif i.action == "update-place":
            next = i.get("next")
            new_place = Place.find(i.place)
            if not new_place:
                flash.add_flash_message("warning", "Unable to update the location of the volunteer.")
                raise web.seeother(next or place.url)
            elif not new_place.writable_by(user):
                return render.access_restricted()
            else:
                person.update(place_id=new_place.id)
                flash.add_flash_message("success", "Assigned {0} to {1}".format(person.name, new_place.name))
                raise web.seeother(next or new_place.url)
        elif i.action in ("make-ward-coordinator", 'make-ac-coordinator', 'make-pc-coordinator'):
            type = i.action.split("-")[1]
            parent = place.get_parent(type)
            if not parent or not parent.writable_by(user):
                return render.access_restricted()
            parent.add_volunteer(name=person.name, email=person.email, phone=person.phone, role='coordinator')
            raise web.seeother(parent.url)
        raise web.seeother(place.url)


        raise web.seeother(place.url)
Ejemplo n.º 8
0
 def person_name_group_list(cls):
     "Runs once, caches the response (already in JSON)"
     before = time()
     seen_group_names = {}
     for p in Person.find():
         group_name = p.group_name
         data = seen_group_names.setdefault(group_name, {})
         #data['count'] = data.get('count', 0) + 1
         data.setdefault('person_ids', []).append(p.id)
     group_names = [
         dict({'name': n}, **seen_group_names[n])
         for n in sorted(seen_group_names)]
     resp = jsonify_with_cors(group_names)
     after = time()
     print('Generated JSON for surname_list in', (after - before), 'sec')
     return resp
Ejemplo n.º 9
0
 def person_name_group_list(cls):
     "Runs once, caches the response (already in JSON)"
     before = time()
     seen_group_names = {}
     for p in Person.find():
         group_name = p.group_name
         data = seen_group_names.setdefault(group_name, {})
         #data['count'] = data.get('count', 0) + 1
         data.setdefault('person_ids', []).append(p.id)
     group_names = [
         dict({'name': n}, **seen_group_names[n])
         for n in sorted(seen_group_names)]
     resp = jsonify_with_cors(group_names)
     after = time()
     print('Generated JSON for surname_list in', (after - before), 'sec')
     return resp
Ejemplo n.º 10
0
def familytreejs_json():
    people = sorted(Person.find(), key=lambda p: p.group_name)
    def _prepare_item(person):
        print(person.group_name, person.name)
        url = url_for('person_detail', obj_id=person.id)

        # XXX orphans should be handled on frontend
        if not list(person.get_parent_families()) and not list(person.get_families()):
            return

        data = {
            'name': person.name,
            'parents': [p.id for p in person.get_parents()],
            'blurb': '{}—{}'.format(person.birth or '?', person.death or '?'),
        }

        return person.id, data

    pairs = map(_prepare_item, people)
    data = OrderedDict(p for p in pairs if p)
    return json.dumps(data)    # {john': {'name': 'John Doe'},}
Ejemplo n.º 11
0
def familytreejs_json():
    people = sorted(Person.find(), key=lambda p: p.group_name)

    def _prepare_item(person):
        print(person.group_name, person.name)
        url = url_for('person_detail', obj_id=person.id)

        # XXX orphans should be handled on frontend
        if not list(person.get_parent_families()) and not list(
                person.get_families()):
            return

        data = {
            'name': person.name,
            'parents': [p.id for p in person.get_parents()],
            'blurb': '{}—{}'.format(person.birth or '?', person.death or '?'),
        }

        return person.id, data

    pairs = map(_prepare_item, people)
    data = OrderedDict(p for p in pairs if p)
    return json.dumps(data)  # {john': {'name': 'John Doe'},}
Ejemplo n.º 12
0
def person_list():
    object_list = Person.find()
    object_list = sorted(object_list, key=lambda x: x.name)
    return render_template('person_list.html', object_list=object_list)
Ejemplo n.º 13
0
def person_list():
    object_list = Person.find()
    object_list = sorted(object_list, key=lambda x: x.name)
    return render_template('person_list.html', object_list=object_list)