-
Notifications
You must be signed in to change notification settings - Fork 85
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
base: master
Are you sure you want to change the base?
Conversation
7554858
to
e6fbb23
Compare
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}"} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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." | ||
) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
Implements #496.