def get_initial(self):
#In some parts of the world it is not possible to derive the correct timezone from latlng, so user needs to select it. We can prepopulate with best guess though.
geojson = json.dumps(self.request.session['new-notice'].get('location', None))
if geojson:
centroid = GEOSGeometry(geojson).centroid
tf = TimezoneFinder()
timezone_from_location = tf.timezone_at(lng=centroid.x, lat=centroid.y)
initial = super(NoticeCreateDatetime, self).get_initial()
initial['timezone'] = timezone_from_location
try:
now = datetime.now(pytz.timezone(timezone_from_location))
initial['starts_at'] = now.date()
except UnknownTimeZoneError:
pass
return initial
评论列表
文章目录