当前位置: 首页>>代码示例>>Python>>正文


Python Person.find方法代码示例

本文整理汇总了Python中models.Person.find方法的典型用法代码示例。如果您正苦于以下问题:Python Person.find方法的具体用法?Python Person.find怎么用?Python Person.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Person的用法示例。


在下文中一共展示了Person.find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GET

# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import find [as 别名]
    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))
开发者ID:anandology,项目名称:voternet,代码行数:12,代码来源:webapp.py

示例2: familytree_primitives_data

# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import find [as 别名]
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))
开发者ID:daleathan,项目名称:wtfamily,代码行数:57,代码来源:web.py

示例3: POST

# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import find [as 别名]
 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)
开发者ID:anandology,项目名称:voternet,代码行数:13,代码来源:webapp.py

示例4: orgchart_data

# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import find [as 别名]
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()])
开发者ID:daleathan,项目名称:wtfamily,代码行数:53,代码来源:web.py

示例5: person_name_group_list

# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import find [as 别名]
 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
开发者ID:neithere,项目名称:wtfamily,代码行数:18,代码来源:restful.py

示例6: familytreejs_json

# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import find [as 别名]
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'},}
开发者ID:daleathan,项目名称:wtfamily,代码行数:23,代码来源:web.py

示例7: person_list

# 需要导入模块: from models import Person [as 别名]
# 或者: from models.Person import find [as 别名]
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)
开发者ID:daleathan,项目名称:wtfamily,代码行数:6,代码来源:web.py


注:本文中的models.Person.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。