aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author藍挺瑋 <lantw44@gmail.com>2012-12-20 01:35:26 +0800
committerLAN-TW <lantw44@gmail.com>2012-12-20 01:35:26 +0800
commit6c1039e4328bb6c80cdbad9e72aafd0ed689b3f7 (patch)
treea8affb0e15c6ed4f004f45ea086d97fa6f4cdccc
parent5ac1ecd34a53fa760e71437b89c906c82ae7abeb (diff)
downloadinccalendar-6c1039e4328bb6c80cdbad9e72aafd0ed689b3f7.tar.gz
inccalendar-6c1039e4328bb6c80cdbad9e72aafd0ed689b3f7.tar.zst
inccalendar-6c1039e4328bb6c80cdbad9e72aafd0ed689b3f7.zip
支援直接下載整年的資料
-rw-r--r--access/fetch.py48
-rw-r--r--js/data.js11
2 files changed, 41 insertions, 18 deletions
diff --git a/access/fetch.py b/access/fetch.py
index 3202abe..2ab65ed 100644
--- a/access/fetch.py
+++ b/access/fetch.py
@@ -52,24 +52,40 @@ class FetchEvent(webapp2.RequestHandler):
if not guserid:
return
- year = int(self.request.get('year'))
- month = int(self.request.get('month'))
+ year = self.request.get('year')
+ month = self.request.get('month')
withcursor = self.request.get('gqlcursor')
- if month >= 12:
- nextmonth = 1
- nextyear = year + 1
+
+ if month == "":
+ year = int(year)
+ data = db.GqlQuery("SELECT * FROM CalEvent "
+ "WHERE ANCESTOR IS :1 AND "
+ "begin >= :2 AND "
+ "begin < :3 "
+ "ORDER BY begin",
+ db.Key.from_path('user', guserid.email()),
+ datetime.datetime(year, 1, 1),
+ datetime.datetime(year + 1, 1, 1))
+
else:
- nextmonth = month + 1
- nextyear = year
-
- data = db.GqlQuery("SELECT * FROM CalEvent "
- "WHERE ANCESTOR IS :1 AND "
- "begin >= :2 AND "
- "begin < :3 "
- "ORDER BY begin",
- db.Key.from_path('user', guserid.email()),
- datetime.datetime(year, month, 1),
- datetime.datetime(nextyear, nextmonth, 1))
+ year = int(year)
+ month = int(month)
+
+ if month >= 12:
+ nextmonth = 1
+ nextyear = year + 1
+ else:
+ nextmonth = month + 1
+ nextyear = year
+
+ data = db.GqlQuery("SELECT * FROM CalEvent "
+ "WHERE ANCESTOR IS :1 AND "
+ "begin >= :2 AND "
+ "begin < :3 "
+ "ORDER BY begin",
+ db.Key.from_path('user', guserid.email()),
+ datetime.datetime(year, month, 1),
+ datetime.datetime(nextyear, nextmonth, 1))
if withcursor != "":
data.with_cursor(withcursor)
diff --git a/js/data.js b/js/data.js
index 20a81a5..846f962 100644
--- a/js/data.js
+++ b/js/data.js
@@ -59,15 +59,21 @@ function inccal_fetch(year, month){
var calevent;
var eventobj;
var progcounter = 0;
+ var timecounter = 0;
var loadingstr = '載入中......';
var rq;
var i;
while(should_continue){
- status_bar_set(loadingstr + ' ' + progcounter.toString());
+ status_bar_set(loadingstr + ' 已下載 ' + timecounter.toString() +
+ ' 次,共取得 ' + progcounter.toString() + ' 項資料');
rq = create_xmlhttp_object();
rq.open('POST', '/access/fetch', false);
rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- postdata = 'year=' + year.toString() + '&month=' + month.toString();
+ if(month == null){
+ postdata = 'year=' + year.toString();
+ }else{
+ postdata = 'year=' + year.toString() + '&month=' + month.toString();
+ }
if(gqlcursor != null){
postdata = postdata + '&gqlcursor=' + encodeURIComponent(gqlcursor);
}
@@ -97,6 +103,7 @@ function inccal_fetch(year, month){
0, 0);
caleventlist.push(eventobj);
}
+ timecounter++;
progcounter += calevent.length;
try{
gqlcursor = retrdata.getElementsByTagName("gqlcursor")[0].childNodes[0].nodeValue;