|
6 | 6 | # Copyright © 2010-2012 Matteo Boscariol <[email protected]> |
7 | 7 | # Copyright © 2012-2018 Luca Wehrstedt <[email protected]> |
8 | 8 | # Copyright © 2013 Bernard Blackham <[email protected]> |
| 9 | +# Copyright © 2025 Pasit Sangprachathanarak <[email protected]> |
9 | 10 | # |
10 | 11 | # This program is free software: you can redistribute it and/or modify |
11 | 12 | # it under the terms of the GNU Affero General Public License as |
@@ -116,6 +117,12 @@ class Task(Base): |
116 | 117 | nullable=False, |
117 | 118 | default=[]) |
118 | 119 |
|
| 120 | + # The list of names of programming languages allowed for this task. |
| 121 | + # If null, all contest languages are allowed. |
| 122 | + allowed_languages: list[str] | None = Column( |
| 123 | + ARRAY(String), nullable=True, default=None |
| 124 | + ) |
| 125 | + |
119 | 126 | # The parameters that control task-tokens follow. Note that their |
120 | 127 | # effect during the contest depends on the interaction with the |
121 | 128 | # parameters that control contest-tokens, defined on the Contest. |
@@ -272,6 +279,21 @@ class Task(Base): |
272 | 279 | passive_deletes=True, |
273 | 280 | back_populates="task") |
274 | 281 |
|
| 282 | + def get_allowed_languages(self) -> list[str] | None: |
| 283 | + """Get the list of allowed languages for this task. |
| 284 | +
|
| 285 | + If the task has specific allowed languages configured, return those. |
| 286 | + Otherwise, return the contest's allowed languages. |
| 287 | +
|
| 288 | + return: list of allowed language names, or None if no contest is set |
| 289 | + """ |
| 290 | + # If task has specific language restrictions, use those |
| 291 | + if self.allowed_languages is not None: |
| 292 | + return self.allowed_languages |
| 293 | + |
| 294 | + # Otherwise, use contest language restrictions |
| 295 | + return self.contest.languages if self.contest else None |
| 296 | + |
275 | 297 |
|
276 | 298 | class Statement(Base): |
277 | 299 | """Class to store a translation of the task statement. |
|
0 commit comments