1. gao shuai
  2. wd-kcb-hg

Commits

gao shuai  committed 3a72164

GoodKookingURI to check kcbs in week date or day parameters

  • Participants
  • Parent commits cdf104a
  • Branches default

Comments (0)

Files changed (7)

File kcbuser.py

View file
  • Ignore whitespace
 from google.appengine.ext.webapp.util import run_wsgi_app
 import re
 import time
+############_______________________获取当前时间___________________________________________________
+import datetime
+from datetime import  timedelta, date
 
+def getCNnow():
+	return datetime.datetime.utcnow() + timedelta(hours=+8)
+
+NowDay=getCNnow().isoweekday()
 
 def f(x,y):
 		list=[]
 		if strterm !='':
 			NEWTERM.startday=datetime.datetime(*time.strptime( strterm, "%Y%m%d" )[:6]).date()
 		else:
-			NEWTERM.startday=datetime.date.today()-datetime.timedelta(weeks=int(week)-1)-datetime.timedelta(days=int(NowDayDic[time.strftime("%A", time.localtime())])-1)
+			NEWTERM.startday=datetime.date.today()-datetime.timedelta(weeks=int(week)-1)-datetime.timedelta(days=int(NowDay)-1)
 		NEWTERM.put()
 		NOWUSER=db.get(user)
 		NOWUSER.nowterm=str(NEWTERM.key())

File kcbuser.pyc

  • Ignore whitespace
Binary file removed.

File main.py

View file
  • Ignore whitespace
 	return datetime.datetime.utcnow() + timedelta(hours=+8)
 
 NowDay=getCNnow().isoweekday()
+def my_urlencode(s) :
+	reprStr = repr(s).replace(r'\x', '%')
+	return reprStr[1:-1]
+def handleMultibyteUrl(func):
+  def handler(self, *paths):
+    if not paths: # 没有路径就不用转义了
+      return func(self)
 
+    newPath = []
+
+    for path in paths: # 如果有多个参数的话,将其全部转义
+      unquotedPath = unquote(path)
+      try:
+        path = unicode(unquotedPath, 'utf8')
+      except:
+        try:
+          path = unicode(unquotedPath, 'gbk')
+        except:
+          try:
+            path = unicode(unquotedPath, 'big5')
+          except:
+            try:
+              path = unicode(unquotedPath, 'shiftjis')
+            except:
+              try:
+                path = unicode(unquotedPath, 'korean')
+              except:
+                pass
+      newPath.append(path)
+    return func(self, *newPath)
+
+  return handler
+
+from urllib import unquote
 import kcbuser
 from kcbuser import kcb,kcbuser,kcbterm
 import os
 	  path = os.path.join(os.path.dirname(__file__), 'tpl','examplepage.html')
 	  self.response.out.write(template.render(path, template_values))
 class ShowHandler(webapp.RequestHandler):
-  def get(self,url):
+  def get(self,url,flag=None,subflag=None):
 	  try:
 		USER=db.GqlQuery('SELECT __key__ FROM kcbuser WHERE url = :1', url.lower())
 		user=USER[0]
 		if db.get(user).public==1:
+
 			try:
 				NowTerm=db.get(db.get(user).nowterm)
 				NoTerm=None
 				KCBs=NowTerm.kcb_set
 			except AttributeError:
 				KCBs=None
-			TermWeek=(getCNnow().date() -NowTerm.startday).days/7+1
+			#For query---
+			TermWeek=(getCNnow().date()-NowTerm.startday).days/7+1
+			if flag:
+				if flag=='nowweek':
+					WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("day").order("time")
+				
+				elif flag=='nextweek':
+					TermWeek+=1
+					WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("day").order("time")
+				
+				elif flag=='lastweek':
+					TermWeek-=1
+					WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("day").order("time")
+				
+				elif flag=='weekplus':
+					TermWeek+=int(subflag)
+					WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("day").order("time")
+				
+				
+				elif flag=='weekminus':
+					TermWeek-=int(subflag)
+					WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("day").order("time")
+				
+				
+				elif flag=='weekplus':
+					TermWeek+=int(subflag)
+					WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("day").order("time")
+				
+				
+				elif flag=='week':
+					TermWeek=int(subflag)
+					WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("day").order("time")
+				elif flag=='date' or flag=='day':
+					if flag=='date':
+						qdate=datetime.datetime(*time.strptime( subflag, "%Y%m%d" )[:6]).date()
+					elif flag=='day':
+						qdate=getCNnow().date()-datetime.timedelta(days=int(NowDay)-int(subflag))
+					# self.response.out.write(qdate)
+					qdateWeek=(qdate-NowTerm.startday).days/7+1
+					QueryKCB=NowTerm.kcb_set.filter(' week =' ,int(qdateWeek)).filter('day = ',int(qdate.isoweekday())).order("time")
+					template_values = {
+					'TERM':NowTerm,
+					'qdate':qdate,
+					'QueryKCB':QueryKCB,
+					'NowWeek':qdateWeek,
+					'NowDay':qdate.isoweekday(),
+					'USER':users.get_current_user(),
+					'NAME':db.get(user).name,
+					}
+		
+					path = os.path.join(os.path.dirname(__file__), 'tpl','bingo.html')
+					self.response.out.write(template.render(path, template_values))
+					return;
+
+				template_values = {
+				'TERM':NowTerm,
+				'WeekKCB':WeekKCB,
+				'NowWeek':TermWeek,
+				'NowDay':NowDay,
+				'USER':users.get_current_user(),
+				'NAME':db.get(user).name,
+				}
+	
+				path = os.path.join(os.path.dirname(__file__), 'tpl','bingo.html')
+				self.response.out.write(template.render(path, template_values))
+				return;
+
 			WeekKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).order("time")
 			# NowKCB=db.GqlQuery("SELECT * FROM kcb WHERE week =:1 AND  day = :2 AND  time = :3 AND term =:4 ORDER BY time ASC LIMIT 1000",int(TermWeek),int(NowDay),int(NowTime),NowTerm)
 			TodayKCB=NowTerm.kcb_set.filter(' week =' ,int(TermWeek)).filter('day = ',int(NowDay)).order("time")
 
 			path = os.path.join(os.path.dirname(__file__), 'tpl','bingo.html')
 			self.response.out.write(template.render(path, template_values))
-
+class UrlShowHandler(webapp.RequestHandler):
+	@handleMultibyteUrl
+	def get(self,path):
+	  self.redirect(my_urlencode(u'/'.encode('utf8')+path.encode('utf8')+u'/'.encode('utf8')))
 application = webapp.WSGIApplication(
                                      [('/', MainPage),
 									 ('/about', AboutPage),
 									  ('/example', ExamplelrPage),
 									  ('/query', QueryHandler),
-									  ('/(.*)', ShowHandler),
+									  ('/(.*)/(.*)/(.*)', ShowHandler),
+									  ('/(.*)/(.*)', ShowHandler),
+  									  ('/(.*)/', ShowHandler),
+  									  ('/(.*)', UrlShowHandler),
 									  ],
                                      debug=True)
 
+#nowweek|nextweek|lastweek|week|day
 def main():
   run_wsgi_app(application)
 

File tpl/bingo.html

View file
  • Ignore whitespace
-
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 <html>
 <head>
 
 <meta http-equiv="Content-Type" content="text/html; charset=utf8">
 <title>{{NAME}}的在线课程表--dxskcb--大学生课程表</title>
-<link href="../static/main.css" rel="stylesheet" type="text/css" media="all" />
+<link href="/static/main.css" rel="stylesheet" type="text/css" media="all" />
     {% include 'seo.html' %}
 </head>
   <body>
 
 
  	 {% if  WeekKCB%}
-<br /> <h1>本周课程</h1>
+<br /> <h1>第{{NowWeek}}周</h1>
 
 {% for KCB in WeekKCB %}
 <h2>{{ KCB.day }}-{{ KCB.time }}|||{{ KCB.name }}|||{{ KCB.place}}</h2>
 {% endfor %}
  {% endif %}
 
- 	 {% if  QueryKCB%}
+<!-- 	 {% if  QueryKCB%}
 <br /> <h1>{{qdate}}的课程</h1>
 
 {% for KCB in QueryKCB %}
 <h2>{{ KCB.day }}-{{ KCB.time }}|||{{ KCB.name }}|||{{ KCB.place}}</h2>
 {% endfor %}
  {% endif %}
+-->
+ 	 {% if  QueryKCB%}
+<br /> <h1>周{{NowDay}}</h1>
+
+{% for KCB in QueryKCB %}
+<h2>{{ KCB.day }}-{{ KCB.time }}|||{{ KCB.name }}|||{{ KCB.place}}</h2>
+{% endfor %}
+ {% endif %}
 
 
     {% include 'header.html' %}
-
+<!--
 <div style="float:left;">
 	 <form action="/query" method="post">
 	  <input type="hidden" name="nowweek" value='1' />
  <input type="Submit" id="submit_btn" value="本周课程" />
  </form>
  </div>
-
+-->
+<a href='nowweek'>本周课程</a>
+<a href='lastweek'>上周课程</a>
+<a href='nextweek'>下周课程</a>
+<a href='date/20110504'>20110504课程</a>
+<br />
+<a href='day/1'>周1课程</a>
+<a href='day/2'>周2课程</a>
+<a href='day/3'>周3课程</a>
+<a href='day/4'>周4课程</a>
+<a href='day/5'>周5课程</a>
+<a href='day/6'>周6课程</a>
+<a href='day/7'>周7课程</a>
 <div style="float:right;">
 
  	 <form action="/query" method="post">

File tpl/error.html.bak

  • Ignore whitespace
-<html>
-<head>
-<meta http-equiv="content-type" content="text/html; charset=UTF-8">
-<link href="/static/main.css" rel="stylesheet" type="text/css" media="all" />
-<title>Ke-Biao</title>
-</head>
-    {% include 'header.html' %}
-  
-  <body>
-<div style="text-align:center;">{{errormsg}}
-
-</div>
-
-
-
-{% include 'footer.html' %}
-</body>
-
-</html>

File tpl/signup.html.bak

  • Ignore whitespace
-
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
-<html>
-<head>
-<title>填写初始信息</title>
-<meta http-equiv="content-type" content="text/html; charset=UTF-8">
-<link href="/static/main.css" rel="stylesheet" type="text/css" media="all" />
-</head>
-
-  <body>
-
-
-
-  <div id='signup'>
-
- <fieldset>
-
-	<legend>↓填写初始信息↓</legend>
-      <form action="/signup/done" method="post"><br />
-      您的姓名:<input type="text" name="name" /><br />
-	 http://kb.gongda.tk/<input type="text" name="url" /><-在此输入你想要的短连接(shorturl)[有效字符:“a-z”(大小写不敏感)“0-9”以及“-”,和“_”,不含引号】
-	<h4>比如你的短链接是“xxx”,那么你就可以直接通过 kb.gongda.tk/xxx 或 ke-biao.appspot.com/xxx 快速访问到你的课表。
-	</h4>
-	<h4>一般情况下http://是不用输的</h4>
-	<br />
-	<br />
-	<br />
-<input type="radio" name="public" value=True  /> 公开 (所有知道你的shorturl的人均可访问到你的课程)
-<br />
-<input type="radio" name="public" value=False /> 不公开 (只有你自己登录后才可访问到你的课程)
-	<br />
-
-<p><input type="Submit" value="提交"  /></p>
-		</fieldset>
-
-    </form>
-
-
-   {% include 'footer.html' %}
-
-	  </body>
-</html>

File user.pyc

  • Ignore whitespace
Binary file removed.