コード例 #1
0
ファイル: views.py プロジェクト: humblejok/gso_betsforfriends
def bets_get(request):
    if request.POST.has_key('token'):
        token = request.POST['token']
        if (settings.DEBUG
                or request.is_secure()) and get_user_meta(None, token) != None:
            return HttpResponse(
                '{"result": true, "message":"Token is valid", "meta":' +
                str(get_user_meta(None, token)) + '}',
                content_type="application/json")
    raise PermissionDenied()
コード例 #2
0
ファイル: views.py プロジェクト: humblejok/gso_betsforfriends
def user_token(request):
    if (settings.DEBUG
            or request.is_secure()) and request.user.is_authenticated:
        context = {
            'user_meta': get_user_meta(User.objects.get(id=request.user.id),
                                       None)
        }
        return render(request, 'mobile/user_token.html', context)
    else:
        raise PermissionDenied()
コード例 #3
0
ファイル: views.py プロジェクト: humblejok/gso_betsforfriends
def index(request):
    now = datetime.datetime.today()
    begin = dt.combine(datetime.date.today(), dt.min.time())
    end = dt.combine(dates.AddDay(begin, 14), dt.max.time())
    all_dates = Match.objects.filter(when__gte=begin, when__lte=end).order_by('when').dates('when','day')
    all_dates = [a_date.strftime('%Y-%m-%d') for a_date in all_dates]
    active_events = BettableEvent.objects.filter(end_date__gte=datetime.date.today).order_by('name')
    if request.user.is_authenticated and request.user.id!=None:
        user = User.objects.get(id=request.user.id)
        if get_user_meta(user)==None:
            initialize_user_meta(user)
        rankings = UserRanking.objects.filter(owner__id=user.id)
        if not rankings.exists():
            initial_ranking = UserRanking()
            initial_ranking.owner = user
            initial_ranking.group = None
            initial_ranking.overall_score = 0
            initial_ranking.rank = None
            initial_ranking.save()
            rankings = UserRanking.objects.filter(owner__id=user.id)
        global_ranking = UserRanking.objects.filter(owner__id=user.id, group=None)
        if global_ranking.exists():
            global_ranking = global_ranking[0]
        else:
            global_ranking = None

        admin_groups = Group.objects.filter(Q(owners__id__exact=request.user.id)).distinct().order_by('name')
        member_groups = Group.objects.filter(Q(members__id__exact=request.user.id) | Q(owners__id__exact=request.user.id)).distinct().order_by('name')

        winner_setups = []
        for group in list(admin_groups) + list(member_groups):
            setup = WinnerSetup.objects.filter(group__id=group.id, group__event__end_date__gte=now)
            if setup.exists():
                setup = setup[0]
                all_steps = setup.setup.all()
                if all_steps.exists():
                    if not group.event.id in winner_setups:
                        winner_setups.append(group.event.id)

        all_matches = Match.objects.filter(when__gte=begin, when__lte=end).order_by('when')
        all_bets = {}
        for match in all_matches:
            bet = Bet.objects.filter(owner__id=request.user.id, match__id=match.id)
            if bet.exists():
                bet = bet[0]
            else:
                bet = Bet()
                bet.clean()
                bet.owner = user
                bet.match = match
                bet.when = datetime.datetime.now()
                bet.winner = None
                score = Score()
                score.name = match.name
                score.first = 0
                score.second = 0
                score.save()
                bet.result = score
                bet.save()
            all_bets[bet.match.id] = {'id': bet.id, 'score': {'first':bet.result.first, 'second':bet.result.second}, 'enabled':str(bet.match.when + datetime.timedelta(minutes=10)>=now).lower(), 'amount': bet.amount if bet.amount!=None else 0}
        allow_amount = request.user.groups.filter(name='allow_amount')

        context = {'winner_setups': winner_setups, 'admin_groups': admin_groups,'member_groups': member_groups, 'all_dates': all_dates, 'all_bets': all_bets, 'rankings': rankings, 'global_rank':global_ranking, 'events': active_events, 'allow_amount': allow_amount, 'events': active_events}
    else:
        context = {'all_dates': all_dates, 'events': active_events, 'all_bets': []}
    return render(request,'index.html', context)
コード例 #4
0
def index(request):
    now = datetime.datetime.today()
    begin = dt.combine(datetime.date.today(), dt.min.time())
    end = dt.combine(dates.AddDay(begin, 14), dt.max.time())
    all_dates = Match.objects.filter(when__gte=begin,
                                     when__lte=end).order_by('when').dates(
                                         'when', 'day')
    all_dates = [a_date.strftime('%Y-%m-%d') for a_date in all_dates]
    active_events = BettableEvent.objects.filter(
        end_date__gte=datetime.date.today).order_by('name')
    if request.user.is_authenticated and request.user.id != None:
        user = User.objects.get(id=request.user.id)
        if get_user_meta(user) == None:
            initialize_user_meta(user)
        rankings = UserRanking.objects.filter(owner__id=user.id)
        if not rankings.exists():
            initial_ranking = UserRanking()
            initial_ranking.owner = user
            initial_ranking.group = None
            initial_ranking.overall_score = 0
            initial_ranking.rank = None
            initial_ranking.save()
            rankings = UserRanking.objects.filter(owner__id=user.id)
        global_ranking = UserRanking.objects.filter(owner__id=user.id,
                                                    group=None)
        if global_ranking.exists():
            global_ranking = global_ranking[0]
        else:
            global_ranking = None

        admin_groups = Group.objects.filter(
            Q(owners__id__exact=request.user.id)).distinct().order_by('name')
        member_groups = Group.objects.filter(
            Q(members__id__exact=request.user.id)
            | Q(owners__id__exact=request.user.id)).distinct().order_by('name')

        winner_setups = []
        for group in list(admin_groups) + list(member_groups):
            setup = WinnerSetup.objects.filter(group__id=group.id,
                                               group__event__end_date__gte=now)
            if setup.exists():
                setup = setup[0]
                all_steps = setup.setup.all()
                if all_steps.exists():
                    if not group.event.id in winner_setups:
                        winner_setups.append(group.event.id)

        all_matches = Match.objects.filter(when__gte=begin,
                                           when__lte=end).order_by('when')
        all_bets = {}
        for match in all_matches:
            bet = Bet.objects.filter(owner__id=request.user.id,
                                     match__id=match.id)
            if bet.exists():
                bet = bet[0]
            else:
                bet = Bet()
                bet.clean()
                bet.owner = user
                bet.match = match
                bet.when = datetime.datetime.now()
                bet.winner = None
                score = Score()
                score.name = match.name
                score.first = 0
                score.second = 0
                score.save()
                bet.result = score
                bet.save()
            all_bets[bet.match.id] = {
                'id':
                bet.id,
                'score': {
                    'first': bet.result.first,
                    'second': bet.result.second
                },
                'enabled':
                str(bet.match.when +
                    datetime.timedelta(minutes=10) >= now).lower(),
                'amount':
                bet.amount if bet.amount != None else 0
            }
        allow_amount = request.user.groups.filter(name='allow_amount')

        context = {
            'winner_setups': winner_setups,
            'admin_groups': admin_groups,
            'member_groups': member_groups,
            'all_dates': all_dates,
            'all_bets': all_bets,
            'rankings': rankings,
            'global_rank': global_ranking,
            'events': active_events,
            'allow_amount': allow_amount,
            'events': active_events
        }
    else:
        context = {
            'all_dates': all_dates,
            'events': active_events,
            'all_bets': []
        }
    return render(request, 'index.html', context)
コード例 #5
0
ファイル: views.py プロジェクト: humblejok/gso_betsforfriends
def bets_get(request):
    if request.POST.has_key('token'):
        token = request.POST['token']
        if (settings.DEBUG or request.is_secure()) and get_user_meta(None,token)!=None:
            return HttpResponse('{"result": true, "message":"Token is valid", "meta":' + str(get_user_meta(None,token)) + '}', content_type="application/json");
    raise PermissionDenied()
コード例 #6
0
ファイル: views.py プロジェクト: humblejok/gso_betsforfriends
def user_token(request):
    if (settings.DEBUG or request.is_secure()) and request.user.is_authenticated:
        context = {'user_meta': get_user_meta(User.objects.get(id=request.user.id),None)}
        return render(request,'mobile/user_token.html', context)
    else:
        raise PermissionDenied()