def send_request(request, fixture_id):
    fixture = get_object_or_404(Fixture, pk=fixture_id)
    can_manage_fixture = False
    user = request.user

    if can_manage_club(user.id, fixture.team_a.club_id):
        can_manage_fixture = True
    if can_manage_club(user.id, fixture.team_b.club_id):
        can_manage_fixture = True

    if not can_manage_fixture:
        return HttpResponseForbidden()

    if request.method == 'POST':

        form = RearrangementRequestForm(request.POST)

        if form.is_valid():

            rearrangement_request = RearrangementRequest(
                original_fixture=fixture,
                reason=form.cleaned_data['reason'],
                new_date_time=form.cleaned_data['new_date_time'],
                status="requested",
                who_requested=user.member
            )
            rearrangement_request.save()

            email_context = {'request': rearrangement_request, 'fixture': fixture}

            msg_club_plain = render_to_string('email/club/fixture_rearrangement.txt', email_context)
            msg_club_html = render_to_string('email/club/fixture_rearrangement.html', email_context)
            msg_admin_plain = render_to_string('email/admin/fixture_rearrangement.txt', email_context)
            msg_admin_html = render_to_string('email/admin/fixture_rearrangement.html', email_context)
            msg_user_plain = render_to_string('email/user/fixture_rearrangement.txt', email_context)
            msg_user_html = render_to_string('email/user/fixture_rearrangement.html', email_context)
            subject = 'Rearrangement Request'

            email_main_club_contacts(fixture.team_a.club, subject, msg_club_plain, msg_club_html)
            email_main_club_contacts(fixture.team_b.club, subject, msg_club_plain, msg_club_html)
            parent_competition = get_most_senior_parent_competition(fixture.competition)
            email_competition_admins(parent_competition, subject, msg_admin_plain, msg_admin_html)
            email_notifications([user.email], subject, msg_user_plain, msg_user_html)

            return redirect('fixtures:detail', fixture_id=fixture_id)

    elif request.method == 'GET':

        form = RearrangementRequestForm()

    else:
        return HttpResponseBadRequest()

    context = {
        'fixture': fixture,
        'form': form,
    }

    return render(request, 'rearrangements/request.html', context)
Ejemplo n.º 2
0
def cancel(request, fixture_id):
    fixture = get_object_or_404(Fixture, pk=fixture_id)
    can_manage_fixture = False
    user = request.user

    if can_manage_club(user.id, fixture.team_a.club_id):
        can_manage_fixture = True
    if can_manage_club(user.id, fixture.team_b.club_id):
        can_manage_fixture = True

    if not can_manage_fixture:
        return HttpResponseForbidden()

    if request.method == 'POST':

        form = FixtureCancellationForm(request.POST)

        if form.is_valid():
            from fixtures.utils.cancellations import send_cancellation_notifications

            if form.cleaned_data['who_cancelled'] == "Home Team":
                team_cancellation = fixture.team_a
            else:
                team_cancellation = fixture.team_b

            now = datetime.now()
            cancellation = FixtureCancellation(
                cancellation_reporter=user.member,
                fixture=fixture,
                datetime_cancelled=now,
                cancellation_reason=form.cleaned_data['cancellation_reason'],
                more_info=form.cleaned_data['more_cancellation_info'],
                cancelled_by_team=team_cancellation)
            cancellation.save()

            send_cancellation_notifications(fixture, cancellation)

            return render(request, 'fixtures/cancellation_sent.html',
                          {'fixture': fixture})

    elif request.method == 'GET':

        form = FixtureCancellationForm()

    else:
        return HttpResponseBadRequest()

    context = {
        'fixture': fixture,
        'form': form,
    }

    return render(request, 'fixtures/cancel.html', context)
Ejemplo n.º 3
0
def detail(request, team_id):
    team = get_object_or_404(Team, pk=team_id)
    fixtures = Fixture.objects.filter(Q(team_a_id=team_id) | Q(team_b_id=team_id)).order_by('date')
    can_manage_team = False
    user = request.user

    if user.is_authenticated:
        if can_manage_club(user.id, team.club.id):
            can_manage_team = True

    now = datetime.datetime.now()

    upcoming_fixtures = fixtures.filter(Q(date__gte=now))
    past_fixtures = fixtures.filter(Q(date__lt=now)).order_by('-date')

    if team.club.secondary_colour == '#000000':
        light_or_dark = 'dark'
    else:
        light_or_dark = 'light'

    return render(request, 'teams/detail.html',
                  {
                      'team': team,
                      'upcoming_fixtures': upcoming_fixtures,
                      'past_fixtures': past_fixtures,
                      'can_manage': can_manage_team,
                      'light_or_dark': light_or_dark
                  })
Ejemplo n.º 4
0
def submit_result(request, fixture_id):
    fixture = get_object_or_404(Fixture, pk=fixture_id)
    can_manage_fixture = False
    can_administrate = False
    user = request.user

    if can_manage_club(user.id, fixture.team_a.club.id):
        can_manage_fixture = True
    if can_manage_club(user.id, fixture.team_b.club.id):
        can_manage_fixture = True
    if can_administrate_competition(user.id, fixture.competition.id):
        can_administrate = True

    if not can_manage_fixture and not can_administrate:
        return HttpResponseForbidden()

    if request.method == "POST":

        form = SubmitResultForm(data=request.POST, fixture=fixture)

        if form.is_valid():
            from fixtures.utils.general import fill_fixture_result

            form.instance.fixture = fixture
            form.instance = fill_fixture_result(form.instance)
            saved = form.save()

            fixture.result = saved
            fixture.save()

            return redirect('fixtures:detail', fixture_id=fixture.id)

    elif request.method == "GET":
        form = SubmitResultForm(fixture)

    else:
        return HttpResponseBadRequest()

    context = {'form': form, 'fixture': fixture}

    return render(request, 'fixtures/submit_result.html', context)
Ejemplo n.º 5
0
def manage(request, club_id):
    club = get_object_or_404(Club, pk=club_id)
    can_manage = False
    user = request.user

    if can_manage_club(user.id, club_id):
        can_manage = True

    if not can_manage:
        return HttpResponseForbidden()

    context = {'club': club, 'membership_size': club.members.count()}

    return render(request, 'clubs/manage.html', context)
Ejemplo n.º 6
0
def can_submit_match_card(user, fixture):
    can_manage_team_a = False
    can_administrate = False

    from nehlwebsite.utils.auth_utils import can_manage_club, can_administrate_competition

    if user.is_authenticated:
        if can_manage_club(user.id, fixture.team_a.club.id):
            can_manage_team_a = True
        if can_administrate_competition(user.id, fixture.competition.id):
            can_administrate = True

    if not (can_administrate or can_manage_team_a):
        return False

    else:
        return True
Ejemplo n.º 7
0
def edit_club_contacts(request, club_id):
    club = get_object_or_404(Club, pk=club_id)
    user = request.user
    can_manage = False

    if can_manage_club(user.id, club_id):
        can_manage = True

    if not can_manage:
        return HttpResponseForbidden()

    if request.method == 'GET':
        formset = ClubManagementFormSet(
            queryset=ClubManagementPosition.objects.filter(club=club),
            form_kwargs={'club': club})
        for form in formset:
            form.fields['holder'].queryset = Member.objects.none()

    elif request.method == 'POST':
        formset = ClubManagementFormSet(
            request.POST,
            queryset=ClubManagementPosition.objects.filter(club=club),
            form_kwargs={'club': club})
        for form in formset:
            form.fields['holder'].queryset = Member.objects.filter(club=club)

        for form in formset.extra_forms:
            form.instance.club = club

        if formset.is_valid():
            formset.save()

        formset = ClubManagementFormSet(
            queryset=ClubManagementPosition.objects.filter(club=club),
            form_kwargs={'club': club})
        for form in formset:
            form.fields['holder'].queryset = Member.objects.filter(club=club)

    else:
        return HttpResponseBadRequest()

    return render(request, 'clubs/contacts/edit.html', {
        'formset': formset,
        'helper': ClubManagementFormSetHelper()
    })
Ejemplo n.º 8
0
def detail(request, club_id):
    club = get_object_or_404(Club, pk=club_id)
    can_manage = False
    user = request.user

    if user.is_authenticated:
        if can_manage_club(user.id, club_id):
            can_manage = True

    if club.secondary_colour == '#000000':
        light_or_dark = 'dark'
    else:
        light_or_dark = 'light'

    return render(request, 'clubs/detail.html', {
        'club': club,
        'can_manage': can_manage,
        'light_or_dark': light_or_dark
    })
Ejemplo n.º 9
0
def request_transfer(request, club_id):
    club = get_object_or_404(Club, pk=club_id)
    can_manage = False
    user = request.user

    if can_manage_club(user.id, club_id):
        can_manage = True

    if not can_manage:
        return HttpResponseForbidden()

    if request.method == 'POST':

        form = TransferRequestForm(request.POST, request.FILES)

        if form.is_valid():

            if 'evidence' in form.files:
                evidence = form.files['evidence']
            else:
                evidence = None

            now = datetime.datetime.now()
            transfer_request = TransferRequest(
                datetime_submitted=now,
                submitter=user.member,
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                date_of_birth=form.cleaned_data['date_of_birth'],
                transfer_from=form.cleaned_data['transfer_from'],
                transfer_to=club,
                evidence=evidence)
            transfer_request.save()

            msg_html = render_to_string('email/transfer-request-email.html',
                                        {'request': transfer_request})
            msg_plain = render_to_string('email/transfer-request-email.txt',
                                         {'request': transfer_request})

            send_mail(
                'Transfer Request',
                msg_plain,
                '*****@*****.**',
                [
                    '*****@*****.**', '*****@*****.**',
                    '*****@*****.**'
                ],
                html_message=msg_html,
            )

            return render(request, 'clubs/members/transfer-request-sent.html')

    elif request.method == 'GET':

        form = TransferRequestForm()

    else:
        return HttpResponseBadRequest()

    return render(request, 'clubs/members/transfer-request.html',
                  {'form': form})
Ejemplo n.º 10
0
    def dispatch(self, request, *args, **kwargs):

        if not can_manage_club(request.user.id, self.kwargs['club_id']):
            return HttpResponseForbidden()

        return super(MemberDetail, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 11
0
def detail(request, fixture_id):
    fixture = get_object_or_404(Fixture, pk=fixture_id)
    can_manage_fixture = False
    can_manage_team_a = False
    can_manage_team_b = False
    can_administrate = False
    rearrangements_allowed = has_config_item(fixture.competition,
                                             'rearrangements_allowed')
    user = request.user

    if fixture.metadata is None:
        fixture.metadata = FixtureMetadata()

    if user.is_authenticated:
        if can_manage_club(user.id, fixture.team_a.club.id):
            can_manage_fixture = True
            can_manage_team_a = True
        if can_manage_club(user.id, fixture.team_b.club.id):
            can_manage_fixture = True
            can_manage_team_b = True
        if can_administrate_competition(user.id, fixture.competition.id):
            can_administrate = True

    metadata = fixture.metadata

    has_occurred = fixture.date <= datetime.now().date()

    squad_a_selected = metadata.squad_a_selected
    squad_b_selected = metadata.squad_b_selected
    squads_selected = squad_a_selected and squad_b_selected

    can_select_squad_a = not squad_a_selected and (can_manage_team_a
                                                   or can_administrate)
    can_select_squad_b = not squad_b_selected and (
        (can_manage_team_a and has_occurred) or can_manage_team_b
        or can_administrate)

    match_card_completed = squads_selected and metadata.match_card_image is not None \
                           and metadata.personal_penalties_submitted and metadata.scorers_submitted

    can_complete_card = squads_selected and not match_card_completed and has_occurred \
                        and (can_manage_team_a or can_administrate)

    is_cancelled = fixture.fixturecancellation_set.count() > 0

    squad_a = Appearance.objects.filter(fixture=fixture, team=fixture.team_a)
    squad_b = Appearance.objects.filter(fixture=fixture, team=fixture.team_b)

    squads = itertools.zip_longest(squad_a, squad_b)

    context = {
        'fixture': fixture,
        'squads': squads,
        'can_manage': can_manage_fixture,
        'can_select_squad_a': can_select_squad_a,
        'can_select_squad_b': can_select_squad_b,
        'can_complete_card': can_complete_card,
        'squad_a_selected': squad_a_selected,
        'squad_b_selected': squad_b_selected,
        'squads_selected': squads_selected,
        'card_complete': match_card_completed,
        'can_administrate': can_administrate,
        'has_occurred': has_occurred,
        'rearrangements_allowed': rearrangements_allowed,
        'is_cancelled': is_cancelled
    }

    return render(request, 'fixtures/detail.html', context)