Ejemplo n.º 1
0
 def get(self, request: WSGIRequest) -> HttpResponse:
     if not request.user.is_authenticated:
         return redirect('/')
     context = self.get_context(request=request)
     if not context["is_verified"]:
         return redirect('/')
     try:
         challenge = Challenge.objects.get(ended=False,
                                           posted=True,
                                           type='MO')
     except Challenge.DoesNotExist:
         messages.add_message(request, messages.WARNING,
                              'No ongoing code jam.')
         client.send_webhook(
             "Teams",
             f"<@{context['discord_user'].uid}> tried creating a team",
             fields=[{
                 "name": "Error",
                 "value": "There is not codejam ongoing"
             }])
         return redirect('home:home')
     if challenge.team_creation_status == False:
         messages.add_message(request, messages.WARNING,
                              'Team Submissions are closed Right Now')
         client.send_webhook(
             "Teams",
             f"<@{context['discord_user'].uid}> tried creating a team",
             fields=[{
                 "name": "Error",
                 "value": "Team submissions are closed"
             }])
         return redirect('home:home')
     return render(request=request,
                   template_name="timathon/create_teams.html",
                   context=context)
Ejemplo n.º 2
0
    def get(self, request: WSGIRequest, challenge_id: int):
        if not request.user.is_authenticated:
            messages.add_message(request,
                                 messages.INFO,
                                 'You are not logged in!')
            return redirect('/')

        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect('/')
        if context["is_admin"] or context["is_challenge_host"]:
            challenge = get_object_or_404(Challenge, id=challenge_id)# Challenge.objects.get(id=challenge_id)
            if challenge.team_creation_status or challenge.voting_status:
                messages.add_message(request,
                                     messages.WARNING,
                                     'Stop Team creation or voting first')
                return redirect('timathon:Home')
            challenge.submissions_status = True
            challenge.save()
            messages.add_message(request,
                                 messages.INFO,
                                 'Submissions have been started')
            client.send_webhook("Timathon", f"Submissions have started",
                                fields=[{"name": "Link", "value": f"[Visit]({request.build_absolute_uri('/timathon/')})"}],
                                codeJamInfo=True)
            client.send_webhook("Code Jam", f"<@{context['discord_user'].uid}> has started the submissions",
                                fields=[{"name": "Link", "value": f"[Visit]({request.build_absolute_uri('/timathon/')})"}])
            return redirect('timathon:Home')
 def get(self, request: WSGIRequest):
     if not request.user.is_authenticated:
         return redirect("/")
     context = self.get_context(request=request)
     if not context["is_verified"]:
         return redirect("/")
     user = request.user
     challenge = get_object_or_404(
         Challenge, ended=False, posted=True, type="MO"
     )  # Challenge.objects.get(ended=False, posted=True, type='MO')
     if len(Team.objects.filter(challenge=challenge, members=user)) <= 0:
         messages.add_message(request, messages.WARNING, "You are not in a team !")
         client.send_webhook(
             "Teams",
             f"<@{context['discord_user'].uid}> tried leaving his team",
             [{"name": "error", "value": "They are not in a team"}],
         )
         return redirect("timathon:Home")
     team = get_object_or_404(
         Team, challenge=challenge, members=user
     )  # Team.objects.get(challenge=challenge, members=user)
     team.members.remove(user)
     team.save()
     if len(team.members.all()) == 0:
         team.delete()
     messages.add_message(request, messages.INFO, "Removed you from the team!")
     client.send_webhook(
         "Teams",
         f"<@{context['discord_user'].uid}> left his team",
     )
     return redirect("timathon:Home")
Ejemplo n.º 4
0
    def post(self, request: WSGIRequest, submission_id):
        context = self.get_context(request=request)
        if not context["is_staff"]:
            messages.add_message(
                request, messages.INFO, "Only staff can access the judging panel."
            )
            return redirect("timathon:Home")

        form = VoteForm(request.POST)
        if form.is_valid():
            user = request.user
            submission = get_object_or_404(Submission, id=submission_id)
            challenge = get_object_or_404(
                Challenge, ended=False, posted=True, type="MO"
            )

            # Check if submission is in the ongoing Timathon.
            if submission.team.challenge != challenge:
                messages.add_message(request, messages.INFO, "Invalid submission.")
                return redirect("timathon:Judge")

            c1 = form.cleaned_data["c1"]
            c2 = form.cleaned_data["c2"]
            c3 = form.cleaned_data["c3"]
            c4 = form.cleaned_data["c4"]
            notes = form.cleaned_data["notes"]

            # Check if user has already voted.
            previous_votes = Vote.objects.filter(user=user, submission=submission)
            if previous_votes:
                messages.add_message(
                    request, messages.WARNING, "You cannot add more than 1 vote!"
                )
                return redirect("timathon:Judge")

            new_vote = Vote.objects.create(
                user=user,
                submission=submission,
                c1=c1,
                c2=c2,
                c3=c3,
                c4=c4,
                notes=notes,
            )

            idv_score = c1 + c2 + c3 + c4
            messages.add_message(request, messages.INFO, "Successfully voted!")
            client.send_webhook(
                "Judging",
                f"<@{context['discord_user'].uid}> added a vote!",
                [
                    {"name": "Team", "value": submission.team.ID},
                    {"name": "Individual score", "value": idv_score},
                ],
            )
            return redirect("timathon:Judge")

        messages.add_message(request, messages.WARNING, "Invalid form.")
        return redirect("timathon:Judge")
Ejemplo n.º 5
0
    def get(self, request: WSGIRequest, challenge_id: int):
        if not request.user.is_authenticated:
            messages.add_message(request, messages.INFO,
                                 "You are not logged in!")
            return redirect("/")

        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect("/")
        if context["is_admin"] or context["is_challenge_host"]:
            challenge = get_object_or_404(
                Challenge,
                id=challenge_id)  # Challenge.objects.get(id=challenge_id)
            # try:
            winners = Team.objects.filter(
                challenge=challenge, submitted=True
            ).exclude(
                winner=0
            )  # [Team.objects.get(challenge=challenge,winner=i) for i in range(1,4)]
            # except Team.DoesNotExist:
            if len(winners) == 0:
                messages.add_message(request, messages.WARNING,
                                     "Declare the winning team first")
                return redirect("timathon:Home")
            challenge.ended = True
            challenge.status = "ENDED"
            challenge.team_creation_status = False
            challenge.submissions_status = False
            challenge.save()
            messages.add_message(request, messages.INFO,
                                 "Challenge has been closed!")
            client.send_webhook(
                "Code Jam",
                f"<@{context['discord_user'].uid}> has ended the codejam. Thanks for participating",
                fields=[{
                    "name": "Link",
                    "value": f"[Visit]({request.build_absolute_uri('/')})",
                }],
            )
            client.send_webhook(
                "Timathon",
                f"Timathon has ended. Thanks for participating",
                fields=[{
                    "name": "Link",
                    "value": f"[Visit]({request.build_absolute_uri('/')})",
                }],
                codeJam=True,
            )
            return redirect("/")

        else:
            messages.add_message(
                request,
                messages.INFO,
                "You should be an admin or challenge host to do this!",
            )
            return redirect("/")
Ejemplo n.º 6
0
 def post(self, request: WSGIRequest):
     if not request.user.is_authenticated:
         return redirect("/")
     context = self.get_context(request=request)
     form = SumbissionForm(request.POST)
     if form.is_valid():
         description = form.cleaned_data["description"]
         github_link = form.cleaned_data["github_link"]
         repl_link = form.cleaned_data['repl_link']
         challenge = Challenge.objects.get(type="MO",
                                           ended=False,
                                           posted=True)
         team = get_object_or_404(
             Team, challenge=challenge, members=request.user
         )  # Team.objects.get(challenge=challenge, members=request.user)
         if len(Submission.objects.filter(challenge=challenge,
                                          team=team)) != 0:
             messages.add_message(request, messages.WARNING,
                                  "You have already submitted.")
             client.send_webhook(
                 "Submissions",
                 f"<@{context['discord_user'].uid}> tried submitting more than once",
             )
             return redirect(reverse("home:home"))
         Submission.objects.create(
             github_link=github_link,
             repl_link=repl_link,
             description=description,
             team=team,
             challenge=challenge,
         )
         team.submitted = True
         team.save()
         messages.add_message(
             request,
             messages.INFO,
             "You have successfully submitted your project in the code jam. ",
         )
         client.send_webhook(
             "Submissions",
             f"<@{context['discord_user'].uid}> submitted their project",
             fields=[{
                 "name": "repo",
                 "value": f"{github_link}"
             }],
         )
         return redirect("/")
     print(form.errors)
     print(form["github_link"])
     print("Invalid form")
     messages.add_message(request, messages.WARNING, "Invalid Form")
     return redirect(reverse("timathon:Submission"))
Ejemplo n.º 7
0
    def get(self, request: WSGIRequest, challenge_id: int):
        if not request.user.is_authenticated:
            messages.add_message(request, messages.INFO,
                                 "You are not logged in!")
            return redirect("/")

        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect("/")
        if context["is_admin"] or context["is_challenge_host"]:
            challenge = get_object_or_404(
                Challenge,
                id=challenge_id)  # Challenge.objects.get(id=challenge_id)
            if challenge.team_creation_status or challenge.submissions_status:
                messages.add_message(request, messages.WARNING,
                                     "Stop Team creation or Submission first")
                return redirect("timathon:Home")
            challenge.voting_status = True
            challenge.save()
            messages.add_message(
                request,
                messages.INFO,
                "Voting has been started Go vote now for your favourite projects",
            )
            client.send_webhook(
                "Timathon",
                f"Voting period has been started",
                fields=[{
                    "name":
                    "Link",
                    "value":
                    f"[Visit]({request.build_absolute_uri('/timathon/')})",
                }],
                codeJamInfo=True,
            )
            client.send_webhook(
                "Code Jam",
                f"<@{context['discord_user'].uid}> has started the Voting period",
                fields=[{
                    "name":
                    "Link",
                    "value":
                    f"[Visit]({request.build_absolute_uri('/timathon/')})",
                }],
            )
            return redirect("timathon:Home")
Ejemplo n.º 8
0
 def post(self, request: WSGIRequest):
     if not request.user.is_authenticated:
         return redirect("/")
     context = self.get_context(request=request)
     form = CreateTeamForm(request.POST)
     if form.is_valid():
         user = request.user
         challenge = get_object_or_404(
             Challenge, ended=False, posted=True, type="MO"
         )  # Challenge.objects.get(ended=False, posted=True, type='MO')
         name = form.cleaned_data["name"]
         user_teams = Team.objects.filter(challenge=challenge, members=user)
         if len(user_teams) != 0:
             messages.add_message(request, messages.WARNING,
                                  "You are Already in a Team")
             client.send_webhook(
                 "Teams",
                 f"<@{context['discord_user'].uid}> tried creating a team",
                 fields=[{
                     "name": "Error",
                     "value": "The are already in a team"
                 }],
             )
             return redirect("/")
         new_team = Team.objects.create(name=name, challenge=challenge)
         new_team.members.add(user)
         new_team.save()
         messages.add_message(request, messages.INFO,
                              "Team successfully created!")
         client.send_webhook(
             "Teams",
             f"<@{context['discord_user'].uid}> created a team",
             [
                 {
                     "name": "name",
                     "value": new_team.name
                 },
                 {
                     "name": "invite",
                     "value": str(new_team.invite)
                 },
             ],
         )
         return redirect("timathon:Home")
     messages.add_message(request, messages.WARNING, "Invalid Form")
     return redirect("timathon:Create_Team")
Ejemplo n.º 9
0
    def get(self, request: WSGIRequest, challenge_id: int):
        if not request.user.is_authenticated:
            messages.add_message(request,
                                 messages.INFO,
                                 'You are not logged in!')
            return redirect('/')

        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect('/')
        if context["is_admin"] or context["is_challenge_host"]:
            ongoing_challenges = Challenge.objects.filter(type='MO', ended=False, posted=True)
            if len(ongoing_challenges) >0:
                messages.add_message(request,
                                     messages.INFO,
                                     'There is already a challenge going on')
                return redirect('timathon:Home')
            challenge = get_object_or_404(Challenge, id=challenge_id) # Challenge.objects.get(id=challenge_id)
            challenge.posted = True
            challenge.status = "RUNNING"
            challenge.team_creation_status = True
            challenge.save()
            messages.add_message(request,
                                 messages.INFO,
                                 'Challenge has been posted!')
            client.send_webhook("Timathon", f"Timathon has started Register Now!",
                                fields=[{"name": "Title", "value": challenge.title},
                                        {"name": "Description", "value": challenge.description},
                                        {"name": "Rules", "value": challenge.rules},
                                        {"name": "Link", "value": f"[Visit]({request.build_absolute_uri('/timathon/')})"}],
                                codeJam=True)
            client.send_webhook("Code Jam", f"<@{context['discord_user'].uid}> started the codejam now you can join teams",
                                fields=[{"name": "Title", "value": challenge.title},
                                        {"name": "Description", "value": challenge.description},
                                        {"name": "Rules", "value": challenge.rules},
                                        {"name": "Link", "value": f"[Visit]({request.build_absolute_uri('/timathon/')})"}])
            return redirect('timathon:Home')

        else:
            messages.add_message(request,
                                 messages.INFO,
                                 'You should be an admin or challenge host to do this!')
            return redirect('/')
Ejemplo n.º 10
0
    def get(self, request: WSGIRequest, challenge_id: int):
        if not request.user.is_authenticated:
            messages.add_message(request, messages.INFO,
                                 "You are not logged in!")
            return redirect("/")

        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect("/")
        if context["is_admin"] or context["is_challenge_host"]:
            challenge = get_object_or_404(
                Challenge,
                id=challenge_id)  # Challenge.objects.get(id=challenge_id)
            challenge.submissions_status = False
            challenge.save()
            messages.add_message(request, messages.INFO,
                                 "Submissions Have been stopped")
            client.send_webhook(
                "Timathon",
                f"Submissions for the Timathon have been stopped",
                fields=[{
                    "name":
                    "Link",
                    "value":
                    f"[Visit]({request.build_absolute_uri('/timathon/')})",
                }],
                codeJamInfo=True,
            )
            client.send_webhook(
                "Code Jam",
                f"<@{context['discord_user'].uid}> has stopped accepting submissions for the code jam",
                fields=[{
                    "name":
                    "Link",
                    "value":
                    f"[Visit]({request.build_absolute_uri('/timathon/')})",
                }],
            )
            return redirect("timathon:Home")
Ejemplo n.º 11
0
    def get(self, request: WSGIRequest, challenge_id: int):
        if not request.user.is_authenticated:
            messages.add_message(request, messages.INFO,
                                 'You are not logged in!')
            return redirect('/')

        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect('/')
        if context["is_admin"] or context["is_challenge_host"]:
            challenge = get_object_or_404(
                Challenge,
                id=challenge_id)  # Challenge.objects.get(id=challenge_id)
            challenge.voting_status = False
            challenge.save()
            messages.add_message(request, messages.INFO, 'Voting Has Ended')
            client.send_webhook(
                "Timathon",
                f"Voting period for the Timathon has ended",
                fields=[{
                    "name":
                    "Link",
                    "value":
                    f"[Visit]({request.build_absolute_uri('/timathon/')})"
                }],
                codeJamInfo=True)
            client.send_webhook(
                "Code Jam",
                f"<@{context['discord_user'].uid}> has ended the voting for the code jam",
                fields=[{
                    "name":
                    "Link",
                    "value":
                    f"[Visit]({request.build_absolute_uri('/timathon/')})"
                }])
            return redirect('timathon:Home')
Ejemplo n.º 12
0
    def get(self, request: WSGIRequest, teamid):
        if not request.user.is_authenticated:
            return redirect("/")
        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect("/")
        user = request.user
        discord_user = context["discord_user"]
        team = get_object_or_404(Team,
                                 ID=teamid)  # Team.objects.get(invite=invite)
        challenge = get_object_or_404(
            Challenge, ended=False, posted=True, type="MO"
        )  # Challenge.objects.get(ended=False, posted=True, type='MO')
        user_teams = Team.objects.filter(challenge=challenge, members=user)
        user_voted_teams = Team.objects.filter(challenge=challenge,
                                               voted_by=user)

        if len(user_teams) == 0:
            messages.add_message(request, messages.WARNING,
                                 "You have not participated in the code jam")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "They have not particpated in the code jam",
                }],
            )
            return redirect("/")
        if len(user_voted_teams) == 0:
            messages.add_message(request, messages.WARNING,
                                 "You have not voted yet.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried unvoting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "They have not voted anyone"
                }],
            )
            return redirect("/")
        if team in user_teams:
            messages.add_message(request, messages.WARNING,
                                 "You Cannot unvote for yourself.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried unvoting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "User is in the in the team"
                }],
            )
            return redirect("/")
        if team not in user_voted_teams:
            messages.add_message(request, messages.WARNING,
                                 "You have not voted this team.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried unvoting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "User has not voted the team"
                }],
            )
            return redirect("/")

        if not challenge.voting_status:
            messages.add_message(request, messages.WARNING,
                                 "Challenge Voting is not open.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "Challenge Voting is not open."
                }],
            )
            return redirect("/")
        team.votes = team.votes - 1
        team.voted_by.remove(user)
        team.save()
        messages.add_message(request, messages.WARNING,
                             f"You have successfully unvoted {team.name}")
        client.send_webhook(
            "Teams",
            f"<@{discord_user.uid}> Unvoted **{team.name}** (ID:{team.ID})")
        return redirect("timathon:Home")
Ejemplo n.º 13
0
 def get(self, request: WSGIRequest, invite):
     if not request.user.is_authenticated:
         return redirect('/')
     context = self.get_context(request=request)
     if not context["is_verified"]:
         return redirect('/')
     user = request.user
     discord_user = context['discord_user']
     try:
         team = Team.objects.get(invite=invite)
     except Team.DoesNotExist:
         messages.add_message(request, messages.WARNING,
                              "Team does not exist")
         return redirect('/')
     try:
         challenge = Challenge.objects.get(ended=False,
                                           posted=True,
                                           type='MO')
     except Challenge.DoesNotExist:
         messages.add_message(request, messages.WARNING,
                              "Challenge does not exist")
         return redirect('/')
     user_teams = Team.objects.filter(challenge=challenge, members=user)
     if len(user_teams) != 0:
         messages.add_message(request, messages.WARNING,
                              "You are Already in a Team")
         client.send_webhook(
             "Teams",
             f"<@{discord_user.uid}> tried joining **{team.name}** (ID:{team.ID})",
             fields=[{
                 "name": "Error",
                 "value": "They are already in a team"
             }])
         return redirect('/')
     if not challenge.team_creation_status:
         messages.add_message(request, messages.WARNING,
                              "Team creations and additions have closed.")
         client.send_webhook(
             "Teams",
             f"<@{discord_user.uid}> tried joining **{team.name}** (ID:{team.ID})",
             fields=[{
                 "name": "Error",
                 "value": "Team creations and additions have closed"
             }])
         return redirect('/')
     if len(team.members.all()) >= 6:
         messages.add_message(request, messages.WARNING,
                              "This team is Full.")
         client.send_webhook(
             "Teams",
             f"<@{discord_user.uid}> tried joining **{team.name}** (ID:{team.ID})",
             fields=[{
                 "name": "Error",
                 "value": "Team is full"
             }])
         return redirect('timathon:Home')
     team.members.add(user)
     team.save()
     messages.add_message(request, messages.SUCCESS,
                          f"You have successfully joined {team.name} team")
     client.send_webhook(
         "Teams",
         f"<@{discord_user.uid}> has successfully joined **{team.name}** (ID:{team.ID})"
     )
     return redirect('timathon:Home')
Ejemplo n.º 14
0
    def get(self, request: WSGIRequest, teamid):
        if not request.user.is_authenticated:
            return redirect('/')
        context = self.get_context(request=request)
        if not context["is_verified"]:
            return redirect('/')
        user = request.user
        discord_user = context['discord_user']
        team = get_object_or_404(Team,
                                 ID=teamid)  # Team.objects.get(invite=invite)
        challenge = get_object_or_404(
            Challenge, ended=False, posted=True, type='MO'
        )  #Challenge.objects.get(ended=False, posted=True, type='MO')
        user_teams = Team.objects.filter(challenge=challenge, members=user)
        user_voted_teams = Team.objects.filter(challenge=challenge,
                                               voted_by=user)
        if len(user_teams) == 0:
            messages.add_message(request, messages.WARNING,
                                 "You have not participated in the code jam")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "They have not particpated in the code jam"
                }])
            return redirect('/')
        if len(
                Submission.objects.filter(challenge=challenge,
                                          team=user_teams[0])) == 0:
            messages.add_message(
                request, messages.WARNING,
                "You have not Submitted a project in the code jam")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name":
                    "Error",
                    "value":
                    "They have not Submitted a project in the code jam"
                }])
            return redirect('/')
        if len(user_voted_teams) >= 3:
            messages.add_message(request, messages.WARNING,
                                 "You have exceeded your amount of votes.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "They have exceeded their amount of votes"
                }])
            return redirect('/')
        if team in user_teams:
            messages.add_message(request, messages.WARNING,
                                 "You Cannot vote for yourself.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "User is in the in the team"
                }])
            return redirect('/')
        if team in user_voted_teams:
            messages.add_message(request, messages.WARNING,
                                 "You Cannot vote this team again.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "User has already voted the team"
                }])
            return redirect('/')

        if not challenge.voting_status:
            messages.add_message(request, messages.WARNING,
                                 "Challenge Voting is not open.")
            client.send_webhook(
                "Teams",
                f"<@{discord_user.uid}> tried voting **{team.name}** (ID:{team.ID})",
                fields=[{
                    "name": "Error",
                    "value": "Challenge Voting is not open."
                }])
            return redirect('/')
        team.votes = team.votes + 1
        team.voted_by.add(user)
        team.save()
        messages.add_message(request, messages.WARNING,
                             f"You have successfully voted {team.name}")
        client.send_webhook(
            "Teams",
            f"<@{discord_user.uid}> Voted **{team.name}** (ID:{team.ID})")
        return redirect('timathon:Home')