本文整理汇总了Python中models.Match类的典型用法代码示例。如果您正苦于以下问题:Python Match类的具体用法?Python Match怎么用?Python Match使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Match类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match_put
def match_put(mid, pid):
""" Insert match via Match ID and DotA2 ID """
if not match_check(mid, pid):
query = Match(match_id=mid, player=pid)
query.save()
return True
return False
示例2: test_undo_match
def test_undo_match(g):
p = Player("test player")
p2 = Player("test player 2")
player_dao.create(p)
p.id = 1
player_dao.create(p2)
p2.id = 2
t = Tournament(0,'','T1','type',0)
tournament_dao.create(t)
t.id = 1
match_dao.create([p.id, p2.id], t.id)
match_id = 1
match = Match(player1=p,player2=p2,id=match_id)
match.score1 = 19
match.score2 = 21
match_dao.update(match)
match_dao.undo(match)
retrieved_match = match_dao.find(match_id)
matches = match_dao.find_by_tournament(t.id)
assert retrieved_match.score1 == 0
assert retrieved_match.score2 == 0
assert retrieved_match.player1.fname == p.fname
assert retrieved_match.player2.fname == p2.fname
assert retrieved_match.player1.id == p.id
assert retrieved_match.player2.id == p2.id
assert not matches[0].entered_time
示例3: exists
def exists(cls,iid,table):
if table == "match":
try:
Match.get(iid=iid)
except Match.DoesNotExist:
return False
if table == "odd":
try:
Odd.get(iid=iid)
except Odd.DoesNotExist:
return False
if table == "cat":
try:
OddCategory.get(idd=iid)
except OddCategory.DoesNotExist:
return False
if table == "result":
try:
Result.get(iid=iid)
except Result.DoesNotExist:
return False
if table == "user":
try:
User.get(iid=iid)
except User.DoesNotExist:
return False
return True
示例4: match
def match(request, user_id):
user = get_object_or_404(Profile, pk=user_id)
match = Match(date=timezone.now())
match.save()
match.users.add(user, request.user)
match.save()
return HttpResponseRedirect(reverse('meet:match_detail', args=(match.id,)))
示例5: entry
def entry():
if not session.get('user'):
return redirect(url_for('index'))
user = session.get('user')
u = User.select().where(User.username == user)[0]
already_entered = Crush.select().where(Crush.user == u)
if request.method == 'POST':
entries = filter(None, request.form.getlist("entry"))
if len(entries) > 5:
return redirect('entry')
captcha = request.form.get('g-recaptcha-response')
captcha_r = requests.post('https://www.google.com/recaptcha/api/siteverify',
data={'secret': '6Lcd-gcTAAAAANlxsT-ptOTxsgRiJKTGTut2VgLk',
'response': captcha,
'remoteip': request.remote_addr})
if not captcha_r.json()['success']:
return render_template('entry.html', user=user, entries=entries,
already_entered=already_entered,
already_entered_count=already_entered.count())
if not any(entries):
return redirect('entry')
suggestions = map(lookup, entries)
for i, entry in enumerate(entries):
if entry not in suggestions[i]:
return render_template('entry.html', user=user,
entries=entries,
suggestions=suggestions,
already_entered=already_entered,
already_entered_count=already_entered.count())
for entry in entries:
exists = Crush.select().where(Crush.user == u, Crush.crush == entry).count()
if not exists:
Crush.create(user=u, crush=entry)
crush_user_exists = User.select().where(User.username == entry).count()
if crush_user_exists:
crush_user = User.select().where(User.username == entry)[0]
crush_user_crushes = map(lambda m: m.crush, Crush.select().where(Crush.user == crush_user))
if crush_user and u.username in crush_user_crushes:
Match.create(user_1 = u, user_2 = crush_user)
return redirect('/matches')
return render_template('entry.html', user=user,
already_entered=already_entered,
already_entered_count=already_entered.count())
示例6: get_all_matches
def get_all_matches(account_id):
"""Try to retrieve and add all matches from a player to the database."""
matches = api.get_match_history(account_id=account_id)["result"]
while matches["results_remaining"] >= 0 and matches["num_results"] > 1:
for match in matches["matches"]:
try:
Match.get(Match.match_id == match["match_id"])
except DoesNotExist:
new_match_task = add_match.delay(match["match_id"])
matches = api.get_match_history(account_id=account_id, start_at_match_id=match["match_id"])["result"]
示例7: confirm_match
def confirm_match(request, req_id=None):
if request.method == "POST":
if req_id is not None:
try:
sr = ScoreRequest.objects.get(id=req_id)
except:
return HttpResponseRedirect('/welcome/')
form = ConfirmRequestForm(request.POST, instance=sr)
print form
if form.is_valid() and sr.player2.user.username == request.user.username: #and needs to verify player2 is current player lol
form.save()
if int(request.POST['verified']) == 2:
#Save fields into a Match object now
match = Match()
match.player1 = sr.player1
match.player2 = sr.player2
match.wins = sr.wins
match.loss = sr.loss
match.ties = sr.ties
match.tournament = sr.tournament
match.save()
return HttpResponseRedirect('/welcome/')
return HttpResponseRedirect('/welcome/')
else:
print "Only POST requests for now"
return HttpResponseRedirect('/welcome/')
示例8: _trigger_played_match
def _trigger_played_match(self, match_type):
if MatchSoloQueue.query(MatchSoloQueue.type == match_type).count() >= 2:
match_solo_queues = [match_queue for match_queue in MatchSoloQueue.query(MatchSoloQueue.type == match_type).fetch(10)]
players = [match_queue.player.get() for match_queue in match_solo_queues]
match = Match(type=match_type)
match.setup_soloqueue_match(players)
ndb.delete_multi([queue.key for queue in match_solo_queues])
for player in players:
player.doing = match.key
player.put()
websocket_notify_player("Player_MatchFound", player.key, None, match.get_data())
示例9: get
def get(self):
#500 is max delete at once limit.
db.delete(Match.all().fetch(500))
match_count = Match.all().count()
template_values = {
'match_count': match_count,
}
path = os.path.join(os.path.dirname(__file__), '../templates/matches/flush.html')
self.response.out.write(template.render(path, template_values))
示例10: post
def post(self):
player = current_user_player()
if player.doing:
error_400(self.response, "ERROR_PLAYER_BUSY", "Player is busy.")
return
bot_match = Match(type="Bot")
bot_match.setup_bot_match(player)
player.doing = bot_match.key
player.put()
set_json_response(self.response, bot_match.get_data("full"))
示例11: matches
def matches():
if not session.get('user'):
return redirect('/login')
user = User.select().where(User.username == session.get('user'))[0]
count = Crush.select().where(Crush.crush == session.get('user')).count()
matches_1 = map(lambda m: m.user_2.username, Match.select().where(Match.user_1 == user))
matches_2 = map(lambda m: m.user_1.username, Match.select().where(Match.user_2 == user))
matches_1.extend(matches_2)
return render_template('match.html', matches=matches_1, count=count, user=user.username)
示例12: syncMatchTable
def syncMatchTable(self):
self.connection.request("GET", "/sync/match")
response = self.connection.getresponse()
data = response.read()
data = json.loads(data)
print response.read()
print data
if not data.has_key('up-to-date'):
for match in data['name']:
try:
Match.create(iid=match['iid'],homeTeam=match['homeTeam'], awayTeam=match["awayTeam"], startTime=match['startTime'],
league=match['league'])
except Exception, e:
print str(e) + "- Match"
示例13: get_matches
def get_matches():
"""
http://wiki.guildwars2.com/wiki/API:1/wvw/matches
"""
for m in api.api_request('wvw/matches')['wvw_matches']:
match = Match(
match_id=m['wvw_match_id'],
red=World.objects.get(world_id=m['red_world_id']),
blue=World.objects.get(world_id=m['blue_world_id']),
green=World.objects.get(world_id=m['green_world_id']),
start_time=m['start_time'],
end_time=m['end_time'])
match.save()
return Match.objects.all()
示例14: check
def check(self):
try:
match = Match.get(iid=self.matchCode.get_text())
category = OddCategory.get(name=self.category.get_active_text())
odd = Odd.get(match=match,category=category,oddCode=self.bet.get_text())
self.addMatchButton.set_sensitive(False)
self.reason.set_text("Match Started")
except Match.DoesNotExist:
self.addMatchButton.set_sensitive(False)
self.odd.set_text("")
self.reason.set_text("Invalid Match")
except OddCategory.DoesNotExist:
self.addMatchButton.set_sensitive(False)
self.odd.set_text("")
self.reason.set_text("Invalid Category")
except Odd.DoesNotExist:
self.addMatchButton.set_sensitive(False)
self.odd.set_text("")
self.reason.set_text("Invalid Bet")
else:
if match.is_valid():
self.addMatchButton.set_sensitive(True)
self.reason.set_text("Available")
self.odd.set_text(str(odd.odd))
else:
self.addMatchButton.set_sensitive(False)
self.reason.set_text("Match Started")
if len(self.bets)>0 and self.amountstaked.get_text()!= "":
self.stakebutton.set_sensitive(True)
else:
self.stakebutton.set_sensitive(False)
示例15: getCurrentMatchByUser
def getCurrentMatchByUser(current_user_id):
#Gets the match the user is currently participating in, or None if no match started.
#TODO: Check & Confirm creation order
hackathon = Match.all().filter("users =", current_user_id).order("-created").get()
if not hackathon or (100 in hackathon.outcome): #Most recent is nonexistant or completed
return None
return hackathon