Skip to content

Commit

Permalink
Show teams when their code was used
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJCLaw committed Jan 9, 2021
1 parent 3d8c1ef commit bf5e702
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 24 additions & 1 deletion code_submitter/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import zipfile
import itertools
from typing import cast

import databases
Expand All @@ -16,7 +17,7 @@

from . import auth, utils, config
from .auth import User, BLUESHIRT_SCOPE
from .tables import Archive, Session, ChoiceHistory
from .tables import Archive, Session, ChoiceHistory, ChoiceForSession

database = databases.Database(config.DATABASE_URL, force_rollback=config.TESTING)
templates = Jinja2Templates(directory='templates')
Expand Down Expand Up @@ -52,11 +53,33 @@ async def homepage(request: Request) -> Response:
sessions = await database.fetch_all(
Session.select().order_by(Session.c.created.desc()),
)
sessions_and_archives = await database.fetch_all(
select([
Archive.c.id,
Session.c.name,
]).select_from(
Archive.join(ChoiceHistory).join(ChoiceForSession).join(Session),
).where(
Archive.c.id.in_(x['id'] for x in uploads),
).order_by(
Archive.c.id,
),
)
print(sessions_and_archives)
sessions_by_upload = {
grouper: [x['name'] for x in items]
for grouper, items in itertools.groupby(
sessions_and_archives,
key=lambda y: cast(int, y['id']),
)
}
print(sessions_by_upload)
return templates.TemplateResponse('index.html', {
'request': request,
'chosen': chosen,
'uploads': uploads,
'sessions': sessions,
'sessions_by_upload': sessions_by_upload,
'BLUESHIRT_SCOPE': BLUESHIRT_SCOPE,
})

Expand Down
4 changes: 3 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ <h3>Upload a new submission for team {{ request.user.team }}</h3>
{% endif %}
</div>
<div class="row">
<div class="col-sm-6">
<div class="col-sm-9">
<h3>Your team's uploads</h3>
<table class="table table-striped">
<tr>
<th scope="col">Id</th>
<th scope="col">Uploaded</th>
<th scope="col">By</th>
<th scope="col">Selected</th>
<th scope="col">Sessions</th>
</tr>
{% for upload in uploads %}
<tr
Expand All @@ -149,6 +150,7 @@ <h3>Your team's uploads</h3>
</span>
{% endif %}
</td>
<td>{{ ', '.join(sessions_by_upload.get(upload.id, ())) }}</td>
</tr>
{% endfor %}
</table>
Expand Down

0 comments on commit bf5e702

Please sign in to comment.