Commits

gao shuai  committed 4f38aa5

tidy

  • Participants
  • Parent commits fb63e8d

Comments (0)

Files changed (10)

-application: wdfanyi
+application: kubaofy
 version: test
 runtime: python
 api_version: 1
   - name: ctr
     direction: desc
   - name: time
+
+- kind: words
+  properties:
+  - name: ctr
     direction: desc
+  - name: time
+    direction: desc
 # -*- coding: utf-8 -*-
+PAGE_SIZE=10
+import math
 import urllib
 import os
 from urllib import unquote
 class swap(db.Model):
 	time = db.DateTimeProperty()
 	content=db.TextProperty()
+class li(db.Model):
+	time = db.DateTimeProperty()
+	content=db.StringProperty()
 def en2c(text):
 	httplib.HTTPConnection.debuglevel = 1
 	url_t = "http://ajax.googleapis.com/ajax/services/language/translate"
 			WIKIS=wiki.all().order("-time").fetch(limit=3)
 			SWAPS=swap.all().order("-time").fetch(limit=2,offset=0)
 			LASTSWAP=swap.all().order("-time").fetch(limit=1)[0].content
+			LIS=li.all().order("-time").fetch(limit=2,offset=0)
+			LASTLI=li.all().order("-time").fetch(limit=1)[0].content
 		except IndexError:
 			WORDS=None
 			WIKIS=None
 			SWAPS=None
 			LASTSWAP=None
+			LIS=None
+			LASTLI=None
 		template_values = {
-		'WORDS':WORDS,
+		'WORDSS':WORDS,
 		'WIKIS':WIKIS,
 		'SWAPS':SWAPS,
 		'LASTSWAP':LASTSWAP,
+		'LIS':LIS,
+		'LASTLI':LASTLI,
 		}
 		# self.before()
 		if flag=='':
 		self.write(template.render(path, template_values))
 class ShowAll(yui.HtmlRequestHandler):
 	def get(self,flag):
-		if flag=='fy':
-			WORDS=words.all().order("-time")
-			template_values = {
-			'WORDS':WORDS,
-			}
-			path = os.path.join(os.path.dirname(__file__), 'tpl','%s.html'%flag)
-			self.write(template.render(path, template_values))
-		if flag=='wiki':
-			WIKIS=wiki.all().order("-time")
-			template_values = {
-			'WIKIS':WIKIS,
-			}
-			path = os.path.join(os.path.dirname(__file__), 'tpl','%s.html'%flag)
-			self.write(template.render(path, template_values))
-		if flag=='swap':
-			SWAPS=swap.all().order("-time")
-			template_values = {
-			'SWAPS':SWAPS,
-			}
-			path = os.path.join(os.path.dirname(__file__), 'tpl','%s.html'%flag)
-			self.write(template.render(path, template_values))
+		page_current=int(self.request.get('p') or '1')
+		exec('''LIS=%s.all().order("-time")'''%flag)
+		pages=math.floor(LIS.count()/PAGE_SIZE)+1
+		exec('''LIS=%s.all().order("-time").fetch(PAGE_SIZE,PAGE_SIZE*(page_current-1))'''%flag)
+		ps=[i for i in range(1,pages+1)]
+		template_values = {
+		'%s'%(flag.upper()+'S'):LIS,
+		'pages': pages,
+		'ps': ps,
+		'page_current': page_current,
+		}
+		path = os.path.join(os.path.dirname(__file__), 'tpl','%s.html'%flag)
+		self.write(template.render(path, template_values))
 class ShowAllPhone(yui.HtmlRequestHandler):
 	def get(self):
 		# self.before()
 		WORD.user='weakdancer'
 
 		if ord(text[0])<=127:
-			WORD.EN=text
+			WORD.EN=text.strip().lower()
 			WORD.CN=en2c(text)
 		else:
 			WORD.CN=text
-			WORD.EN=c2en(text)
+			WORD.EN=c2en(text).strip()
+
 		WORD.time=getCNnow()
 		WORD.put()
 		self.write(WORD.EN)
 	def post(self):
-		text=self.request.get('word')
+		text=self.request.get('word').strip().lower()
 		WORD=words()
 		WORD.user='weakdancer'
 		if ord(text[0])<=127:
 		WORD.time=getCNnow()
 		WORD.put()
 		self.write(WORD.EN)
-		self.redirect('/fy')
+		self.redirect('/words')
 
 class RememberPage(yui.HtmlRequestHandler):
 	def get(self):
-		WORDS=words.all().order('-ctr').order('-time').fetch(8)
+		WORDS=words.all().order('-ctr').order('time').fetch(8)
 		template_values = {
 		'WORDS':WORDS,
 		}
 			SWAP.put()
 			self.redirect('/swap')
 
+
+class LiHandler(yui.HtmlRequestHandler):
+	def post(self,flag):
+		if flag == 'new':
+			contents=self.request.get('content').split('\n')
+			for content in contents:
+				LI=li()
+				LI.content=content
+				LI.time=getCNnow()
+				LI.put()
+			self.redirect('/li')
+
+
+class sdfdfHandler(yui.HtmlRequestHandler):
+	def get(self):
+		WORDS=words.all()
+		for  WORD in WORDS:
+			WORD.EN=WORD.EN.strip().lower()
+			WORD.put()
+		self.redirect('/sfsdfsdfsdfsdfdsfsdf')
+
 class NotFound(yui.HtmlRequestHandler):
 	@yui.server_cache(60, False)
 	def get(self):
 	  self.write(template.render(path, template_values))
 application = yui.WsgiApplication([
 	# ('/', Hello),
-	('/(fy|wiki|swap|)', Mainpage),
-	('/show/(.*)', ShowAll),
+	('/(words|wiki|swap|li|)', Mainpage),
+	('/show/(words|wiki|swap|li)', ShowAll),
 	('/showphone', ShowAllPhone),
 	('/del', Admin),
 	('/translate', TranslateHandler),
 	('/r/(.*)', RememberPage),
 	('/wiki/(.*)', WikiHandler),
 	('/swap/(.*)', SwapHandler),
+	('/li/(.*)', LiHandler),
+	('/lskjlkfdkf', sdfdfHandler),
 	('.*', NotFound) # not existing, expected to be 404 not found
 ])
 

File tpl/footer.html

+<div class="inner" align="center" style="font-size:24px;">
+                    {% for p in ps %}{% ifequal p page_current %}<span class="page_current">第{{ p }}页</span>{% else %}<a href="?p={{ p }}" class="page_normal">第{{ p }}页</a>{% endifequal %}{% endfor %}
+</div>

File tpl/fy.html

-
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
-<html>
-<head>
-<title>wdfanyi</title>
-<meta http-equiv="Content-Type" content="text/html; charset=utf8">
-<link href="../static/main.css" rel="stylesheet" type="text/css" media="all" />
-    {% include 'seo.html' %}
-</head>
-  <body>
-
-
-
-<div style="text-align:center;float:center;width:auto;margin-right: auto; margin-left: auto;">
-
-	{% for WORD in WORDS %}
-	<fieldset>
-
-		<legend>{{WORD.time|date:"Y年m月d日 H时i分"}}</legend>
-
-
-	<p>{{WORD.EN}}</p>
-
-		<hr class="l" />
-	<p>{{WORD.CN}}</p>
-	<div style="font-size:12px;color:#630;float:left;"></div>
-
-	<div style="font-size:12px;color:#000;float:right;"></div>
-
-	</fieldset>
-
-	{% endfor %}
-
-	<form action="/translate" method="post">
-		<fieldset>
-		<legend>翻译</legend>
-		<div>	<textarea rows="5" cols="40" name='word'></textarea></div>
-		<input type="submit" class="btn3" value="提交" >
-		</fieldset>
-		</form>
-
-</div>
-
-
-
-    {% include 'header.html' %}
-  {% include 'footer.html' %}
-  </body>
-</html>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+<title>wdfanyi</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf8">
+<link href="../static/main.css" rel="stylesheet" type="text/css" media="all" />
+    {% include 'seo.html' %}
+</head>
+  <body>
+
+
+<div style="float:auto;width:auto;margin-right: auto; margin-left: auto;">
+	{% for LI in LIS %}
+	<fieldset>
+
+		<legend>{{LI.time|date:"Y年m月d日 H时i分"}}</legend>
+
+	<pre>{{LI.content|escape}}</pre>
+
+	<div style="font-size:12px;color:#630;float:left;"></div>
+
+	<div style="font-size:12px;color:#000;float:right;"></div>
+
+	</fieldset>
+	{% endfor %}
+			<form action="/li/new" method="post">
+		<fieldset>
+		<legend>LI</legend>
+		<div>	<textarea name='content'>{{LASTLI|escape}}</textarea></div>
+		<input type="submit" class="btn3" value="提交" >
+		</fieldset>
+		</form>
+</div>
+
+
+
+    {% include 'header.html' %}
+  {% include 'footer.html' %}
+  </body>
+</html>

File tpl/mainpage.html

 
 <div style="text-align:center;float:left;width:30%;">
 <fieldset>
-<legend><a href='/show/fy'>FY</a></legend>
-	{% for WORD in WORDS %}
+<legend><a href='/show/words'>WORDS</a></legend>
+	{% for WORD in WORDSS %}
 	<fieldset>
 
 		<legend>{{WORD.time|date:"Y年m月d日 H时i分"}}</legend>
 
-
+<div class="word"><object data="http://www.google.com/dictionary/flash/SpeakerApp16.swf" type="application/x-shockwave-flash" id="pronunciation" height="36" width=" 36">
+    <param name="movie" value="http://www.google.com/dictionary/flash/SpeakerApp16.swf">
+    <param name="flashvars" value="sound_name=http://www.gstatic.com/dictionary/static/sounds/de/0/{{WORD.EN}}.mp3">
+    <param name="wmode" value="transparent">
+    <a href="http://www.gstatic.com/dictionary/static/sounds/de/0/{{WORD.EN}}.mp3"><img src="http://www.google.com/dictionary/flash/SpeakerOffA16.png" alt="发音" height="16" width="16" border="0"></a>
+    </object></div>
 	<p>{{WORD.EN|escape}}</p>
 
 		<hr class="l" />
 		</fieldset>
 		</form>
 </div>
-
+<!--
 <div style="text-align:center;float:left;width:30%;">
 <fieldset>
 <legend><a href='/show/wiki'>WIKI</a></legend>
 		</fieldset>
 		</form>
 </div>
+-->
+<div style="float:left;width:20%">
+		<form action="/li/new" method="post">
+		<fieldset>
+		<legend><a href='/show/li'>LI</a></legend>
+		<div>	<textarea  name='content'>{{LASTLI|escape}}</textarea></div>
+		<input type="submit" class="btn3" value="提交" >
+
+		</form>
+{% for LI in LIS %}
+	<fieldset>
+
+		<legend>{{LI.time|date:"Y年m月d日 H时i分"}}</legend>
+
+	<pre>{{LI.content|escape}}</pre>
+
+
+
+	</fieldset>
+	{% endfor %}
+</fieldset>
+</div>
 
 <div style="float:left;width:25%">
 		<form action="/swap/new" method="post">

File tpl/remember.html

 	<legend><a href="http://dict.youdao.com/m/search?keyfrom=dict.mindex&vendor=$vendor&q={{WORD.EN}}">{{WORD.EN}}</a></legend>
 
 {{WORD.ctr}}
-<form action="/r/r" method="post">
+<!--<form action="/r/r" method="post">
 <input type="hidden" name='item' value={{WORD.key}}   />
 <input type="Submit"  value="记下一次"  />
 </form>
 <form action="/r/reset" method="post">
 <input type="hidden" name="item" value= {{WORD.key}} >
 <input type="Submit" value="难记"  />
-</form>
+</form>-->
 <form action="/r/del" method="post">
 <input type="hidden" name="item" value= {{WORD.key}} >
 <input type="Submit" value="记住了"  />

File tpl/words.html

+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+<title>wdfanyi</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf8">
+<link href="../static/main.css" rel="stylesheet" type="text/css" media="all" />
+    {% include 'seo.html' %}
+</head>
+  <body>
+
+
+
+<div style="text-align:center;float:center;width:auto;margin-right: auto; margin-left: auto;">
+
+	{% for WORD in WORDSS %}
+	<fieldset>
+
+		<legend>{{WORD.time|date:"Y年m月d日 H时i分"}}</legend>
+
+<div class="word"><object data="http://www.google.com/dictionary/flash/SpeakerApp16.swf" type="application/x-shockwave-flash" id="pronunciation" height="36" width=" 36">
+    <param name="movie" value="http://www.google.com/dictionary/flash/SpeakerApp16.swf">
+    <param name="flashvars" value="sound_name=http://www.gstatic.com/dictionary/static/sounds/de/0/{{WORD.EN}}.mp3">
+    <param name="wmode" value="transparent">
+    <a href="http://www.gstatic.com/dictionary/static/sounds/de/0/{{WORD.EN}}.mp3"><img src="http://www.google.com/dictionary/flash/SpeakerOffA16.png" alt="发音" height="16" width="16" border="0"></a>
+    </object></div>
+	<p>{{WORD.EN}}</p>
+<a href="http://dict.baidu.com/s?wd={{WORD.EN}}">百度</a>
+<a href="http://dict.cn/{{WORD.EN}}">海词</a>
+<a href="http://hk.dictionary.yahoo.com/dictionary?p={{WORD.EN}}">雅虎</a>||
+<a href="http://www.google.com/dictionary?langpair=en|en&q={{WORD.EN}}">google</a>
+<a href="http://www.thefreedictionary.com/{{WORD.EN}}">3dictionary</a>
+<a href="http://dictionary.reference.com/browse/{{WORD.EN}}">dictionary</a>
+		<hr class="l" />
+	<p>{{WORD.CN}}</p>
+	<div style="font-size:12px;color:#630;float:left;"></div>
+
+	<div style="font-size:12px;color:#000;float:right;"></div>
+
+	</fieldset>
+
+	{% endfor %}
+
+	<form action="/translate" method="post">
+		<fieldset>
+		<legend>翻译</legend>
+		<div>	<textarea rows="5" cols="40" name='word'></textarea></div>
+		<input type="submit" class="btn3" value="提交" >
+		</fieldset>
+		</form>
+
+</div>
+
+
+
+    {% include 'header.html' %}
+  {% include 'footer.html' %}
+  </body>
+</html>

File yui.pyc

Binary file modified.