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


Python Place.find方法代码示例

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


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

示例1: add_polling_centers

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def add_polling_centers(state, filename):
    d = {}
    with db.transaction():
        for ac_code, px_code, pb_code, name in read_csv(filename):
            print "adding polling center", state.id, ac_code, px_code
            if (ac_code, px_code) not in d:
                key = "{0}/{1}/{2}".format(state.key, ac_code, px_code)                    
                if not db.select("places", where="type='PX' AND key=$key", vars=locals()):
                    pb_key = "{0}/{1}/{2}".format(state.key, ac_code, pb_code)
                    pb = Place.find(pb_key)
                    lazy_insert("places", key=key, name=name, type="PX", 
                        code=key.split("/")[-1],
                        state_id=state.id,
                        region_id=pb.region_id,
                        pc_id=pb.pc_id,
                        ac_id=pb.ac_id,
                        ward_id=pb.ward_id)
                d[ac_code, px_code] = 1
        commit_lazy_inserts()

    with db.transaction():
        for ac_code, px_code, pb_code, name in read_csv(filename):
            key = "{0}/{1}/{2}".format(state.key, ac_code, px_code)                    
            px = Place.find(key)
            pb_key = "{0}/{1}/{2}".format(state.key, ac_code, pb_code)
            db.update("places", px_id=px.id, where="key=$pb_key", vars=locals())
开发者ID:anandology,项目名称:voternet,代码行数:28,代码来源:loaddata.py

示例2: POST

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
    def POST(self, place):
        data = json.loads(web.data())['data']

        for row in data:
            code = place.key + "/" + row['code']
            pb = Place.find(code)

            if row['ward'] and row['ward'].strip():
                # Extract te group code from its name
                key = place.key + "/" + row['ward'].split("-")[0].strip()
                ward = Place.find(key)
                if pb.ward_id != ward.id:
                    pb.set_ward(ward)
            else:
                pb.set_ward(None)

            if row['px'] and row['px'].strip():
                # Extract te group code from its name
                key = place.key + "/" + row['px'].split("-")[0].strip()
                px = Place.find(key)
                if pb.px_id != px.id:
                    pb.set_px(px)
            else:
                pb.set_px(None)

        web.header("content-type", "application/json")
        return '{"result": "ok"}'
开发者ID:anandology,项目名称:voternet,代码行数:29,代码来源:webapp.py

示例3: POST_update_pcs

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
    def POST_update_pcs(self, place, data):
        for row in data:
            key = place.key + "/" + row['code']
            pc = Place.find(key)

            if row['region'] and row['region'].strip():
                # Extract te group code from its name
                key = place.key + "/" + row['region'].split("-")[0].strip()
                region = Place.find(key)
                if pc.region_id != region.id:
                    pc.set_parent("REGION", region)
            else:
                pc.set_parent("REGION", None)
        web.header("content-type", "application/json")
        return '{"result": "ok"}'
开发者ID:anandology,项目名称:voternet,代码行数:17,代码来源:webapp.py

示例4: GET

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
    def GET(self, key):
        place = Place.find(key)
        if not place:
            raise web.notfound()

        booths = place.get_all_polling_booths()
        from collections import defaultdict
        d = defaultdict(list)
        pxd = {}
        for booth in booths:
            px = booth.get_parent("PX")
            px_code = px.key.split("/")[-1]
            d[px_code].append(booth)
            pxd[px_code] = px

        def get_row(px_code):
            booths = d[px_code]
            px = pxd[px_code]
            ward = px.get_parent("WARD")
            ward_name = ward and ward.name or "-"
            return [place.code, place.name, px_code, ",".join(b.code for b in booths), px.name, ward_name]

        data = [get_row(px_code) for px_code in sorted(d)]
        web.header("content-type", "text/plain")
        return "\n".join("\t".join(row) for row in data)
开发者ID:anandology,项目名称:voternet,代码行数:27,代码来源:webapp.py

示例5: main

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def main():
    import sys
    import webapp
    webapp.check_config()

    global db 
    db = get_db()

    if "--add-admin" in sys.argv:
        index = sys.argv.index("--add-admin")
        email = sys.argv[index+1]
        state = Place.find(key=webapp.get_state())

        # Hack to fix the error at account.get_current_user() when adding volunteer
        web.ctx.current_user = None

        state.add_volunteer("Fix Your Name", email, "0000000000", role="admin")
        return
    if "--polling-centers" in sys.argv:
        index = sys.argv.index("--polling-centers")
        state_code = sys.argv[index+1]
        filename = sys.argv[index+2]
        state = Place.find(state_code)
        print "add_polling_centers", state, filename
        add_polling_centers(state, filename)
        return
    if "--wards" in sys.argv:
        index = sys.argv.index("--wards")
        state_code = sys.argv[index+1]
        filename = sys.argv[index+2]
        state = Place.find(state_code)
        print "add_wards", state, filename
        add_wards(state, filename)
        return


    
    dir = sys.argv[1]
    code = sys.argv[2]
    name = sys.argv[3]

    state = add_state(code, name)

    add_pcs(state, dir)
    add_acs(state, dir)
    #add_wards(state, dir)
    add_polling_booths(state, dir)
开发者ID:anandology,项目名称:voternet,代码行数:49,代码来源:loaddata.py

示例6: autoadd_pb_agents

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def autoadd_pb_agents(place_key):
    """Finds all volunteers in the place and adds a new role as polling booth agent.
    """
    place = Place.find(place_key)
    if not place:
        raise ValueError("Invalid place {0}".format(place_key))

    _add_pb_agents(place, place.get_all_volunteers())
开发者ID:anandology,项目名称:voternet,代码行数:10,代码来源:actions.py

示例7: debug

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def debug(place_key):
    place = Place.find(place_key)
    if not place:
        raise ValueError("Invalid place {0}".format(place_key))    

    agents = [a for a in place.get_pb_agents() if a.voterid if a.email]
    a = agents[0]
    utils.sendmail_voterid_added(a)
开发者ID:anandology,项目名称:voternet,代码行数:10,代码来源:actions.py

示例8: main

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def main():
    if not db.select("places", where="type='STATE' AND code='karnataka'"):
        db.insert("places", name="Karnataka", type="STATE", code="karnataka", parent_id=None)
    state = Place.find("karnataka")
    #add_places(state)
    add_pcs(state)
    add_acs(state)
    add_wards(state)
    add_polling_booths(state)
开发者ID:anandology,项目名称:voternet,代码行数:11,代码来源:initdb.py

示例9: email_voterid_added

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def email_voterid_added(place_key):
    """Email all volunteers that their voter ID registration is complete.
    """
    place = Place.find(place_key)
    if not place:
        raise ValueError("Invalid place {0}".format(place_key))

    agents = [a for a in place.get_pb_agents() if a.email and a.get_voterid_info()]    
    conn = utils.get_smtp_conn()    
    for a in agents:
        utils.sendmail_voterid_added(a, conn=conn)
开发者ID:anandology,项目名称:voternet,代码行数:13,代码来源:actions.py

示例10: update_voterinfo

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def update_voterinfo(place_key):
    """Updtes voter info of all volunteers with voterids whos voter info is not updated yet.
    """
    place = Place.find(place_key)
    if not place:
        raise ValueError("Invalid place {0}".format(place_key))    
    for a in place.get_all_volunteers("pb_agent"):
        a.populate_voterid_info()
        info = a.get_voterid_info()
        if info and info.pb_id != a.place_id:
            a.update(place_id=info.pb_id)
开发者ID:anandology,项目名称:voternet,代码行数:13,代码来源:actions.py

示例11: add_pb_agents

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def add_pb_agents(place_key, tsv_file):
    """Takes a tsv file containing name, phone, email fields and adds them as PB agents.
    """
    place = Place.find(place_key)
    if not place:
        raise ValueError("Invalid place {0}".format(place_key))

    def parse_line(line):
        name, phone, email = line.strip("\n").split("\t")
        return web.storage(name=name, phone=phone, email=email, voterid=None)

    agents = [parse_line(line) for line in open(tsv_file) if line.strip()]
    _add_pb_agents(place, agents)
开发者ID:anandology,项目名称:voternet,代码行数:15,代码来源:actions.py

示例12: email_fill_voterid

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def email_fill_voterid(place_key):
    """Reminds all PB volunteers who have not filled their voter ID
    in the specified place to fill it.

    place can be a PC/AC or a WARD.
    """
    place = Place.find(place_key)
    if not place:
        raise ValueError("Invalid place {0}".format(place_key))

    agents = [a for a in place.get_pb_agents() if a.email and not a.voterid]

    pool = ThreadPool(20)
    def sendmail(a):
        utils.sendmail_voterid_pending(a)
    pool.map(sendmail, agents)
开发者ID:anandology,项目名称:voternet,代码行数:18,代码来源:actions.py

示例13: g

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
    def g(self, code, *args):
        place = Place.find(key=code)
        if not place:
            raise web.notfound()

        if types is not None and place.type not in types:
            raise web.notfound()

        user = account.get_current_user()

        if not user or not place.viewable_by(user):
            raise web.ok(render.access_restricted())

        if roles:
            if not user or not place.writable_by(user, roles=roles):
                return render.permission_denied(user=user)
        return f(self, place, *args)
开发者ID:anandology,项目名称:voternet,代码行数:19,代码来源:webapp.py

示例14: add_invites

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
def add_invites(place_key, filename, batch):
    from webapp import import_people

    place = Place.find(place_key)
    if not place:
        raise ValueError("Invalid place {0}".format(place_key))

    rows = [line.strip("\n").split("\t") for line in open(filename) if line.strip()]
    re_badchars = re.compile("[^A-Za-z0-9 \.-]+")
    count = 0
    with get_db().transaction():
        for row in rows:
            name, phone, email = row
            name = re_badchars.sub("", name).strip()
            d = web.storage(name=name, phone=phone, email=email, place=None, role=None)
            if import_people().add_volunteer(d, place, batch=batch, as_invite=True):
                count += 1
    logger.info("imported %s people", count)
开发者ID:anandology,项目名称:voternet,代码行数:20,代码来源:actions.py

示例15: add_volunteer

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import find [as 别名]
    def add_volunteer(self, row, ac, batch, as_invite):
        if not row.name:
            return

        if row.place:
            key = ac.key + "/" + row.place.split("-")[0].strip()
            place = Place.find(key)
            if not place:
                return
        else:
            place = ac
        if row.email and place.find_volunteer(email=row.email, phone=None, role=row.role):
            logger.warn("Already found a vol with same email and role. Ignoring this %s", row)
            return
        if row.phone and place.find_volunteer(email=None, phone=row.phone, role=row.role):
            logger.warn("Already found a vol with same phone number and role. Ignoring this %s", row)
            return
        if not row.email and not row.phone:
            logger.warn("No email/phone number specified. Ignoring this %s", row)
            return

        if as_invite:
            if not row.email:
                logger.warn("Can't add invite as no email provided. Ignoring this %s", row)
                return
            if Invite.find_by_email(row.email):
                logger.warn("Already found an invite with the same email. Ignoring this %s", row)
                return

            place.add_invite(       
                name=row.name, 
                phone=row.phone, 
                email=row.email, 
                batch=batch)
        else:
            place.add_volunteer(
                name=row.name, 
                phone=row.phone, 
                email=row.email, 
                voterid=row.voterid, 
                role=row.role,
                notes=batch)
        return True
开发者ID:anandology,项目名称:voternet,代码行数:45,代码来源:webapp.py


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