示例#1
0
    def dispatch(self, request, *args, **kwargs):
        tournament = self.tournament
        if tournament.current_round_id is None:
            full_path = self.request.get_full_path()
            if hasattr(self.request, 'user') and self.request.user.is_superuser:
                logger.warning("Current round wasn't set, redirecting to set-current-round page")
                set_current_round_url = reverse_tournament('tournament-set-current-round', self.tournament)
                redirect_url = add_query_parameter(set_current_round_url, 'next', full_path)
                return HttpResponseRedirect(redirect_url)
            else:
                logger.warning("Current round wasn't set, redirecting to site index")
                messages.warning(request, _("There's a problem with the data for the tournament "
                    "%(tournament_name)s. Please contact a tab director and ask them to set its "
                    "current round.") % {'tournament_name': tournament.name})
                home_url = reverse('tabbycat-index')
                redirect_url = add_query_parameter(home_url, 'redirect', 'false')
                return HttpResponseRedirect(redirect_url)

        try:
            return super().dispatch(request, *args, **kwargs)
        except (MultipleDebateTeamsError, NoDebateTeamFoundError) as e:
            if hasattr(self.request, 'user') and self.request.user.is_superuser:
                logger.warning("Debate team side assignment error, redirecting to tournament-fix-debate-teams")
                messages.warning(request, _("You've been redirected to this page because of a problem with "
                        "how teams are assigned to sides in a debate."))
                return redirect_tournament('tournament-fix-debate-teams', tournament)
            else:
                logger.warning("Debate team side assignment error, redirecting to tournament-public-index")
                messages.warning(request, _("There's a problem with how teams are assigned to sides "
                        "in a debate. The tab director will need to resolve this issue."))
                return redirect_tournament('tournament-public-index', tournament)
示例#2
0
    def dispatch(self, request, *args, **kwargs):
        t = self.tournament

        if not getattr(settings, 'DISABLE_SENTRY', False):
            with configure_scope() as scope:
                scope.set_extra(
                    'tab_director_email',
                    getattr(settings, 'TAB_DIRECTOR_EMAIL', "not provided"))
                scope.set_extra('tournament_prefs',
                                self.tournament.preferences.all())

        # Lack of current_round caused by creating a tournament without rounds
        if t.current_round is None:
            if hasattr(self.request,
                       'user') and self.request.user.is_superuser:
                messages.warning(
                    request,
                    _("You've been redirected to this "
                      "page because tournament %(tournament_name)s has no rounds."
                      "Please create some before returning to the admin site")
                    % {'tournament_name': t.name})
                admin_url = reverse('admin:tournaments_round_changelist')
                return redirect(admin_url)
            else:
                logger.warning(
                    "Current round wasn't set, redirecting to site index")
                messages.warning(
                    request,
                    _("There's a problem with the data "
                      "for the tournament %(tournament_name)s. Please contact a "
                      "tab director and ask them to investigate.") %
                    {'tournament_name': t.name})
                return redirect('tabbycat-index')

        try:
            return super().dispatch(request, *args, **kwargs)
        except (MultipleDebateTeamsError, NoDebateTeamFoundError):
            if hasattr(self.request,
                       'user') and self.request.user.is_superuser:
                logger.warning(
                    "Debate team side assignment error, redirecting "
                    "to tournament-fix-debate-teams")
                messages.warning(
                    request,
                    _("You've been redirected to this "
                      "page because of a problem with how teams are assigned to "
                      "sides in a debate."))
                return redirect_tournament('tournament-fix-debate-teams', t)
            else:
                logger.warning(
                    "Debate team side assignment error, redirecting "
                    "to tournament-public-index")
                messages.warning(
                    request,
                    _("There's a problem with how teams "
                      "are assigned to sides in a debate. The tab director will "
                      "need to resolve this issue."))
                return redirect_tournament('tournament-public-index', t)
示例#3
0
    def post(self, request, *args, **kwargs):
        source = request.POST.get("source", "")

        try:
            management.call_command(importtournament.Command(),
                                    source,
                                    force=True,
                                    strict=False)
        except TournamentDataImporterError as e:
            messages.error(
                self.request,
                mark_safe(
                    "<p>There were one or more errors creating the demo tournament. "
                    "Before retrying, please delete the existing demo tournament "
                    "<strong>and</strong> the institutions in the Edit Database Area.</p>"
                    "<p><i>Technical information: The errors are as follows:"
                    "<ul>" + "".join("<li>{}</li>".format(message)
                                     for message in e.itermessages()) +
                    "</ul></i></p>"))
            logger.error("Error importing demo tournament: " + str(e))
            return redirect('tabbycat-index')
        else:
            messages.success(
                self.request, "Created new demo tournament. You "
                "can now configure it below.")

        new_tournament = Tournament.objects.get(slug=source)
        return redirect_tournament('tournament-configure',
                                   tournament=new_tournament)
示例#4
0
    def post(self, request, *args, **kwargs):
        source = request.POST.get("source", "")

        if source not in ['minimal8team', 'australs24team', 'bp88team']:
            return HttpResponseBadRequest("%s isn't a demo dataset" % source)

        try:
            management.call_command(importtournament.Command(),
                                    source,
                                    force=True,
                                    strict=False,
                                    encoding='utf-8')
        except TournamentDataImporterError as e:
            messages.error(
                self.request,
                mark_safe(
                    _(
                        "<p>There were one or more errors creating the demo tournament. "
                        "Before retrying, please delete the existing demo tournament "
                        "<strong>and</strong> the institutions in the Edit Database Area.</p>"
                        "<p><i>Technical information: The errors are as follows:</i></p>",
                    ) + "<ul><li><i>" +
                    "</i></li><li><i>".join(e.itermessages()) +
                    "</i></li></ul>"))
            logger.error("Error importing demo tournament: " + str(e))
            return redirect('tabbycat-index')
        else:
            messages.success(
                self.request,
                _("Created new demo tournament. You "
                  "can now configure it below."))

        new_tournament = Tournament.objects.get(slug=source)
        return redirect_tournament('tournament-configure',
                                   tournament=new_tournament)
示例#5
0
文件: views.py 项目: czlee/tabbycat
    def post(self, request, *args, **kwargs):
        # Advance relative to the round of the view, not the current round, so
        # that in times of confusion, going back then clicking again won't advance
        # twice.
        next_round = self.tournament.round_set.filter(seq__gt=self.round.seq).order_by('seq').first()

        if next_round:
            self.tournament.current_round = next_round
            self.tournament.save()
            self.log_action(round=next_round, content_object=next_round)

            if (next_round.stage == Round.STAGE_ELIMINATION and
                    self.round.stage == Round.STAGE_PRELIMINARY):
                messages.success(request, _("The current round has been advanced to %(round)s. "
                        "You've made it to the end of the preliminary rounds! Congratulations! "
                        "The next step is to generate the break.") % {'round': next_round.name})
                return redirect_tournament('breakqual-index', self.tournament)
            else:
                messages.success(request, _("The current round has been advanced to %(round)s. "
                    "Woohoo! Keep it up!") % {'round': next_round.name})
                return redirect_round('availability-index', next_round)

        else:
            messages.error(request, _("Whoops! Could not advance round, because there's no round "
                "after this round!"))
            return super().post(request, *args, **kwargs)
示例#6
0
文件: views.py 项目: molins/tabbycat
    def post(self, request, *args, **kwargs):
        # Advance relative to the round of the view, not the current round, so
        # that in times of confusion, going back then clicking again won't advance
        # twice.
        next_round = self.tournament.round_set.filter(
            seq__gt=self.round.seq).order_by('seq').first()

        if next_round:
            self.tournament.current_round = next_round
            self.tournament.save()
            self.log_action(round=next_round, content_object=next_round)

            if (next_round.stage == Round.STAGE_ELIMINATION
                    and self.round.stage == Round.STAGE_PRELIMINARY):
                messages.success(
                    request,
                    _("The current round has been advanced to %(round)s. "
                      "You've made it to the end of the preliminary rounds! Congratulations! "
                      "The next step is to generate the break.") %
                    {'round': next_round.name})
                return redirect_tournament('breakqual-index', self.tournament)
            else:
                messages.success(
                    request,
                    _("The current round has been advanced to %(round)s. "
                      "Woohoo! Keep it up!") % {'round': next_round.name})
                return redirect_round('availability-index', next_round)

        else:
            messages.error(
                request,
                _("Whoops! Could not advance round, because there's no round "
                  "after this round!"))
            return super().post(request, *args, **kwargs)
示例#7
0
def index(request):
    tournaments = Tournament.objects.all()
    if tournaments.count() == 1:
        if request.user.is_authenticated():
            logger.debug('One tournament only, user is: %s, redirecting to tournament-admin-home', request.user)
            return redirect_tournament('tournament-admin-home', tournaments.first())
        else:
            logger.debug('One tournament only, user is: %s, redirecting to tournament-public-index', request.user)
            return redirect_tournament('tournament-public-index', tournaments.first())

    elif not tournaments.exists() and not User.objects.exists():
        logger.debug('No users and no tournaments, redirecting to blank-site-start')
        return redirect('blank-site-start')

    else:
        return render(request, 'site_index.html', dict(tournaments=tournaments))
示例#8
0
def create_division(request, t):
    division = Division.objects.create(name="temporary_name", tournament=t)
    division.save()
    division.name = "%s" % division.id
    division.save()

    return redirect_tournament('division_allocations', t)
示例#9
0
文件: views.py 项目: czlee/tabbycat
 def formset_valid(self, formset):
     result = super().formset_valid(formset)
     nsaved = len(self.instances)
     ndeleted = len(formset.deleted_objects)
     self.add_message(nsaved, ndeleted)
     if "add_more" in self.request.POST:
         return redirect_tournament(self.same_view, self.tournament)
     return result
示例#10
0
 def formset_valid(self, formset):
     result = super().formset_valid(formset)
     nsaved = len(self.instances)
     ndeleted = len(formset.deleted_objects)
     self.add_message(nsaved, ndeleted)
     if "add_more" in self.request.POST:
         return redirect_tournament(self.same_view, self.tournament)
     return result
示例#11
0
 def dispatch(self, request, *args, **kwargs):
     tournament = self.get_tournament()
     if tournament.pref(self.public_page_preference):
         return super().dispatch(request, *args, **kwargs)
     else:
         logger.error("Tried to access a disabled public page")
         messages.error(self.request, self.get_disabled_message())
         return redirect_tournament('tournament-public-index', tournament)
示例#12
0
    def post(self, request, *args, **kwargs):
        self.round.completed = True
        self.round.save()
        self.log_action(round=self.round, content_object=self.round)

        incomplete_rounds = self.tournament.round_set.filter(completed=False)

        if not incomplete_rounds.exists():
            messages.success(request, _("%(round)s has been marked as completed. "
                "All rounds are now completed, so you're done with the tournament! "
                "Congratulations!") % {'round': self.round.name})
            return redirect_tournament('tournament-admin-home', self.tournament)

        elif not self.round.next:
            messages.success(request, _("%(round)s has been marked as completed. "
                "That's the last round in that sequence! Going back to the first "
                "round that hasn't been marked as completed.") % {'round': self.round.name})
            # guaranteed to exist, otherwise the first 'if' statement would have been false
            round_for_redirect = incomplete_rounds.order_by('seq').first()
            return redirect_round('availability-index', round_for_redirect)

        if (self.round.stage == Round.STAGE_PRELIMINARY and
                self.round.next.stage == Round.STAGE_ELIMINATION):

            incomplete_prelim_rounds = incomplete_rounds.filter(stage=Round.STAGE_PRELIMINARY)

            if not incomplete_prelim_rounds.exists():
                messages.success(request, _("%(round)s has been marked as completed. "
                    "You've made it to the end of the preliminary rounds! Congratulations! "
                    "The next step is to generate the break.") % {'round': self.round.name})
                return redirect_tournament('breakqual-index', self.tournament)

            else:
                messages.success(request, _("%(round)s has been marked as completed. "
                    "That was the last preliminary round, but one or more preliminary "
                    "rounds are still not completed. Going back to the first incomplete "
                    "preliminary round.") % {'round': self.round.name})
                round_for_redirect = incomplete_prelim_rounds.order_by('seq').first()
                return redirect_round('availability-index', round_for_redirect)

        else:
            messages.success(request, _("%(this_round)s has been marked as completed. "
                "Moving on to %(next_round)s! Woohoo! Keep it up!") % {
                'this_round': self.round.name, 'next_round': self.round.next.name,
            })
            return redirect_round('availability-index', self.round.next)
示例#13
0
文件: views.py 项目: tfpk/tabbycat
 def get(self, request, *args, **kwargs):
     self.object = self.get_object()
     if not self.object.public:
         logger.warning(
             "Tried to access a non-public speaker category tab page: %s",
             self.object.slug)
         messages.error(self.request, self.get_disabled_message())
         return redirect_tournament('tournament-public-index',
                                    self.get_tournament())
     return super().get(request, *args, **kwargs)
示例#14
0
文件: views.py 项目: czlee/tabbycat
 def get(self, request, *args, **kwargs):
     tournaments = Tournament.objects.all()
     if tournaments.count() == 1 and not request.user.is_authenticated:
         logger.debug("One tournament only, user is: %s, redirecting to tournament-public-index", request.user)
         return redirect_tournament("tournament-public-index", tournaments.first())
     elif not tournaments.exists() and not User.objects.exists():
         logger.debug("No users and no tournaments, redirecting to blank-site-start")
         return redirect("blank-site-start")
     else:
         return super().get(request, *args, **kwargs)
示例#15
0
 def formset_valid(self, formset):
     result = super().formset_valid(formset)
     if self.instances:
         count = len(self.instances)
         message = ungettext("Saved %(count)d venue constraint.",
             "Saved %(count)d venue constraints.", count) % {'count': count}
         messages.success(self.request, message)
     if "add_more" in self.request.POST:
         return redirect_tournament('venues-constraints', self.get_tournament())
     return result
示例#16
0
 def dispatch(self, request, *args, **kwargs):
     tournament = self.get_tournament()
     if self.public_page_preference is None:
         raise ImproperlyConfigured("public_page_preference isn't set on this view.")
     if tournament.pref(self.public_page_preference):
         return super().dispatch(request, *args, **kwargs)
     else:
         logger.error("Tried to access a disabled public page")
         messages.error(self.request, self.get_disabled_message())
         return redirect_tournament('tournament-public-index', tournament)
示例#17
0
 def dispatch(self, request, *args, **kwargs):
     tournament = self.get_tournament()
     if tournament is None:
         messages.info(self.request, _("That tournament no longer exists."))
         return redirect('tabbycat-index')
     if self.is_page_enabled(tournament):
         return super().dispatch(request, *args, **kwargs)
     else:
         logger.warning("Tried to access a disabled public page")
         messages.error(self.request, self.get_disabled_message())
         return redirect_tournament('tournament-public-index', tournament)
示例#18
0
 def formset_valid(self, formset):
     result = super().formset_valid(formset)
     if self.instances:
         messages.success(
             self.request,
             _("Saved %(count)d venue constraints.") %
             {'count': len(self.instances)})
     if "add_more" in self.request.POST:
         return redirect_tournament('venues-constraints',
                                    self.get_tournament())
     return result
示例#19
0
 def get(self, request, *args, **kwargs):
     tournaments = Tournament.objects.all()
     if request.GET.get('redirect', '') == 'false':
         return super().get(request, *args, **kwargs)
     if tournaments.count() == 1 and not request.user.is_authenticated:
         logger.debug('One tournament only, user is: %s, redirecting to tournament-public-index', request.user)
         return redirect_tournament('tournament-public-index', tournaments.first())
     elif not tournaments.exists() and not User.objects.exists():
         logger.debug('No users and no tournaments, redirecting to blank-site-start')
         return redirect('blank-site-start')
     else:
         return super().get(request, *args, **kwargs)
示例#20
0
文件: views.py 项目: czlee/tabbycat
 def formset_valid(self, formset):
     result = super().formset_valid(formset)
     if self.instances:
         message = ngettext("Saved speaker category: %(list)s",
             "Saved speaker categories: %(list)s",
             len(self.instances)
         ) % {'list': ", ".join(category.name for category in self.instances)}
         messages.success(self.request, message)
     else:
         messages.success(self.request, _("No changes were made to the speaker categories."))
     if "add_more" in self.request.POST:
         return redirect_tournament('participants-speaker-categories-edit', self.tournament)
     return result
示例#21
0
 def formset_valid(self, formset):
     result = super().formset_valid(formset)
     if self.instances:
         messages.success(
             self.request,
             _("Saved venue categories: %(list)s") % {
                 'list': ", ".join(category.name
                                   for category in self.instances)
             })
     if "add_more" in self.request.POST:
         return redirect_tournament('venues-categories',
                                    self.get_tournament())
     return result
示例#22
0
 def formset_valid(self, formset):
     result = super().formset_valid(formset)
     if self.instances:
         message = ungettext("Saved venue category: %(list)s",
             "Saved venue categories: %(list)s",
             len(self.instances)
         ) % {'list': ", ".join(category.name for category in self.instances)}
         messages.success(self.request, message)
     else:
         messages.success(self.request, _("No changes were made to the venue categories."))
     if "add_more" in self.request.POST:
         return redirect_tournament('venues-categories', self.get_tournament())
     return result
示例#23
0
文件: mixins.py 项目: modale/tabbycat
 def dispatch(self, request, *args, **kwargs):
     tournament = self.get_tournament()
     if tournament is None:
         messages.info(self.request, "That tournament no longer exists.")
         return redirect('tabbycat-index')
     if self.public_page_preference is None:
         raise ImproperlyConfigured(
             "public_page_preference isn't set on this view.")
     if tournament.pref(self.public_page_preference):
         return super().dispatch(request, *args, **kwargs)
     else:
         logger.error("Tried to access a disabled public page")
         messages.error(self.request, self.get_disabled_message())
         return redirect_tournament('tournament-public-index', tournament)
示例#24
0
def create_division_allocation(request, t):
    from tournaments.division_allocator import DivisionAllocator

    teams = list(Team.objects.filter(tournament=t))
    institutions = Institution.objects.all()
    venue_groups = VenueGroup.objects.all()

    # Delete all existing divisions - this shouldn't affect teams (on_delete=models.SET_NULL))
    divisions = Division.objects.filter(tournament=t).delete()

    alloc = DivisionAllocator(teams=teams, divisions=divisions, venue_groups=venue_groups, tournament=t, institutions=institutions)
    success = alloc.allocate()

    if success:
        return redirect_tournament('division_allocations', t)
    else:
        return HttpResponseBadRequest("Couldn't create divisions")
示例#25
0
def create_byes(request, t):
    divisions = Division.objects.filter(tournament=t)
    Team.objects.filter(tournament=t, type=Team.TYPE_BYE).delete()
    for division in divisions:
        teams_count = Team.objects.filter(division=division).count()
        if teams_count % 2 != 0:
            bye_institution, created = Institution.objects.get_or_create(
                name="Byes", code="Byes")
            bye_team = Team(
                institution=bye_institution,
                reference="Bye for Division " + division.name,
                short_reference="Bye",
                tournament=t,
                division=division,
                use_institution_prefix=False,
                type=Team.TYPE_BYE
            ).save()

    return redirect_tournament('division_allocations', t)
示例#26
0
    def formset_valid(self, formset):
        self.instances = formset.save(commit=False)
        if self.instances:
            for category in self.instances:
                category.tournament = self.tournament

            message = ngettext(
                "Saved room category: %(list)s",
                "Saved venue categories: %(list)s",
                len(self.instances),
            ) % {
                'list': ", ".join(category.name for category in self.instances)
            }
            messages.success(self.request, message)
        else:
            messages.success(self.request,
                             _("No changes were made to the room categories."))

        if "add_more" in self.request.POST:
            return redirect_tournament('venues-categories', self.tournament)
        return super().formset_valid(formset)
示例#27
0
文件: views.py 项目: czlee/tabbycat
    def post(self, request, *args, **kwargs):
        source = request.POST.get("source", "")

        try:
            management.call_command(importtournament.Command(), source,
                                    force=True, strict=False)
        except TournamentDataImporterError as e:
            messages.error(self.request, mark_safe(
                "<p>There were one or more errors creating the demo tournament. "
                "Before retrying, please delete the existing demo tournament "
                "<strong>and</strong> the institutions in the Edit Database Area.</p>"
                "<p><i>Technical information: The errors are as follows:"
                "<ul>" + "".join("<li>{}</li>".format(message) for message in e.itermessages()) + "</ul></i></p>"
            ))
            logger.error("Error importing demo tournament: " + str(e))
            return redirect('tabbycat-index')
        else:
            messages.success(self.request, "Created new demo tournament. You "
                "can now configure it below.")

        new_tournament = Tournament.objects.get(slug=source)
        return redirect_tournament('tournament-configure', tournament=new_tournament)