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


Python Match.set_period方法代码示例

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


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

示例1: add_matches

# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import set_period [as 别名]

#.........这里部分代码省略.........
                    n = find_duplicates(pla_obj, plb_obj, sca, scb, date)
                    if n > 0 and not dup_switch:
                        failure.append(s)
                        base['messages'].append(Message(
                            '%i possible duplicate(s) found, add !DUP switch to force.' % n,
                            s, Message.ERROR))
                        continue

                # If the user is not logged in, we now have enough information to create a prematch.
                if not base['adm']:
                    pm = PreMatch(group=pmgroup, sca=sca, scb=scb, pla=pla_obj, plb=plb_obj,\
                            pla_string=' '.join(pla), plb_string=' '.join(plb), date=pmgroup.date)
                    if rca:
                        pm.rca = rca
                    elif pla_obj:
                        pm.rca = pla_obj.race
                    else:
                        pm.rca = None

                    if rcb:
                        pm.rcb = rcb
                    elif plb_obj:
                        pm.rcb = plb_obj.race
                    else:
                        pm.rcb = None

                    pm.save()
                    success.append(pm)
                    continue

                # Abort if race information is incorrect
                if pla_obj.race == 'S' and rca == None:
                    failure.append(s)
                    base['messages'].append(Message(
                        '%s is Random or Switcher, need race information.' % pla_obj.tag,
                        s, Message.ERROR))
                    continue

                if plb_obj.race == 'S' and rcb == None:
                    failure.append(s)
                    base['messages'].append(Message(
                        '%s is Random or Switcher, need race information.' % plb_obj.tag,
                        s, Message.ERROR))
                    continue

                # Add match
                m = Match()
                m.pla = pla_obj
                m.plb = plb_obj
                m.sca = sca
                m.scb = scb
                m.rca = pla_obj.race if rca == None else rca
                m.rcb = plb_obj.race if rcb == None else rcb
                m.date = date
                m.submitter = request.user
                m.set_period()
                m.eventobj = eventobj
                m.offline = offline
                m.game = game
                m.save()

                success.append(m)

            except Exception as e:
                failure.append(s)
                base['messages'].append(Message('Could not parse: ' + e.message, s, Message.ERROR))
                continue

        success = display_matches(success, messages=False)
        if len(success) > 0:
            base['messages'].append(Message('Added %i match(es).' % len(success), type=Message.SUCCESS))

        base.update({'matches': '\n'.join(failure), 'success': success})

    elif 'eventid' in request.GET:
        try:
            event = Event.objects.get(id=int(request.GET['eventid']))
            if event.closed:
                event.closed = False
                event.save()
                base['messages'].append(Message('Reopened \'%s\'.' % event.fullname, type=Message.SUCCESS))
            base['eobj'] = event.id
        except:
            base['messages'].append(Message('Couldn\'t find event ID %s.' % request.GET['eventid'], 
                type=Message.ERROR))

    try:
        if base['adm'] and request.POST['action'] == 'Add and close event' and eventobj is not None:
            if len(failure) == 0:
                eventobj.close()
                base['messages'].append(Message('Event \'%s\' closed.' % eventobj.fullname, 
                                                type=Message.SUCCESS))
            else:
                base['messages'].append(Message('Event \'%s\' was NOT closed.' % eventobj.fullname,
                                                type=Message.WARNING))
    except:
        pass

    base.update(csrf(request))
    return render_to_response('add.html', base)
开发者ID:Arzar,项目名称:aligulac,代码行数:104,代码来源:submitviews.py

示例2: review

# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import set_period [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)
开发者ID:Arzar,项目名称:aligulac,代码行数:93,代码来源:submitviews.py


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