forked from 2i2c-org/frx-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also commit missed redo of the evaluator loop
- Loading branch information
Showing
10 changed files
with
176 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "page.html" %} | ||
|
||
|
||
{% block body %} | ||
|
||
<h1>Add someone to team {{team.name}}</h1> | ||
|
||
<form class="form" action="{% url 'teams-add-member' team.id %}" method="post" enctype="multipart/form-data"> | ||
{% csrf_token %} | ||
{{ form }} | ||
<input class="form-control btn btn-primary mt-2" type="submit" value="Submit"> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "page.html" %} | ||
|
||
|
||
{% block body %} | ||
|
||
<h1>Create a team</h1> | ||
|
||
<form class="form" action="{% url 'teams-create' %}" method="post" enctype="multipart/form-data"> | ||
{% csrf_token %} | ||
{{ form }} | ||
<input class="form-control btn btn-primary mt-2" type="submit" value="Submit"> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "page.html" %} | ||
|
||
{% block body %} | ||
|
||
<h2>List of Teams you are a part of</h2> | ||
<a href="{% url 'teams-create' %}" class="btn btn-secondary">Create a new team</a> | ||
|
||
<ul> | ||
{% for t in teams %} | ||
<li><a href="{% url 'teams-view' t.id %}">{{ t.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends "page.html" %} | ||
|
||
{% block body %} | ||
|
||
<h2>{{ team.name }}</h2> | ||
|
||
<h3>Members</h3> | ||
<a href="{% url 'teams-add-member' team.id %}" class="btn btn-secondary">Add users to this team</a> | ||
|
||
<ul> | ||
{% for u in team.members.all %} | ||
<li>{{ u.username }}</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
from .views import default, teams | ||
|
||
urlpatterns = [ | ||
path("upload", views.upload, name="upload"), | ||
path("results", views.results, name="results"), | ||
path("", views.home, name="home") | ||
path("upload", default.upload, name="upload"), | ||
path("results", default.results, name="results"), | ||
path("teams/list", teams.list, name="teams-list"), | ||
path("teams/create", teams.create, name="teams-create"), | ||
path("teams/<int:id>", teams.view, name="teams-view"), | ||
path("teams/<int:id>/add-member", teams.add_member, name="teams-add-member"), | ||
path("", default.home, name="home") | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
import tempfile | ||
from django.shortcuts import render | ||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, Http404 | ||
from django.urls import reverse | ||
from django import forms | ||
from django.contrib.auth.decorators import login_required | ||
from django.contrib.auth.models import User | ||
from ..models import Team, TeamMembership | ||
from django.conf import settings | ||
|
||
@login_required | ||
def list(request: HttpRequest) -> HttpResponse: | ||
teams = request.user.teams.all() | ||
|
||
return render(request, 'teams/list.html', { | ||
'teams': teams | ||
}) | ||
|
||
|
||
class TeamForm(forms.Form): | ||
name = forms.CharField(max_length=1024) | ||
|
||
|
||
@login_required | ||
def create(request: HttpRequest) -> HttpResponse: | ||
if request.method == "POST": | ||
form = TeamForm(request.POST) | ||
if form.is_valid(): | ||
team = Team() | ||
team.name = form.cleaned_data['name'] | ||
# FIXME: Transactions? | ||
team.save() | ||
membership = TeamMembership() | ||
membership.user = request.user | ||
membership.team = team | ||
membership.is_admin = True | ||
membership.save() | ||
return HttpResponseRedirect(reverse('teams-view', args=(team.id, ))) | ||
else: | ||
form = TeamForm() | ||
return render(request, "teams/create.html", {"form": form}) | ||
|
||
# Intentionally not authenticated, as anyone should be able to view team membership | ||
def view(request: HttpRequest, id: int) -> HttpResponse: | ||
try: | ||
team = Team.objects.filter(id=id).get() | ||
except Team.DoesNotExist: | ||
raise Http404("The requested team does not exist") | ||
|
||
return render(request, "teams/view.html", {"team": team}) | ||
|
||
|
||
|
||
class AddMemberForm(forms.Form): | ||
username = forms.CharField(max_length=1024) | ||
is_admin = forms.BooleanField(required=False) | ||
|
||
@login_required | ||
def add_member(request: HttpRequest, id: int) -> HttpRequest: | ||
try: | ||
team = Team.objects.filter(id=id).get() | ||
except Team.DoesNotExist: | ||
raise Http404("The requested team does not exist") | ||
|
||
# FIXME: Validate that we are admin on the team so we can add people | ||
if request.method == "POST": | ||
form = AddMemberForm(request.POST) | ||
if form.is_valid(): | ||
# FIXME: Handle missing users | ||
# FIXME: Handle an 'invitation acceptance' flow for users | ||
user = User.objects.filter(username=form.cleaned_data['username']).get() | ||
membership = TeamMembership() | ||
membership.user = user | ||
membership.team = team | ||
membership.is_admin = form.cleaned_data['is_admin'] | ||
membership.save() | ||
return HttpResponseRedirect(reverse('teams-view', args=(team.id, ))) | ||
else: | ||
form = AddMemberForm() | ||
return render(request, "teams/add-member.html", {"form": form, "team": team}) |