# Path: owntracks/models.py
# class OwnTrackLog(models.Model):
#     tid = models.CharField(max_length=100, null=False, verbose_name='用户')
#     lat = models.FloatField(verbose_name='纬度')
#     lon = models.FloatField(verbose_name='经度')
#     created_time = models.DateTimeField('创建时间', default=now)
# 
#     def __str__(self):
#         return self.tid
# 
#     class Meta:
#         ordering = ['created_time']
#         verbose_name = "OwnTrackLogs"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'created_time'


import datetime
import itertools
import json
import logging
import requests
    import django.utils.timezone
from itertools import groupby
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.http import JsonResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from .models import OwnTrackLog
        from django.http import HttpResponseForbidden
    from django.utils.timezone import utc
                tid=tid, lat=lat, lon=lon))
        if tid and lat and lon:
            m = OwnTrackLog()
            m.tid = tid
            m.lat = lat
            m.lon = lon
            m.save()
            return HttpResponse('ok')
        else:
            return HttpResponse('data error')
    except Exception as e:
        logger.error(e)
        return HttpResponse('error')


@login_required
def show_maps(request):
    if request.user.is_superuser:
        defaultdate = str(datetime.datetime.now().date())
        date = request.GET.get('date', defaultdate)
        context = {
            'date': date
        }
        return render(request, 'owntracks/show_maps.html', context)
    else:
        return HttpResponseForbidden()


@login_required
def show_log_dates(request):

# Path: owntracks/models.py
# class OwnTrackLog(models.Model):
#     tid = models.CharField(max_length=100, null=False, verbose_name='用户')
#     lat = models.FloatField(verbose_name='纬度')
#     lon = models.FloatField(verbose_name='经度')
#     created_time = models.DateTimeField('创建时间', default=now)
# 
#     def __str__(self):
#         return self.tid
# 
#     class Meta:
#         ordering = ['created_time']
#         verbose_name = "OwnTrackLogs"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'created_time'


# Path: owntracks/views.py
import datetime
import itertools
import json
import logging
import requests
    import django.utils.timezone
from itertools import groupby
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.http import JsonResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from .models import OwnTrackLog
        from django.http import HttpResponseForbidden
    from django.utils.timezone import utc

                tid=tid, lat=lat, lon=lon))
        if tid and lat and lon:
            m = OwnTrackLog()
            m.tid = tid
            m.lat = lat
            m.lon = lon
            m.save()
            return HttpResponse('ok')
        else:
            return HttpResponse('data error')
    except Exception as e:
        logger.error(e)
        return HttpResponse('error')


@login_required
def show_maps(request):
    if request.user.is_superuser:
        defaultdate = str(datetime.datetime.now().date())
        date = request.GET.get('date', defaultdate)
        context = {
            'date': date
        }
        return render(request, 'owntracks/show_maps.html', context)
    else:
        return HttpResponseForbidden()


@login_required
def show_log_dates(request):

    dates = OwnTrackLog.objects.values_list('created_time', flat=True)