示例#1
0
文件: views.py 项目: Taxane/dppl
def login(request):
    """ This is the fallback page when a user attempts to access a page and
    they aren't logged in. Pass it the get variable "next" to have the user
    redirected once they've successfully logged in.
    """
    error = ""
    next = request.REQUEST.get('next', "/").strip()

    if request.user.is_authenticated():
        return redirect("/")
    elif request.method == "POST":
        email = request.POST.get('email', '').strip()
        password = request.POST.get('password', '').strip()

        user = auth.authenticate(email=email, password=password)

        if user is not None:
            if user.is_active:
                auth.login(request, user)
                return redirect(next)
            else:
                error = "Your account is inactive."
        else:
            error = "Your email or password is incorrect."

    return render_response(request, "accounts/login.html", {
        'next': next,
        'error': error,
        })
示例#2
0
文件: views.py 项目: Taxane/dppl
def schedule(request):
    """ Display the schedule """
    league = League.objects.get(pk=settings.LEAGUE_ID)
    seasons = league.current_seasons()
    divisions = league.division_set.all()

    return render_response(request, 'theleague/schedule.html', {
        'current_seasons': seasons,
        'divisions': divisions,
    })
示例#3
0
文件: views.py 项目: blenderbox/dppl
def schedule(request):
    """ Display the schedule """
    league = League.objects.get(pk=settings.LEAGUE_ID)
    seasons = league.current_seasons()
    divisions = league.division_set.all()

    return render_response(request, 'theleague/schedule.html', {
        'current_seasons': seasons,
        'divisions': divisions,
    })
示例#4
0
文件: views.py 项目: Taxane/dppl
def scoreboard(request):
    """ Display the scoreboard. """
    now = datetime.datetime.now()
    league = League.objects.get(pk=settings.LEAGUE_ID)
    season = league.current_season

    if season is None:
        return render_response(
            request, 'theleague/scoreboard.html', {
                'rounds': None,
                'first_division_rounds': [],
                'second_division_rounds': [],
            })

    divisions = league.division_set.all()
    rounds = season.round_set.select_related().filter(
        go_dead_date__lt=now).order_by('-go_live_date')

    # All of the round ids as a list
    round_ids = [r.id for r in rounds]

    # A lambda to get matches by division
    matches = lambda i: Match.objects.filter(division__id=divisions[i].id,
                                             round__id__in=round_ids)

    # A lambda to regroup the matches by round
    division = lambda x: [(k, list(g)) for k, g in groupby(
        matches(x),
        key=lambda o: getattr(o, 'round'),
    )]

    return render_response(
        request,
        'theleague/scoreboard.html',
        {
            'rounds': rounds,
            # Get the round-grouped matches of the first division in `divisions`
            'first_division_rounds': division(0),
            # Get the round-grouped matches of the second division in `divisions`
            'second_division_rounds': division(1),
        })
示例#5
0
def index(request):
    """ Display the current round """
    now = datetime.datetime.now()
    season = League.objects.get(pk=settings.LEAGUE_ID).current_season

    if season:
        rounds = season.round_set.filter(
            go_dead_date__gt=now).order_by('go_live_date')[:1]

    current_round = rounds.get() if rounds else None

    return render_response(request, 'pages/index.html', {
        'current_round': current_round,
    })
示例#6
0
文件: views.py 项目: blenderbox/dppl
def index(request):
    """ Display the current round """
    now = datetime.datetime.now()
    season = League.objects.get(pk=settings.LEAGUE_ID).current_season

    if season:
        rounds = season.round_set.filter(go_dead_date__gt=now).order_by(
                'go_live_date')[:1]

    current_round = rounds.get() if rounds else None

    return render_response(request, 'pages/index.html', {
        'current_round': current_round,
    })
示例#7
0
文件: views.py 项目: blenderbox/dppl
def scoreboard(request):
    """ Display the scoreboard. """
    now = datetime.datetime.now()
    league = League.objects.get(pk=settings.LEAGUE_ID)
    season = league.current_season

    if season is None:
        return render_response(request, 'theleague/scoreboard.html', {
                  'rounds': None,
                  'first_division_rounds': [],
                  'second_division_rounds': [],
              })

    divisions = league.division_set.all()
    rounds = season.round_set.select_related().filter(
            go_dead_date__lt=now).order_by('-go_live_date')

    # All of the round ids as a list
    round_ids = [r.id for r in rounds]

    # A lambda to get matches by division
    matches = lambda i: Match.objects.filter(
            division__id=divisions[i].id, round__id__in=round_ids)

    # A lambda to regroup the matches by round
    division = lambda x: [(k, list(g)) for k, g in groupby(
                    matches(x),
                    key=lambda o: getattr(o, 'round'),
                )]

    return render_response(request, 'theleague/scoreboard.html', {
        'rounds': rounds,
        # Get the round-grouped matches of the first division in `divisions`
        'first_division_rounds': division(0),
        # Get the round-grouped matches of the second division in `divisions`
        'second_division_rounds': division(1),
    })
示例#8
0
文件: views.py 项目: blenderbox/dppl
def team_member(request, team_slug, team_member_slug):
    """ Display the team """
    league = League.objects.get(pk=settings.LEAGUE_ID)
    # TODO: make this actually pull in teams just from the league.
    team = get_object_or_404(Team, slug=team_slug)

    try:
        profile = team.profile_team.get(slug=team_member_slug)
    except Profile.DoesNotExist:
        raise Http404

    return render_response(request, 'theleague/team_member.html', {
        'schedule': team.current_schedule(league.current_season),
        'team': team,
        'profile': profile,
    })
示例#9
0
文件: views.py 项目: Taxane/dppl
def team_member(request, team_slug, team_member_slug):
    """ Display the team """
    league = League.objects.get(pk=settings.LEAGUE_ID)
    # TODO: make this actually pull in teams just from the league.
    team = get_object_or_404(Team, slug=team_slug)

    try:
        profile = team.profile_team.get(slug=team_member_slug)
    except Profile.DoesNotExist:
        raise Http404

    return render_response(
        request, 'theleague/team_member.html', {
            'schedule': team.current_schedule(league.current_season),
            'team': team,
            'profile': profile,
        })
示例#10
0
文件: views.py 项目: blenderbox/dppl
def team(request, team_slug=None):
    """ Display the team. """
    league = League.objects.get(pk=settings.LEAGUE_ID)
    objs = Team.objects.filter(division__league__id=settings.LEAGUE_ID)

    if team_slug is not None:
        objs = objs.filter(slug=team_slug)

    try:
        team = objs[:1][0]
    except IndexError:
        raise Http404

    return render_response(request, 'theleague/team.html', {
        'schedule': team.current_schedule(league.current_season),
        'team': team,
    })
示例#11
0
文件: views.py 项目: Taxane/dppl
def team(request, team_slug=None):
    """ Display the team. """
    league = League.objects.get(pk=settings.LEAGUE_ID)
    objs = Team.objects.filter(division__league__id=settings.LEAGUE_ID)

    if team_slug is not None:
        objs = objs.filter(slug=team_slug)

    try:
        team = objs[:1][0]
    except IndexError:
        raise Http404

    return render_response(
        request, 'theleague/team.html', {
            'schedule': team.current_schedule(league.current_season),
            'team': team,
        })
示例#12
0
文件: views.py 项目: Taxane/dppl
def update_profile(request):
    """ This allows a user to update his or her profile. """
    profile_kwargs = {
            'instance': request.user.profile,
            'prefix': 'profile',
            }
    email_kwargs = {
            'instance': request.user,
            'prefix': 'email',
            }

    if request.method == 'POST':
        if profile_kwargs['prefix'] in request.POST:
            profile_form = ProfileForm(request.POST, request.FILES,
                    **profile_kwargs)
            if profile_form.is_valid():
                profile_form.save()
                messages.success(request, "Your profile has been successfully "
                        "updated")
                return redirect("accounts:edit_profile")
            email_form = EmailForm(**email_kwargs)

        elif email_kwargs['prefix'] in request.POST:
            email_form = EmailForm(request.POST, **email_kwargs)
            if email_form.is_valid():
                email_form.save()
                messages.success(request, "Your email address has been "
                        "successfully updated.")
                return redirect("accounts:edit_profile")
            profile_form = ProfileForm(**profile_kwargs)

    else:
        profile_form = ProfileForm(**profile_kwargs)
        email_form = EmailForm(**email_kwargs)

    return render_response(request, "accounts/edit-profile.html", {
        'profile_form': profile_form,
        'email_form': email_form,
        })
示例#13
0
def rules(request):
    """ Display the rules. """
    return render_response(request, 'pages/rules.html', {})
示例#14
0
文件: views.py 项目: kayluhb/dppl
def index(request):
    """ Display a list of places.
    """
    today = datetime.date.today()

    return render_response(request, 'pages/index.html', {})
示例#15
0
文件: views.py 项目: kayluhb/dppl
def rules(request):
    """ Display a list of places.
    """

    return render_response(request, 'pages/rules.html', {})