Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add category configuring, and default accept unofficial to true for active elements #166

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aplus_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def setup(app):
app.add_config_value('append_content', [], 'html')
app.add_config_value('override', {}, 'html')
app.add_config_value('category_names', {}, 'html')
app.add_config_value('categories', {}, 'html')
app.add_config_value('static_host', None, 'html')
app.add_config_value('ae_default_submissions', 0, 'html')
app.add_config_value('skip_language_inconsistencies', False, 'html')
Expand Down
14 changes: 13 additions & 1 deletion directives/ae_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Directive that places active element output divs.
'''
import os.path
from typing import Any, Dict

from docutils.parsers.rst import directives
from docutils import nodes
from sphinx.errors import SphinxError
Expand Down Expand Up @@ -84,6 +86,7 @@ def run(self):
key_title = "{} {}".format(translations.get(env, 'exercise'), key)

# Load or create exercise configuration.
data: Dict[str, Any]
if 'config' in self.options:
path = os.path.join(env.app.srcdir, self.options['config'])
if not os.path.exists(path):
Expand All @@ -106,9 +109,18 @@ def run(self):
'title': env.config.submit_title.format(
key_title=key_title, config_title=config_title
),
'category': 'active elements',
'max_submissions': self.options.get('submissions', data.get('max_submissions', env.config.ae_default_submissions)),
})

if "category" in self.options:
data["category"] = self.options["category"]
elif "category" not in data:
data["category"] = (
"active elements"
if data["max_submissions"] == 0 else
"active elements with max submissions"
)

data.setdefault('status', self.options.get('status', 'unlisted'))

self.apply_override(data, category)
Expand Down
18 changes: 17 additions & 1 deletion toc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,31 @@ def parse_chapter(docname, doc, parent, module_meta):

# Create categories.
category_names = app.config.category_names
for key, name in category_names.items():
category = app.config.categories.get(key, {"name": name})
if name != category.get("name", name):
markkuriekkinen marked this conversation as resolved.
Show resolved Hide resolved
raise SphinxError(f"Name mismatch between config options 'category_names' and 'categories' for key '{key}': '{name}' vs '{category['name']}'")

categories = {
key: {
'name': category_names.get(key, key),
} for key in category_keys
}

for key, category in app.config.categories.items():
if key not in categories:
raise SphinxError(f"Category with key '{key}' was configured but not used in the material")

categories[key].update(category)
markkuriekkinen marked this conversation as resolved.
Show resolved Hide resolved

for key in ['chapter', 'feedback']:
if key in categories:
categories[key]['status'] = 'nototal'
categories[key].setdefault('status', 'nototal')

if "active elements" in categories:
categories["active elements"].setdefault("accept_unofficial_submits", True)

# Set unprotected paths
unprotected_paths = course_meta.get('unprotected-paths', app.config.unprotected_paths)
if isinstance(unprotected_paths, str):
unprotected_paths = shlex.split(unprotected_paths)
Expand Down