time zone magic around virtualevent
This commit is contained in:
@@ -16,6 +16,7 @@ import xml.etree.ElementTree as et
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from timezonefinder import TimezoneFinder
|
||||
|
||||
import dataprep
|
||||
from rowers.utils import geo_distance
|
||||
@@ -38,6 +39,24 @@ class InvalidTrajectoryError(Exception):
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
def get_course_timezone(course):
|
||||
polygons = GeoPolygon.objects.filter(course = course)
|
||||
points = GeoPoint.objects.filter(polygon = polygons[0])
|
||||
lat = points[0].latitude
|
||||
lon = points[0].longitude
|
||||
|
||||
tf = TimezoneFinder()
|
||||
try:
|
||||
timezone_str = tf.timezone_at(lng=lon,lat=lat)
|
||||
except ValueError:
|
||||
timezone_str = 'UTC'
|
||||
|
||||
if timezone_str is None:
|
||||
timezone_str = tf.closest_timezone_at(lng=lon,lat=lat)
|
||||
if timezone_str is None:
|
||||
timezone_str = 'UTC'
|
||||
|
||||
return timezone_str
|
||||
|
||||
def polygon_to_path(polygon):
|
||||
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
||||
|
||||
@@ -1074,7 +1074,7 @@ class VirtualRace(PlannedSession):
|
||||
contact_phone = models.CharField(validators=[phone_regex], max_length=17, blank=True)
|
||||
|
||||
contact_email = models.EmailField(max_length=254,
|
||||
validators=[validate_email])
|
||||
validators=[validate_email],blank=True)
|
||||
|
||||
# Date input utility
|
||||
class DateInput(forms.DateInput):
|
||||
|
||||
@@ -86,6 +86,30 @@ def timefield_to_seconds_duration(t):
|
||||
|
||||
return duration
|
||||
|
||||
|
||||
def get_virtualrace_times(virtualrace):
|
||||
geocourse = GeoCourse.objects.get(id = virtualrace.course.id)
|
||||
timezone_str = courses.get_course_timezone(geocourse)
|
||||
|
||||
startdatetime = datetime.datetime.combine(
|
||||
virtualrace.startdate,virtualrace.start_time)
|
||||
enddatetime = datetime.datetime.combine(
|
||||
virtualrace.enddate,virtualrace.end_time)
|
||||
|
||||
startdatetime = pytz.timezone(timezone_str).localize(
|
||||
startdatetime
|
||||
)
|
||||
enddatetime = pytz.timezone(timezone_str).localize(
|
||||
enddatetime
|
||||
)
|
||||
|
||||
return {
|
||||
'startdatetime':startdatetime,
|
||||
'enddatetime':enddatetime,
|
||||
'evaluation_closure':virtualrace.evaluation_closure,
|
||||
'registration_closure':virtualrace.registration_closure,
|
||||
}
|
||||
|
||||
def get_session_metrics(ps):
|
||||
rowers = ps.rower.all()
|
||||
rscore = []
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
<div class="grid_12 alpha">
|
||||
|
||||
<h1>New Virtual Race</h1>
|
||||
|
||||
|
||||
<div class="grid_8 alpha">
|
||||
<h1>New Virtual Race</h1>
|
||||
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||
{% if form.errors %}
|
||||
<p style="color: red;">
|
||||
@@ -28,10 +28,21 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid_6 prefix_6" id="id_guidance">
|
||||
|
||||
<div class="grid_4 omega">
|
||||
<p>
|
||||
<ul>
|
||||
<li>All times are local times in the race course time zone</li>
|
||||
<li>Adding a contact phone number and email is not mandatory, but we
|
||||
strongly recommend it.</li>
|
||||
<li>If your event has a registration closure deadline, participants
|
||||
have to enter (and can withdraw) before the registration closure time.</li>
|
||||
<li>Participants can submit results until the evaluation closure time.</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
|
||||
@@ -148,6 +148,7 @@ import matplotlib.pyplot as plt
|
||||
from rowers.emails import send_template_email
|
||||
|
||||
from pytz import timezone as tz,utc
|
||||
from timezonefinder import TimezoneFinder
|
||||
import dateutil
|
||||
import mpld3
|
||||
from mpld3 import plugins
|
||||
@@ -13324,7 +13325,28 @@ def virtualevent_create_view(request):
|
||||
contact_phone = cd['contact_phone']
|
||||
contact_email = cd['contact_email']
|
||||
|
||||
# correct times
|
||||
|
||||
geocourse = GeoCourse.objects.get(id= course.id)
|
||||
timezone_str = courses.get_course_timezone(geocourse)
|
||||
|
||||
startdatetime = datetime.datetime.combine(startdate,start_time)
|
||||
enddatetime = datetime.datetime.combine(enddate,end_time)
|
||||
|
||||
startdatetime = pytz.timezone(timezone_str).localize(
|
||||
startdatetime
|
||||
)
|
||||
enddatetime = pytz.timezone(timezone_str).localize(
|
||||
enddatetime
|
||||
)
|
||||
evaluation_closure = pytz.timezone(timezone_str).localize(
|
||||
evaluation_closure.replace(tzinfo=None)
|
||||
)
|
||||
registration_closure = pytz.timezone(timezone_str).localize(
|
||||
registration_closure.replace(tzinfo=None)
|
||||
)
|
||||
|
||||
|
||||
|
||||
vs = VirtualRace(
|
||||
name=name,
|
||||
|
||||
Reference in New Issue
Block a user