feat: add custom defined reveal time for unlisted unranked races - #219
feat: add custom defined reveal time for unlisted unranked races#219TreZc0 wants to merge 10 commits into
Conversation
deains
left a comment
There was a problem hiding this comment.
Sorry for taking forever on this.
|
|
||
| if cleaned_data.get('reveal_at') and self.data.get('timezone_offset'): | ||
| try: | ||
| from datetime import timedelta |
There was a problem hiding this comment.
This import is unnecessary as timedelta is already imported at the top of the file
| timezone_offset = 0 | ||
|
|
||
| local_time = cleaned_data['reveal_at'] | ||
| utc_time = local_time + timedelta(minutes=timezone_offset) |
There was a problem hiding this comment.
This isn't strictly speaking the right way to timezone-shift a datetime in Python, although since local_time should already be in UTC, I think this will still work? Might have to test it.
| races_to_reveal = Race.objects.filter( | ||
| unlisted=True, | ||
| recordable=False, | ||
| reveal_at__lte=now, | ||
| ) |
There was a problem hiding this comment.
I think you also want to filter this to only include completed races
state__in=[RaceStates.finished, RaceStates.cancelled, RaceStates.partitioned],
| for race in races_to_reveal: | ||
| race.unlisted = False | ||
| race.reveal_at = None | ||
| race.save() |
There was a problem hiding this comment.
Use race.increment_version() instead of save() so the update is broadcast correctly to websocket listeners.
|
|
||
| race.add_message( | ||
| 'This race has been automatically revealed as scheduled.', | ||
| highlight=True, |
There was a problem hiding this comment.
I don't think highlight is necessary for this.
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): |
There was a problem hiding this comment.
FYI this migration will need to be remade/merged
| 'Define when this race should be publicly visible, in your local timezone. ' | ||
| 'Only available for races that are both unlisted and unranked.' |
There was a problem hiding this comment.
Can we add something like "If blank, race will be revealed on finish."
| $('#id_ranked') | ||
| .prop('checked', rankedWasChecked) | ||
| .prop('disabled', false); | ||
| $('#id_ranked').prop('checked', true).prop('disabled', false); |


Premise:
Many communities with team racing use unlisted races for async functionality.
Currently, unranked unlisted races that cannot be recorded are instantly set to be listed after the race in done, as that's the final step of the race's lifecycle.
This can reveal info before it's convenient for tournaments.
Implementation
With this, races only get revealed instantly if no reveal_at time is set.
Through a hidden field timezone_conversion, the local timezone of the user is tracked, so they can enter their time in local timezone. the database saves the time in UTC:
To facility the process of making races visible after reveal_at time is reached, I suggest wrapping racetime/management/commands/reveal_hidden_races.py in a cronjob, probably running every 10 minutes.