本文整理汇总了Python中event.models.Event.get_events_in_range方法的典型用法代码示例。如果您正苦于以下问题:Python Event.get_events_in_range方法的具体用法?Python Event.get_events_in_range怎么用?Python Event.get_events_in_range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event.models.Event
的用法示例。
在下文中一共展示了Event.get_events_in_range方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: event_range_search
# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import get_events_in_range [as 别名]
def event_range_search(request, *args, **kwargs):
if request.method != 'POST':
# FIXME: 405 Method Not Allowed
return None
query = Q()
res = {'events_in_range': []}
range_value = dict(request.POST)
keys = ['ne_lat', 'sw_lat', 'ne_lng', 'sw_lng']
for key in keys:
range_value[key] = float(range_value[key][0])
events = Event.get_events_in_range(range_value['ne_lat'],
range_value['sw_lat'],
range_value['ne_lng'],
range_value['sw_lng'])
tags = [int(t) for t in request.POST.getlist('tags')]
if len(tags) > 0:
Tag = apps.get_model('tag', 'Tag')
tag_query = None
for t in tags:
tag = Tag.objects.get(pk=t)
if tag_query is None:
tag_query = Q(tag=tag)
else:
tag_query = tag_query | Q(tag=tag)
query = query & tag_query
events = events.all() \
.filter(query) \
.order_by('-id') \
.distinct()
events = [e for e in events if not e.is_over()]
for event in events:
status = event.get_status()
res['events_in_range'].append({
'id': event.id,
'name': event.name,
'start_time': event.start_time, #.strftime(DATETIME_FORMAT),
'end_time': event.end_time, #.strftime(DATETIME_FORMAT),
'place': event.meeting_place,
'longitude': event.longitude,
'latitude': event.latitude,
'img': event.get_image_url(),
'status': status['msg'],
'label': status['label'],
})
return JsonResponse(res)