views.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:open-notices 作者: memespring 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号