From 6be257060277ea501bb467ff997bc2536497ec78 Mon Sep 17 00:00:00 2001 From: "547884940@qq.com" <547884940@qq.com> Date: Fri, 30 Jan 2015 20:47:18 +0800 Subject: [PATCH] [user]edit --- PiBox/PiHome/PiApp/api.py | 4 +- PiBox/PiHome/PiApp/models.py | 2 +- PiBox/PiHome/WebShell/www/Thumbs.db | Bin 0 -> 6656 bytes PiBox/PiHome/templates/login.html | 2 + "PiBox/sh/datapoint_tools\200pic.py" | 106 ++++++++++++++++++++++++ "PiBox/sh/datapoint_tools\360switch.py" | 33 ++++++++ 6 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 PiBox/PiHome/WebShell/www/Thumbs.db create mode 100644 "PiBox/sh/datapoint_tools\200pic.py" create mode 100644 "PiBox/sh/datapoint_tools\360switch.py" diff --git a/PiBox/PiHome/PiApp/api.py b/PiBox/PiHome/PiApp/api.py index dc35a09..366a43c 100644 --- a/PiBox/PiHome/PiApp/api.py +++ b/PiBox/PiHome/PiApp/api.py @@ -49,9 +49,9 @@ def check_username(request): return HttpResponse(simplejson.dumps({'msg':'Please enter a valid email format'})) user = PiUser.objects.get(username = request.GET['username']) if user is not None: - return HttpResponse(simplejson.dumps({'msg':'Username already exists'})) + return HttpResponse(simplejson.dumps({'msg':'Email already exists'})) except: - return HttpResponse(simplejson.dumps({'msg':'Username can be used'})) + return HttpResponse(simplejson.dumps({'msg':'Email can be used'})) def check_login(request): if request.user.is_authenticated(): diff --git a/PiBox/PiHome/PiApp/models.py b/PiBox/PiHome/PiApp/models.py index 979e21e..c8ec195 100644 --- a/PiBox/PiHome/PiApp/models.py +++ b/PiBox/PiHome/PiApp/models.py @@ -21,7 +21,7 @@ class PiUser(AbstractUser): class PiSettings(models.Model): - ip = models.IPAddressField(default="127.0.0.1") + ip = models.GenericIPAddressField(default="127.0.0.1") port = models.IntegerField(default=3333) enable_register = models.BooleanField(default=True) diff --git a/PiBox/PiHome/WebShell/www/Thumbs.db b/PiBox/PiHome/WebShell/www/Thumbs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un?GI^4U5XByf4oPNjYr@EXtD^Eu|Lc8u@R@MdgJ5iG9Wrx^iZS5wt^;s*U zf2Pg6&60U~NVkBa*d|l8`9q{pZ`dxkNR~pr6Rd%lm7JZbEfK`m9Bps1%U-3bwAkV$~5FuJ!{*kWF(mMHbVp^-;xp(Z|#G!2x6W$`W zrPCfy@guiL7EN~bZjmGUj$Hdsk?JM{ZVkryTVy#z4>Sh!P1XHSuEgBz$8(gD=Vi;h z=K1-^I{7M1XzUp@@A8lK+L3Qn+B+OWxv5$-yJD&1W1V|H{Yl5e-T#*VcMJRj!oX&{ literal 0 HcmV?d00001 diff --git a/PiBox/PiHome/templates/login.html b/PiBox/PiHome/templates/login.html index 060be16..820a213 100644 --- a/PiBox/PiHome/templates/login.html +++ b/PiBox/PiHome/templates/login.html @@ -27,9 +27,11 @@ {% csrf_token %}
+
+
diff --git "a/PiBox/sh/datapoint_tools\200pic.py" "b/PiBox/sh/datapoint_tools\200pic.py" new file mode 100644 index 0000000..6c6cbc6 --- /dev/null +++ "b/PiBox/sh/datapoint_tools\200pic.py" @@ -0,0 +1,106 @@ +#/bin/env python +# -*-coding:utf8-*- +''' +# Any issues or improvements please contact jacob-chen@iotwrt.com +''' +import urllib +import urllib2 +import sys +import json + +try: + from poster.encode import multipart_encode + from poster.streaminghttp import register_openers +except: + print "In order to post file,you should install poster modules!!" + print "sudo pip install poster" + +if __name__ == '__main__': + + choose = int(raw_input('1.write 2.read 3.edit 4.remove 5.history')) + domain = raw_input('domain(as 192.168.10.106:8000) : ') + sensor_id = raw_input('sensor_id(int) : ') + + #write + if choose == 1: + filepath = raw_input('filepath(as ./xxx.jpg) : ') + key = raw_input('key(as 2012-12-12T11:11:11) : ') + + # 在 urllib2 上注册 http 流处理句柄 + register_openers() + + # 开始对文件的 multiart/form-data 编码 + # "value" 是参数的名字,一般通过 HTML 中的 标签的 name 参数设置 + # headers 包含必须的 Content-Type 和 Content-Length + # datagen 是一个生成器对象,返回编码过后的参数,这里如果有多个参数的话依次添加即可 + datagen, headers = multipart_encode({"value": open(filepath, "rb"), "key" : key}) + + request = urllib2.Request("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/", datagen, headers) + + get = urllib2.urlopen(request).read() + print 'ret body:', get + s = json.loads(get) + print 'msg:', s['msg'] + + #read + elif choose == 2: + key = raw_input('key(as 2012-12-12T11:11:11) : ') + params = urllib.urlencode({'key': key}) + f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/get/?%s" % params) + get = f.read() + print 'ret body:', get + s = json.loads(get) + print 'key:',s['key'],'value:',s['value'] + + #edit + elif choose == 3: + filepath = raw_input('filepath(as ./xxx.jpg) : ') + key = raw_input('key(as 2012-12-12T11:11:11) : ') + + # 在 urllib2 上注册 http 流处理句柄 + register_openers() + + # 开始对文件的 multiart/form-data 编码 + # "value" 是参数的名字,一般通过 HTML 中的 标签的 name 参数设置 + # headers 包含必须的 Content-Type 和 Content-Length + # datagen 是一个生成器对象,返回编码过后的参数,这里如果有多个参数的话依次添加即可 + datagen, headers = multipart_encode({"value": open(filepath, "rb"), "key" : key}) + + request = urllib2.Request("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/edit/", datagen, headers) + + get = urllib2.urlopen(request).read() + print 'ret body:', get + s = json.loads(get) + print 'msg:', s['msg'] + + #remove + elif choose == 4: + key = raw_input('key(as 2012-12-12T11:11:11) : ') + params = urllib.urlencode({'key': key}) + f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/remove/?%s" % params) + get = f.read() + print 'ret body:', get + s = json.loads(get) + print 'msg:', s['msg'] + + #history + elif choose == 5: + ex = raw_input('latest 20?y or n') + if ex == 'y': + f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/history/") + get = f.read() + print 'ret body:', get + s = json.loads(get) + for item in s['datapoint']: + print 'key:',item['key'],'value:',item['value'] + else: + start = raw_input('start(as 2012-12-12T11:11:11) : ') + end = raw_input('end(as 2012-12-12T11:11:11) : ') + interval = raw_input('interval(int) : ') + params = urllib.urlencode({'start': start, 'end' : end, 'interval' : interval}) + f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/history/?%s" % params) + get = f.read() + print 'ret body:', get + s = json.loads(get) + for item in s['datapoint']: + print 'key:',item['key'],'value:',item['value'] \ No newline at end of file diff --git "a/PiBox/sh/datapoint_tools\360switch.py" "b/PiBox/sh/datapoint_tools\360switch.py" new file mode 100644 index 0000000..8f35c58 --- /dev/null +++ "b/PiBox/sh/datapoint_tools\360switch.py" @@ -0,0 +1,33 @@ +#/bin/env python +# -*-coding:utf8-*- +''' +# Any issues or improvements please contact jacob-chen@iotwrt.com +''' +import urllib +import json + +if __name__ == '__main__': + + choose = int(raw_input('1.write 2.read ')) + domain = raw_input('domain(as 192.168.10.106:8000) : ') + sensor_id = raw_input('sensor_id(int) : ') + + if choose == 1: + value = int(raw_input('value(int) : ')) + # params = urllib.urlencode() + params = urllib.urlencode({'value': value}) + f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/?%s" % params) + get = f.read() + print 'ret body:', get + + s = json.loads(get) + print 'msg:', s['msg'] + + elif choose == 2: + # params = urllib.urlencode() + f = urllib.urlopen("http://" + domain + "/API/sensor/" + sensor_id + "/datapoint/get/") + get = f.read() + print 'ret body:', get + + s = json.loads(get) + print 'value:', s['value']