Skip to content

Commit

Permalink
增加配置说明,owntracks功能修改
Browse files Browse the repository at this point in the history
  • Loading branch information
liangliangyy committed Mar 4, 2018
1 parent c6a5bba commit c31e496
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ windows电脑:


浏览器打开: http://127.0.0.1:8000/ 就可以看到效果了。

## 更多配置:
[更多配置介绍](/bin/config.md)
## 问题相关

有任何问题欢迎提Issue,或者将问题描述发送至我邮箱 `liangliangyy#gmail.com`.我会尽快解答.推荐提交Issue方式.

66 changes: 66 additions & 0 deletions bin/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 主要功能配置介绍:

## 缓存:
缓存默认使用`memcache`缓存,如果你没有`memcache`环境,则将`settings.py`中的`locmemcache`改为`default`,并删除默认的`default`配置即可。
```python
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'KEY_PREFIX': 'django_test' if TESTING else 'djangoblog',
'TIMEOUT': 60 * 60 * 10
},
'locmemcache': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'TIMEOUT': 10800,
'LOCATION': 'unique-snowflake',
}
}
```
## oauth登录:

现在已经支持微博,Google,GitHub,Facebook登录,需要在其对应的开放平台申请oauth登录权限,然后修改`settings.py`中的如下配置:
```python
OAHUTH = {
'sina': {
'appkey': os.environ.get('SINA_APP_KEY'),
'appsecret': os.environ.get('SINA_APP_SECRET'),
'callbackurl': 'http://www.lylinux.net/oauth/authorize?type=weibo'
},
'google': {
'appkey': os.environ.get('GOOGLE_APP_KEY'),
'appsecret': os.environ.get('GOOGLE_APP_SECRET'),
'callbackurl': 'http://www.lylinux.net/oauth/authorize?type=google'
},
'github': {
'appkey': os.environ.get('GITHUB_APP_KEY'),
'appsecret': os.environ.get('GITHUB_APP_SECRET'),
'callbackurl': 'http://www.lylinux.net/oauth/authorize?type=github'
},
'facebook': {
'appkey': os.environ.get('FACEBOOK_APP_KEY'),
'appsecret': os.environ.get('FACEBOOK_APP_SECRET'),
'callbackurl': 'http://www.lylinux.net/oauth/authorize?type=facebook'
}
}
```
将对应的appkey和appsecret修改为你自己的,将`callbackurl`的域名也修改为你的域名。

## owntracks:
owntracks是一个位置追踪软件,可以定时的将你的坐标提交到你的服务器上,现在简单的支持owntracks功能,需要安装owntracks的app,然后将api地址设置为:
`你的域名/owntracks/logtracks`就可以了。然后访问`你的域名/owntracks/show_dates`就可以看到有经纬度记录的日期,点击之后就可以看到运动轨迹了。地图是使用高德地图绘制。

## 邮件功能:
同样,将`settings.py`中的`ADMINS = [('liangliang', '[email protected]')]`配置为你自己的错误接收邮箱,另外修改:
```python
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get('DJANGO_EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('DJANGO_EMAIL_PASSWORD')
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = os.environ.get('DJANGO_EMAIL_USER')
```
为你自己的邮箱配置。

## 微信公众号
集成了简单的微信公众号功能,在微信后台将token地址设置为:`你的域名/robot` 即可,默认token为`lylinux`,当然你可以修改为你自己的,在`servermanager/robot.py`中。
8 changes: 8 additions & 0 deletions owntracks/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def test_own_track_log(self):
self.client.post('/owntracks/logtracks', json.dumps(o), content_type='application/json')
length = len(OwnTrackLog.objects.all())
self.assertEqual(length, 1)

rsp = self.client.get('/owntracks/show_maps')
self.assertEqual(rsp.status_code, 302)

user = BlogUser.objects.create_superuser(email="[email protected]",
username="liangliangyy1", password="liangliangyy1")

Expand All @@ -37,7 +41,11 @@ def test_own_track_log(self):
s.lon = 123.234
s.lat = 34.234
s.save()
rsp = self.client.get('/owntracks/show_dates')
self.assertEqual(rsp.status_code, 200)
rsp = self.client.get('/owntracks/show_maps')
self.assertEqual(rsp.status_code, 200)
rsp = self.client.get('/owntracks/get_datas')
self.assertEqual(rsp.status_code, 200)
rsp = self.client.get('/owntracks/get_datas?date=2018-02-26')
self.assertEqual(rsp.status_code, 200)
9 changes: 4 additions & 5 deletions owntracks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
app_name = "owntracks"

urlpatterns = [
path('owntracks/logtracks', views.manage_owntrack_log),
path('owntracks/show_maps', views.show_maps),
path('owntracks/get_datas', views.get_datas)
path('owntracks/logtracks', views.manage_owntrack_log, name='logtracks'),
path('owntracks/show_maps', views.show_maps, name='show_maps'),
path('owntracks/get_datas', views.get_datas, name='get_datas'),
path('owntracks/show_dates', views.show_log_dates, name='show_dates')
]

# http://home.lylinux.net:2213/owntracks/logtracks
35 changes: 31 additions & 4 deletions owntracks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Create your views here.
import json
import datetime
from itertools import groupby
from django.http import HttpResponse
from .models import OwnTrackLog
Expand Down Expand Up @@ -38,7 +39,27 @@ def manage_owntrack_log(request):

@login_required
def show_maps(request):
return render(request, 'owntracks/show_maps.html')
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:
from django.http import HttpResponseForbidden
return HttpResponseForbidden()


@login_required
def show_log_dates(request):
dates = OwnTrackLog.objects.values_list('created_time', flat=True)
results = list(set(map(lambda x: x.strftime('%Y-%m-%d'), dates)))

context = {
'results': results
}
return render(request, 'owntracks/show_log_dates.html', context)


def convert_to_amap(locations):
Expand All @@ -52,14 +73,20 @@ def convert_to_amap(locations):
'coordsys': 'gps'
}
rsp = requests.get(url=api, params=query)
logger.info(type(rsp.text))

result = json.loads(rsp.text)
return result['locations']


@login_required
def get_datas(request):
models = OwnTrackLog.objects.all()
now = datetime.datetime.now()
querydate = datetime.datetime(now.year, now.month, now.day, 0, 0, 0)
if request.GET.get('date', None):
date = list(map(lambda x: int(x), request.GET.get('date').split('-')))
querydate = datetime.datetime(date[0], date[1], date[2], 0, 0, 0)
nextdate = querydate + datetime.timedelta(days=1)
models = OwnTrackLog.objects.filter(created_time__range=(querydate, nextdate))
result = list()
if models and len(models):
for tid, item in groupby(sorted(models, key=lambda k: k.tid), key=lambda k: k.tid):
Expand All @@ -72,4 +99,4 @@ def get_datas(request):
paths.append(i.split(','))
d["path"] = paths
result.append(d)
return JsonResponse(result, safe=False)
return JsonResponse(result, safe=False)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jsonpickle==0.9.6
markdown2==2.3.5
mistune==0.8.3
olefile==0.45.1
packaging==16.8
packaging==17.1
Pillow==5.0.0
Pygments==2.2.0
PyMySQL==0.8.0
Expand Down
1 change: 1 addition & 0 deletions templates/blog/tags/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
{% endif %}
{% if user.is_superuser %}
<li><a href="{% url "blog:refresh" %}" target="_blank">刷新缓存</a></li>
<li><a href="{% url 'owntracks:show_dates' %}" target="_blank">运动轨迹记录</a></li>
{% endif %}
<li><a href="http://gitbook.lylinux.net" target="_blank" rel="nofollow">GitBook</a></li>
</ul>
Expand Down
17 changes: 17 additions & 0 deletions templates/owntracks/show_log_dates.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>记录日期</title>
</head>
<body>

<ul>
{% for date in results %}
<li>
<a href="{% url 'owntracks:show_maps' %}?date={{ date }}">{{ date }}</a>
</li>
{% endfor %}
</ul>
</body>
</html>
6 changes: 3 additions & 3 deletions templates/owntracks/show_maps.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
font-size: 14px;
}
</style>
<title>快速入门</title>
<title>运动轨迹</title>
</head>

<body>
Expand Down Expand Up @@ -98,7 +98,7 @@

$('<div id="loadingTip">加载数据,请稍候...</div>').appendTo(document.body);

$.getJSON('/owntracks/get_datas', function (d) {
$.getJSON('/owntracks/get_datas?date={{ date }}', function (d) {

if (!d || !d.length) {
$("#loadingTip").text("没有数据...")
Expand All @@ -120,7 +120,7 @@
d.forEach(function (item, index) {
var navg1 = pathSimplifierIns.createPathNavigator(index, {
loop: true,
speed: 1000000,
speed: 1000,
});

navg1.start();
Expand Down

0 comments on commit c31e496

Please sign in to comment.