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


Python dao.Dao类代码示例

本文整理汇总了Python中dao.Dao的典型用法代码示例。如果您正苦于以下问题:Python Dao类的具体用法?Python Dao怎么用?Python Dao使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: delete

    def delete(self, region, id):
        """ Deletes a pending tournament.
            If a (non-pending) tournament with this id exists, tell the user they can't do that.
            Route restricted to admins for this region. """
        dao = Dao(region, mongo_client=mongo_client)

        user = get_user_from_request(request, dao)
        if not user:
            return 'Permission denied', 403

        pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))

        if not pending_tournament:
            tournament = dao.get_tournament_by_id(ObjectId(id))
            if not tournament:
                return "No pending tournament found with that id.", 400
            else:
                if not is_user_admin_for_regions(user, tournament.regions):
                    return 'Permission denied', 403
                else:
                    return "Cannot delete a finalized tournament.", 400

        if not is_user_admin_for_regions(user, pending_tournament.regions):
            return 'Permission denied', 403

        dao.delete_pending_tournament(pending_tournament)
        return {"success": True}
开发者ID:acoulon99,项目名称:garpr,代码行数:27,代码来源:server.py

示例2: post

 def post(self, region):
     dao = Dao(region, mongo_client=mongo_client)
     requesting_user = get_user_from_access_token(request.headers, dao)
     if not requesting_user.admin_regions: #wow, such auth
         return "user is not an admin", 403
     args = merges_put_parser.parse_args() #parse args
     try:
         base_player_id = ObjectId(args['base_player_id'])
         to_be_merged_player_id = ObjectId(args['to_be_merged_player_id'])
     except:
         return "invalid ids, that wasn't an ObjectID", 400
     # the above should validate that we have real objectIDs
     # now lets validate that both of those players exist
     if not dao.get_player_by_id(base_player_id):
         return "base_player not found", 400
     if not dao.get_player_by_id(to_be_merged_player_id):
         return "to_be_merged_player not found", 400
     #get curr time
     now = datetime.now()
     #create a new merge object
     the_merge = Merge(requesting_user.id, base_player_id, to_be_merged_player_id, now)
     #store it in the dao
     merge_id = dao.insert_pending_merge(the_merge)
     string_rep = str(merge_id)
     return_dict = {'id': string_rep}
     return return_dict, 200
开发者ID:MrMonacle,项目名称:garpr,代码行数:26,代码来源:server.py

示例3: get

    def get(self, region):
        args = player_list_get_parser.parse_args()
        dao = Dao(region, mongo_client=mongo_client)
        return_dict = {}

        # single player matching alias within region
        if args['alias'] is not None:
            return_dict['players'] = []
            db_player = dao.get_player_by_alias(args['alias'])
            if db_player:
                return_dict['players'].append(db_player.get_json_dict())
        # search multiple players by name across all regions
        elif args['query'] is not None:
            all_players = dao.get_all_players(all_regions=True)
            return_dict['players'] = [p.get_json_dict() for p in self._get_players_matching_query(all_players, args['query'])]
        # all players within region
        else:
            return_dict['players'] = [p.get_json_dict() for p in dao.get_all_players()]

        convert_object_id_list(return_dict['players'])

        # remove extra fields
        for player in return_dict['players']:
            del player['regions']
            del player['aliases']
            del player['ratings']

        return return_dict
开发者ID:acoulon99,项目名称:garpr,代码行数:28,代码来源:server.py

示例4: post

 def post(self):
     dao = Dao()
     self.response.out.write(dao.put_linha(id = self.request.get("id"),
                                           deleted = self.request.get("deleted"),
                                           info = self.request.get("info"),
                                           pontos = self.request.get("pontos"),
                                           hashes = self.request.get("hashes")))
开发者ID:adanfm,项目名称:cruzalinhas,代码行数:7,代码来源:frontend.py

示例5: grab

def grab(interval):
    coeffprovider = CoeffProvider()
    dao = Dao()
    coeffs = coeffprovider.get_coeff_list()
    dao.save_new_data(coeffs)
    print(time.ctime())
    threading.Timer(interval, grab, [interval]).start()
开发者ID:Michael-karn-ivanov,项目名称:dotapy,代码行数:7,代码来源:dota.py

示例6: put

    def put(self, region, id):
        dao = Dao(region, mongo_client=mongo_client)
        user = get_user_from_request(request, dao)

        args = tournament_details_add_match_parser.parse_args()
        tournament = dao.get_tournament_by_id(ObjectId(id))

        if not user:
            return 'Permission denied', 403
        if not is_user_admin_for_regions(user, tournament.regions):
            return 'Permission denied', 403

        winner_id = args['winner_id']
        loser_id = args['loser_id']

        if winner_id is None or loser_id is None:
            print "winner and loser IDs not present. Cannot continue"
            return "winner and loser IDs not present. Cannot continue", 400

        try:
            dao.add_match_by_tournament_id(ObjectId(id), ObjectId(winner_id), ObjectId(loser_id))
            return 'Successful addition', 200
        except Exception as e:
            print 'error adding match to tournament: ' + str(e)
            return 'error adding match to tournament: ' + str(e), 400
开发者ID:garsh0p,项目名称:garpr,代码行数:25,代码来源:server.py

示例7: get

    def get(self, region, id):
        dao = Dao(region, mongo_client=mongo_client)
        if not dao:
            return 'Dao not found', 404
        response = None
        tournament = None
        try:
            tournament = dao.get_tournament_by_id(ObjectId(id))
        except:
            return 'Invalid ObjectID', 400
        if tournament is not None:
            response = convert_tournament_to_response(tournament, dao)
        else:
            user = get_user_from_request(request, dao)
            # this usage is safe, if the ID was fake, we would have already
            # blown the coop above
            pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
            if not pending_tournament:
                return 'Not found!', 404
            if not user:
                return 'Permission denied', 403
            if not is_user_admin_for_regions(user, pending_tournament.regions):
                return 'Permission denied', 403
            response = pending_tournament.dump(context='web')

        return response
开发者ID:garsh0p,项目名称:garpr,代码行数:26,代码来源:server.py

示例8: import_tournament

def import_tournament(type, path, bracket, region, name):
    config = Config()
    mongo_client = MongoClient(host=config.get_mongo_url())

    if type == 'tio':
        scraper = TioScraper(path, bracket)
    elif type =='challonge':
        scraper = ChallongeScraper(path)
    else:
        click.echo("Illegal type")

    dao = Dao(region, mongo_client=mongo_client)

    player_map = get_player_alias_to_id_map(scraper, dao)

    # TODO pass in a map of overrides for specific players
    tournament = Tournament.from_scraper(type, scraper, player_map, region)
    if name:
        tournament.name = name

    dao.insert_tournament(tournament)

    click.echo("Generating new ranking...")
    rankings.generate_ranking(dao)

    click.echo("Done!")
开发者ID:AJAnderson,项目名称:garpr,代码行数:26,代码来源:import_tournament.py

示例9: bulk_alias_merge

def bulk_alias_merge(path, region):
    config = parse_config()
    username = config.get('database', 'user')
    host = config.get('database', 'host')
    auth_db = config.get('database', 'auth_db')
    password = getpass.getpass()

    mongo_client = MongoClient(host='mongodb://%s:%[email protected]%s/%s' % (username, password, host, auth_db))
    dao = Dao(region, mongo_client=mongo_client)

    with open(path) as f:
        reader = csv.reader(f)
        for row in reader:
            target_alias = row[0]
            db_target = dao.get_player_by_alias(target_alias)
            if db_target is None:
                print '%s is not a valid alias' % target_alias
                continue

            for source_alias in row[1:]:
                source_alias = source_alias.strip()
                if source_alias:
                    db_source = dao.get_player_by_alias(source_alias)
                    if db_source is None:
                        print '%s is not a valid alias' % source_alias
                        continue

                    print source_alias, '->', target_alias
                    dao.merge_players(source=db_source, target=db_target)
开发者ID:AJAnderson,项目名称:garpr,代码行数:29,代码来源:bulk_alias_merge.py

示例10: import_tournament

def import_tournament(type, path, bracket, region, name):
    config = parse_config()
    username = config.get('database', 'user')
    host = config.get('database', 'host')
    auth_db = config.get('database', 'auth_db')
    password = getpass.getpass()

    mongo_client = MongoClient(host='mongodb://%s:%[email protected]%s/%s' % (username, password, host, auth_db))

    if type == 'tio':
        scraper = TioScraper(path, bracket)
    elif type =='challonge':
        scraper = ChallongeScraper(path)
    else:
        click.echo("Illegal type")

    dao = Dao(region, mongo_client=mongo_client)

    import_players(scraper, dao)

    tournament = Tournament.from_scraper(type, scraper, dao)
    if name:
        tournament.name = name

    dao.insert_tournament(tournament)

    click.echo("Generating new ranking...")
    rankings.generate_ranking(dao)

    click.echo("Done!")
开发者ID:novacourtois,项目名称:garpr,代码行数:30,代码来源:import_tournament.py

示例11: put

    def put(self, region, id):
        dao = Dao(region, mongo_client=mongo_client)
        player = dao.get_player_by_id(ObjectId(id))

        if not player:
            return "No player found with that region/id.", 400

        # TODO auth for this needs to be different, otherwise an admin can tag with their region and then edit everything
        user = get_user_from_request(request, dao)
        if not user:
            return 'Permission denied', 403
        if not is_user_admin_for_regions(user, player.regions):
            return 'Permission denied', 403

        args = player_put_parser.parse_args()

        if args['name']:
            player.name = args['name']
        if args['aliases']:
            for a in args['aliases']:
                if not isinstance(a, unicode):
                    return "each alias must be a string", 400
            new_aliases = [a.lower() for a in args['aliases']]
            if player.name.lower() not in new_aliases:
                return "aliases must contain the players name!", 400
            player.aliases = new_aliases
        if args['regions']:
            for a in args['regions']:
                if not isinstance(a, unicode):
                    return "each region must be a string", 400
            player.regions = args['regions']

        dao.update_player(player)
开发者ID:acoulon99,项目名称:garpr,代码行数:33,代码来源:server.py

示例12: calculate

def calculate():
    dao = Dao()
    elo = Elo(k_factor=ELO_K_FACTOR, rating_class=float, initial=DEFAULT_RATING, beta=ELO_BETA)
    calculator = PreCalculation(DEFAULT_RATING, elo)
    dataframe = dao.get_past()
    dataframe = calculator.prepare_subtype(dataframe)
    rating = calculator.replay_elo(dataframe)
    print rating
开发者ID:Michael-karn-ivanov,项目名称:dotapy,代码行数:8,代码来源:dota.py

示例13: test_init_with_invalid_region

    def test_init_with_invalid_region(self):
        print Dao.get_all_regions(mongo_client=self.mongo_client)
        # create a dao with an existing region
        Dao(self.region, mongo_client=self.mongo_client, new=False)

        # create a dao with a new region
        with self.assertRaises(RegionNotFoundException):
            Dao('newregion', mongo_client=self.mongo_client, new=False)
开发者ID:novacourtois,项目名称:garpr,代码行数:8,代码来源:test_dao.py

示例14: test_get_all_regions

    def test_get_all_regions(self):
        # add another region
        region = Region('newregion', 'New Region')
        Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)

        regions = Dao.get_all_regions(self.mongo_client, database_name=DATABASE_NAME)
        self.assertEquals(len(regions), 3)
        self.assertEquals(regions[0], region)
        self.assertEquals(regions[1], self.region_1)
        self.assertEquals(regions[2], self.region_2)
开发者ID:MrMonacle,项目名称:garpr,代码行数:10,代码来源:test_dao.py

示例15: delete

 def delete(self):
     args = session_delete_parser.parse_args()
     dao = Dao(None, mongo_client=mongo_client)
     if not dao:
         return 'Dao not found', 404
     logout_success = dao.logout_user_or_none(args['session_id'])
     if not logout_success:
         return 'who is you', 404
     return ('logout success', 200,
             {'Set-Cookie': "session_id=deleted; expires=Thu, 01 Jan 1970 00:00:00 GMT"})
开发者ID:garsh0p,项目名称:garpr,代码行数:10,代码来源:server.py


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