Skip to content

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Jan 29, 2026

Summary

This PR addresses three issues with training program exports:

  1. Added "Export all tasks" button to training program general page - Training programs now have an export link similar to contests, which exports all tasks from the managing contest.

  2. Fixed training day export - Changed _export_contest_to_yaml_format to use contest.get_tasks() instead of contest.tasks. Training days store their tasks separately, so the previous code would export an empty task list.

  3. Changed managing contest naming convention - Managing contests are now created with the same name as the training program (instead of __ prefix). Updated contest filtering logic to check the training_program relationship instead of relying solely on the __ prefix. Backward compatibility is maintained for existing __ prefixed contests.

Review & Testing Checklist for Human

  • Verify backward compatibility: Existing training programs have managing contests with __ prefix. Test that these still work correctly (access control, filtering, redirects).
  • Test new training program creation: Create a new training program and verify the managing contest is created with the correct name (no __ prefix) and that it's properly hidden from contest lists.
  • Test export functionality:
    • Export from training program general page (new button)
    • Export a training day that has tasks
    • Verify the exported YAML contains the correct tasks
  • Verify contest filtering: Check that managing contests don't appear in contest dropdowns/lists where they shouldn't (e.g., "move tasks to" dropdown, contest list page).
  • Test direct URL access: Try accessing a managing contest directly by its URL - should be blocked for both new (same name) and legacy (__ prefix) managing contests.

Notes

  • The exclude_internal_contests() utility function now filters out both __ prefixed contests AND contests that are managing contests for training programs.
  • No database migration is included - existing managing contests will keep their __ prefix. This creates some inconsistency but maintains backward compatibility.

Link to Devin run: https://app.devin.ai/sessions/4d6920a93a8e45e79c033dbb2c871908
Requested by: Ron Ryvchin (@ronryv)


Open with Devin

Summary by CodeRabbit

  • New Features

    • Training programs can be exported as downloadable ZIPs
    • Added export link on the training program edit page
  • Improvements

    • Contest lookup and access now respect training program associations
    • Contest lists and filters exclude contests that manage training programs
    • Broader export coverage includes user pictures in file enumerations

✏️ Tip: You can customize this high-level summary in your review settings.

1. Add 'Export all tasks' button to training program general page
   - Added export link that exports the managing contest's tasks

2. Fix training day export to use get_tasks() instead of contest.tasks
   - Training days have tasks separate from contest.tasks
   - Updated _export_contest_to_yaml_format to use get_tasks()

3. Rename managing contest to match training program name
   - Changed from '__' + name to just name
   - Updated contest filtering to check if contest is a managing contest
   - Updated exclude_internal_contests() to filter managing contests
   - Updated CWS and AWS handlers to check training_program relationship

Co-Authored-By: Ron Ryvchin <[email protected]>
@devin-ai-integration
Copy link
Author

devin-ai-integration bot commented Jan 29, 2026

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
📝 Walkthrough

Walkthrough

This pull request introduces an export capability for training programs via a new ExportTrainingProgramHandler, refactors contest resolution to use explicit training_program relationships instead of name-based heuristics, removes the "__" prefix convention from contest names, and updates contest filtering to exclude training-program-managed contests.

Changes

Cohort / File(s) Summary
Training Program Export
cms/server/admin/handlers/__init__.py, cms/server/admin/handlers/export_handlers.py, cms/server/admin/templates/training_program.html
Added ExportTrainingProgramHandler to export training programs to YAML/ZIP format, exposed new /training_program/([0-9]+)/export route, and added export link in the training program UI.
Contest Resolution and Redirect Logic
cms/server/admin/handlers/base.py, cms/server/contest/handlers/contest.py
Changed redirect and lookup logic from name-based ("__" prefix heuristic) to relationship-based; reversed contest/training program resolution order in multi-contest mode to prioritize TrainingProgram lookup first.
Contest Filtering and Training Program Handlers
cms/server/admin/handlers/trainingprogram.py, cms/server/util.py
Removed "__" prefix from managing contest names on creation, added explicit filtering to exclude training-program-managed contests, and tightened constraints on contest selection in task reassignment.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Daniel-Aga

Poem

A rabbit hops through training grounds,
No more "__" prefixes bound—
Relationships now lead the way,
With exports bright as morning's play,
The contests dance in proper form. 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the PR, which is to fix broken exports for training programs by adding export functionality and updating related logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Author

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View issue and 5 additional flags in Devin Review.

Open in Devin Review

@ronryv
Copy link
Collaborator

ronryv commented Jan 29, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@cms/server/contest/handlers/contest.py`:
- Around line 179-181: The direct-access branch blocks "__" names but doesn't
set self.training_program for managing contests; update the block that checks
self.contest.name.startswith("__") to also, when the current contest is a
managing contest, set self.training_program = self.contest.training_program
(same logic used in the single-contest path where contest.training_program is
assigned) so that can_access_task() and StudentTask checks see the training
program; ensure you follow the same null/exists checks used in the
single-contest assignment to avoid None propagation.
🧹 Nitpick comments (1)
cms/server/admin/handlers/export_handlers.py (1)

607-612: Nit: Rename unused loop variable.

The static analysis tool flags dirs as unused in the os.walk loop. While this is a common pattern, renaming to _dirs would suppress the warning and signal intent.

♻️ Optional fix
-            for root, dirs, files in os.walk(contest_dir):
+            for root, _dirs, files in os.walk(contest_dir):

Copy link
Author

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

View issue and 7 additional flags in Devin Review.

Open in Devin Review

@ronryv ronryv merged commit 8c811d0 into training_program Jan 29, 2026
4 of 5 checks passed
ronryv added a commit that referenced this pull request Jan 29, 2026
* Fix broken exports for training programs

1. Add 'Export all tasks' button to training program general page
   - Added export link that exports the managing contest's tasks

2. Fix training day export to use get_tasks() instead of contest.tasks
   - Training days have tasks separate from contest.tasks
   - Updated _export_contest_to_yaml_format to use get_tasks()

3. Rename managing contest to match training program name
   - Changed from '__' + name to just name
   - Updated contest filtering to check if contest is a managing contest
   - Updated exclude_internal_contests() to filter managing contests
   - Updated CWS and AWS handlers to check training_program relationship

Co-Authored-By: Ron Ryvchin <[email protected]>

* Fix export button URL and add training program export route

Co-Authored-By: Ron Ryvchin <[email protected]>

* review comments

* Add pictures to dump exporter

* export fix

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Ron Ryvchin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant