views.py 文件源码

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

项目:EVE-Ratting-Tool 作者: StephenSwat 项目源码 文件源码
def query_anomalies(request, system_name):
    cache_result = cache.get('json_cache:%s' % system_name)

    if cache_result is None:
        rv = {}

        current_anoms = get_object_or_404(System, name=system_name).anomaly_set.select_related('owner')

        if current_anoms.count() == 0:
            return JsonResponse({'anomalies': {}})

        last_update = current_anoms.order_by('-last_seen').values_list('last_seen')[0][0]

        for a in current_anoms.all():
            if (last_update - a.last_seen).total_seconds() > 300:
                continue

            rv[a.signature] = {
                'type': a.site_type,
                'last': formats.date_format(a.last_seen),
                'first': formats.date_format(a.first_seen),
                'claimed': a.claimed,
            }

            if a.owner is not None:
                rv[a.signature]['owner'] = a.owner.get_full_name()
                rv[a.signature]['owner_id'] = a.owner.character_id

        cache_result = {'last_update': formats.date_format(last_update), 'anomalies': rv}
        cache.set('json_cache:%s' % system_name, cache_result)

    return JsonResponse(cache_result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号