Skip to content

Add command for creating mock competitions #502

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

kyepskee
Copy link
Contributor

@kyepskee kyepskee commented Apr 4, 2025

Implements #496.

@kyepskee kyepskee self-assigned this Apr 4, 2025
@kyepskee kyepskee force-pushed the mock-competition-command branch from 7554858 to e6fbb23 Compare April 8, 2025 20:17
@kyepskee kyepskee marked this pull request as ready for review April 8, 2025 20:18
@kyepskee kyepskee requested a review from MasloMaslane as a code owner April 8, 2025 20:18
kyepskee added 2 commits April 8, 2025 22:33
create_mock_competition creates a lot of rubbish in the Django database,
so it's important to warn users about that. Also, I add a suggestion to
use dumpdata and loaddata commands so that the previous state of the
database can be easily restored.
I make one of the named arguments of the command required, so that it's
harder to execute by mistake, as it can fill your database with rubbish.
def get_unique_field_value(model_class, field_name, base_value):
regex_pattern = base_value + r"(\d+)"

filter_kwargs = {f"{field_name}__regex": f"^{regex_pattern}"}
Copy link
Contributor

Choose a reason for hiding this comment

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

That's an overkill, startswith should be enough: https://docs.djangoproject.com/en/5.1/ref/models/querysets/#startswith

# Create levels[level] values for each category and store them in info_values[level]
info_values = [[] for i in range(len(levels))]
for level in range(len(levels)):
print(level, levels)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove debug print

dest="levels",
default=2,
help="Number of levels of nesting of the competition."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

add an option to fix random seed value

)

@transaction.atomic
def handle(self, *args, **options):
Copy link
Contributor

Choose a reason for hiding this comment

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

this function is too long, please refactor and add some helper functions, maybe local function recurse can be moved to normal function outside handle

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.

2 participants