本文整理汇总了Python中models.Match.date方法的典型用法代码示例。如果您正苦于以下问题:Python Match.date方法的具体用法?Python Match.date怎么用?Python Match.date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.date方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_matches
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import date [as 别名]
def add_matches(request):
# This view is the default redirect for login requests
if 'username' in request.POST and 'password' in request.POST:
user = authenticate(username=request.POST['username'], password=request.POST['password'])
if user != None and user.is_active:
login(request, user)
base = base_ctx('Submit', 'Matches', request)
add_login_message(base, extra='Submitted results will be pending review before inclusion.')
# If the user is logged in, the template needs a username and a list of event objects
if base['adm']:
base['events'] = Event.objects.filter(closed=False, rgt=F('lft')+1).order_by('lft')
if 'matches' in request.POST:
# Collect various information from the form
try:
event = request.POST['event'].strip()
except:
event = None
date = request.POST['date']
matches = request.POST['matches'].splitlines()
offline = not (request.POST['type'] != 'offline')
game = request.POST['game']
if game not in ['WoL', 'HotS']:
game = 'WoL'
base['game'] = game
base['type'] = 'offline' if offline else 'online'
base['matches'] = '\n'.join(matches)
base['date'] = date
base['event'] = event
# Get event object. If not admin, an exception will be thrown and eventobj = None.
try:
eventobj = Event.objects.get(id=int(request.POST['eobj']))
if eventobj.id == 2:
eventobj = None
except:
eventobj = None
if eventobj is not None:
base['eobj'] = eventobj.id
# Get extra data needed if not admin.
try:
source = request.POST['source']
contact = request.POST['contact']
notes = request.POST['notes']
base['source'] = source
base['contact'] = contact
base['notes'] = notes
except:
pass
# Check various requirements for non-admins
if not base['adm'] and len(matches) > 100:
base['messages'].append(Message('Please do not submit more than 100 results at a time.',
'Too many entries', Message.ERROR))
base.update(csrf(request))
return render_to_response('add.html', base)
if not base['adm'] and source.strip() == '':
base['messages'].append(Message('Please include a source.', 'Source missing', Message.ERROR))
base.update(csrf(request))
return render_to_response('add.html', base)
# If not admin, make a PreMatchGroup.
if not base['adm']:
pmgroup = PreMatchGroup(date=date, event=event, source=source, contact=contact, notes=notes,\
game=game, offline=offline)
pmgroup.save()
# Lists of successes and failures
success = []
failure = []
# Loop through match entries
for s in matches:
if s.strip() == '':
continue
try:
# Parse and collect the components
collect = parse_match(s.strip())
pla = collect[0]
plb = collect[1]
sca = int(collect[2][0])
scb = int(collect[2][1])
# Check for !DUP and !MAKE switches if user is logged in
dup_switch = False
make_switch = False
while collect[2][-1][0] == '!':
if collect[2][-1] == '!MAKE':
make_switch = True
elif collect[2][-1] == '!DUP':
dup_switch = True
collect[2] = collect[2][:-1]
#.........这里部分代码省略.........
示例2: single_match
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import date [as 别名]
def single_match(raw, mid):
m = Match(id=mid)
match_incr()
if raw[0][0]['officl'] == "1" and raw[0][0]['cas'] == "1":
# m.mode = 'cs'
m.mode = 2
elif raw[0][0]['officl'] == "1" and raw[0][0]['cas'] == "0":
# m.mode = "rnk"
m.mode = 1
else:
# m.mode = "acc"
m.mode = 3
m.version = raw[3][0]['version']
m.map_used = raw[3][0]['map']
m.length = raw[3][0]['time_played']
# '2014-07-27 01:31:18'
unaware_date = datetime.strptime(raw[3][0]['mdt'], '%Y-%m-%d %H:%M:%S')
m.date = utc.localize(unaware_date)
pitems = {}
for p in raw[1]:
items = []
for item in range(1, 7):
if p['slot_' + str(item)]:
items.append(int(p['slot_' + str(item)]))
pitems[p['account_id']] = items
for p in raw[2]:
if p['account_id'] not in pitems:
pitems[p['account_id']] = []
m.players.append(PlayerMatch(
player_id=int(p['account_id']),
nickname=p['nickname'],
clan_id=int(p['clan_id']),
hero_id=int(p['hero_id']),
position=int(p['position']),
items=pitems[p['account_id']],
team=int(p['team']),
level=int(p['level']),
win=bool(int(p['wins'])),
concedes=int(p['concedes']),
concedevotes=int(p['concedevotes']),
buybacks=int(p['buybacks']),
discos=int(p['discos']),
kicked=int(p['kicked']),
mmr_change=float(p['amm_team_rating']),
herodmg=int(p['herodmg']),
kills=int(p['herokills']),
assists=int(p['heroassists']),
deaths=int(p['deaths']),
kdr=div(p['herokills'], p['deaths']),
goldlost2death=int(p['goldlost2death']),
secs_dead=int(p['secs_dead']),
cs=int(p['teamcreepkills']) + int(p['neutralcreepkills']),
bdmg=p['bdmg'],
denies=p['denies'],
exp_denied=p['exp_denied'],
gpm=divmin(p['gold'], m.length),
xpm=divmin(p['exp'], m.length),
apm=divmin(p['actions'], m.length),
consumables=int(p['consumables']),
wards=int(p['wards'])
))
return m
示例3: review
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import date [as 别名]
def review(request):
base = base_ctx('Submit', 'Review', request)
if not base['adm']:
base.update(csrf(request))
return render_to_response('login.html', base)
add_login_message(base)
base['events'] = Event.objects.filter(closed=False, rgt=F('lft')+1).order_by('lft')
if 'act' in request.POST and base['adm'] == True:
if int(request.POST['eobj']) != 2:
eobj = Event.objects.get(id=int(request.POST['eobj']))
base['eobj'] = eobj.id
delete = True if request.POST['act'] == 'reject' else False
success = []
ndel = 0
for key in sorted(request.POST.keys()):
if request.POST[key] != 'y':
continue
if key[0:6] == 'match-':
pm = PreMatch.objects.get(id=int(key.split('-')[-1]))
if delete:
group = pm.group
pm.delete()
if not group.prematch_set.all().exists():
group.delete()
ndel += 1
continue
if pm.pla == None:
pm.pla_string = request.POST['match-%i-pla' % pm.id]
if pm.plb == None:
pm.plb_string = request.POST['match-%i-plb' % pm.id]
if pm.pla == None or pm.plb == None:
review_treat_players(pm, base)
if pm.pla and not pm.rca:
pm.pla = None
if pm.plb and not pm.rcb:
pm.plb = None
pm.save()
if pm.pla and pm.plb and pm.rca and pm.rcb:
m = Match()
m.pla = pm.pla
m.plb = pm.plb
m.sca = pm.sca
m.scb = pm.scb
m.rca = pm.rca
m.rcb = pm.rcb
if request.POST['date'].strip() == '':
m.date = pm.group.date
else:
m.date = request.POST['date']
m.event = pm.group.event
m.eventobj = eobj
m.submitter = request.user
m.set_period()
m.offline = pm.group.offline
m.game = pm.group.game
m.save()
success.append(m)
group = pm.group
pm.delete()
if not group.prematch_set.all().exists():
group.delete()
base['success'] = display_matches(success, messages=False)
if len(success) > 0:
base['messages'].append(Message('Approved %i match(es).' % len(success), type=Message.SUCCESS))
if ndel > 0:
base['messages'].append(Message('Rejected %i match(es).' % ndel, type=Message.SUCCESS))
groups = PreMatchGroup.objects.filter(prematch__isnull=False)\
.select_related('prematch').order_by('id', 'event').distinct()
for g in groups:
g.prematches = display_matches(g.prematch_set.all(), messages=False)
base['groups'] = groups
base.update(csrf(request))
return render_to_response('review.html', base)