def matchs_save(request): if request.user.id!=None and request.user.is_authenticated and request.user.is_superuser: message = "Aucun probleme." all_matchs = json.loads(request.POST['all_matchs']) event_id = request.POST['event_id'] for match in all_matchs: LOGGER.info("Working on match " + str(match)) web_match = all_matchs[match] py_match = Match.objects.get(id=match) if py_match.result==None: score = Score() else: score = Score.objects.get(id=py_match.result.id) score.first = web_match[u'score'][u'first'] score.second = web_match[u'score'][u'second'] score.name = "Official score " + py_match.name score.save() py_match.result = score py_match.save() generate_matchs(all_matchs.keys()) event = BettableEvent.objects.get(id=event_id) generates_per_participant_result(event) # TODO: Change if event.sport.identifier=='SPORT_FOOTBALL': compute_fifa_wc_pools(event) compute_fifa_wc_8th(event) event_meta = get_event_meta(event) for m_type in event_meta['final_phases'][1:]: complete_meta_for_type(event, m_type) return HttpResponse('{"result": true, "message":"' + message + '"}', content_type="application/json"); else: raise PermissionDenied()
def matchs_save(request): if request.user.id != None and request.user.is_authenticated and request.user.is_superuser: message = "Aucun probleme." all_matchs = json.loads(request.POST['all_matchs']) event_id = request.POST['event_id'] for match in all_matchs: LOGGER.info("Working on match " + str(match)) web_match = all_matchs[match] py_match = Match.objects.get(id=match) if py_match.result == None: score = Score() else: score = Score.objects.get(id=py_match.result.id) score.first = web_match[u'score'][u'first'] score.second = web_match[u'score'][u'second'] score.name = "Official score " + py_match.name score.save() py_match.result = score py_match.save() generate_matchs(all_matchs.keys()) event = BettableEvent.objects.get(id=event_id) generates_per_participant_result(event) # TODO: Change if event.sport.identifier == 'SPORT_FOOTBALL': compute_fifa_wc_pools(event) compute_fifa_wc_8th(event) event_meta = get_event_meta(event) for m_type in event_meta['final_phases'][1:]: complete_meta_for_type(event, m_type) return HttpResponse('{"result": true, "message":"' + message + '"}', content_type="application/json") else: raise PermissionDenied()
def bets_save(request): if request.user.is_authenticated and request.user.id!=None: message = "Aucun probleme." user = User.objects.get(id=request.user.id) now = dt.now() all_bets = json.loads(request.POST['all_bets']) for bet in all_bets: web_bet = all_bets[bet] bet_id = web_bet[u'id'] user_bet = Bet.objects.get(id=bet_id, owner__id=user.id) if user_bet.match.when+ datetime.timedelta(minutes=10)>=now: score = Score.objects.get(id=user_bet.result.id) user_bet.when = now score.first = web_bet[u'score'][u'first'] score.second = web_bet[u'score'][u'second'] score.save() if score.first==score.second: user_bet.winner = None elif score.first>score.second: user_bet.winner = user_bet.match.first else: user_bet.winner = user_bet.match.second user_bet.amount = web_bet[u'amount'] if web_bet.has_key(u'amount') else 0 user_bet.save() else: LOGGER.warn("Tried to bet after date") message = "Un ou plusieurs matchs ont deja commence." return HttpResponse('{"result": true, "message":"' + message + '"}', content_type="application/json");
def bets_save(request): if request.user.is_authenticated and request.user.id != None: message = "Aucun probleme." user = User.objects.get(id=request.user.id) now = dt.now() all_bets = json.loads(request.POST['all_bets']) for bet in all_bets: web_bet = all_bets[bet] bet_id = web_bet[u'id'] user_bet = Bet.objects.get(id=bet_id, owner__id=user.id) if user_bet.match.when + datetime.timedelta(minutes=10) >= now: score = Score.objects.get(id=user_bet.result.id) user_bet.when = now score.first = web_bet[u'score'][u'first'] score.second = web_bet[u'score'][u'second'] score.save() if score.first == score.second: user_bet.winner = None elif score.first > score.second: user_bet.winner = user_bet.match.first else: user_bet.winner = user_bet.match.second user_bet.amount = web_bet[u'amount'] if web_bet.has_key( u'amount') else 0 user_bet.save() else: LOGGER.warn("Tried to bet after date") message = "Un ou plusieurs matchs ont deja commence." return HttpResponse('{"result": true, "message":"' + message + '"}', content_type="application/json")