|
3 | 3 | from grader_service.registry import VersionSpecifier, register_handler |
4 | 4 |
|
5 | 5 |
|
| 6 | +def _get_trait_default_from_class(cls, trait_name): |
| 7 | + traits = cls.class_traits() |
| 8 | + return traits[trait_name].default() |
| 9 | + |
| 10 | + |
| 11 | +def _get_effective_executor_value(app_cfg, executor_class, trait_name): |
| 12 | + """ |
| 13 | + Return the configured value for trait_name if present in app_cfg, |
| 14 | + otherwise return the class default pulled from the trait metadata. |
| 15 | + """ |
| 16 | + # app_cfg is a traitlets.config.Config object (mapping-like) |
| 17 | + # executor_class is the class (LocalAutogradeExecutor or similar) |
| 18 | + |
| 19 | + # 1) look up the per-class node as a mapping (not attribute access) |
| 20 | + user_node = app_cfg.get(executor_class.__name__, None) |
| 21 | + |
| 22 | + # user_node may be None, or a Config object / dict-like. Use mapping access. |
| 23 | + if user_node is not None and trait_name in user_node: |
| 24 | + # Use .get to return the exact user-supplied value (won't be a lazy object) |
| 25 | + return user_node.get(trait_name) |
| 26 | + |
| 27 | + # 2) fallback to the trait's default from the class metadata |
| 28 | + return _get_trait_default_from_class(executor_class, trait_name) |
| 29 | + |
| 30 | + |
6 | 31 | @register_handler(path=r"\/api\/config\/?", version_specifier=VersionSpecifier.ALL) |
7 | 32 | class ConfigHandler(GraderBaseHandler): |
8 | 33 | """ |
9 | 34 | Handler class for requests to /config |
10 | 35 | """ |
11 | 36 |
|
12 | | - @authorize([Scope.student, Scope.tutor, Scope.instructor]) |
| 37 | + # todo: ask if this is correct |
| 38 | + @authorize([Scope.tutor, Scope.instructor]) |
13 | 39 | async def get(self): |
14 | | - """ |
15 | | - Gathers useful config for the grader labextension and returns it. |
16 | | - :return: config in dict |
17 | | - """ |
18 | | - self.write({}) |
| 40 | + app_cfg = self.application.config |
| 41 | + executor_class = app_cfg.RequestHandlerConfig.autograde_executor_class |
| 42 | + |
| 43 | + def resolve(name): |
| 44 | + return _get_effective_executor_value(app_cfg, executor_class, name) |
| 45 | + |
| 46 | + self.write_json( |
| 47 | + { |
| 48 | + "default_cell_timeout": resolve("default_cell_timeout"), |
| 49 | + "min_cell_timeout": resolve("min_cell_timeout"), |
| 50 | + "max_cell_timeout": resolve("max_cell_timeout"), |
| 51 | + } |
| 52 | + ) |
0 commit comments