Skip to content

Commit bf5e702

Browse files
committed
Show teams when their code was used
1 parent 3d8c1ef commit bf5e702

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

code_submitter/server.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
22
import zipfile
3+
import itertools
34
from typing import cast
45

56
import databases
@@ -16,7 +17,7 @@
1617

1718
from . import auth, utils, config
1819
from .auth import User, BLUESHIRT_SCOPE
19-
from .tables import Archive, Session, ChoiceHistory
20+
from .tables import Archive, Session, ChoiceHistory, ChoiceForSession
2021

2122
database = databases.Database(config.DATABASE_URL, force_rollback=config.TESTING)
2223
templates = Jinja2Templates(directory='templates')
@@ -52,11 +53,33 @@ async def homepage(request: Request) -> Response:
5253
sessions = await database.fetch_all(
5354
Session.select().order_by(Session.c.created.desc()),
5455
)
56+
sessions_and_archives = await database.fetch_all(
57+
select([
58+
Archive.c.id,
59+
Session.c.name,
60+
]).select_from(
61+
Archive.join(ChoiceHistory).join(ChoiceForSession).join(Session),
62+
).where(
63+
Archive.c.id.in_(x['id'] for x in uploads),
64+
).order_by(
65+
Archive.c.id,
66+
),
67+
)
68+
print(sessions_and_archives)
69+
sessions_by_upload = {
70+
grouper: [x['name'] for x in items]
71+
for grouper, items in itertools.groupby(
72+
sessions_and_archives,
73+
key=lambda y: cast(int, y['id']),
74+
)
75+
}
76+
print(sessions_by_upload)
5577
return templates.TemplateResponse('index.html', {
5678
'request': request,
5779
'chosen': chosen,
5880
'uploads': uploads,
5981
'sessions': sessions,
82+
'sessions_by_upload': sessions_by_upload,
6083
'BLUESHIRT_SCOPE': BLUESHIRT_SCOPE,
6184
})
6285

templates/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ <h3>Upload a new submission for team {{ request.user.team }}</h3>
125125
{% endif %}
126126
</div>
127127
<div class="row">
128-
<div class="col-sm-6">
128+
<div class="col-sm-9">
129129
<h3>Your team's uploads</h3>
130130
<table class="table table-striped">
131131
<tr>
132132
<th scope="col">Id</th>
133133
<th scope="col">Uploaded</th>
134134
<th scope="col">By</th>
135135
<th scope="col">Selected</th>
136+
<th scope="col">Sessions</th>
136137
</tr>
137138
{% for upload in uploads %}
138139
<tr
@@ -149,6 +150,7 @@ <h3>Your team's uploads</h3>
149150
</span>
150151
{% endif %}
151152
</td>
153+
<td>{{ ', '.join(sessions_by_upload.get(upload.id, ())) }}</td>
152154
</tr>
153155
{% endfor %}
154156
</table>

0 commit comments

Comments
 (0)