• R/O
  • SSH
  • HTTPS

aoiso: 提交


Commit MetaInfo

修订版59 (tree)
时间2011-05-12 00:26:35
作者hwakimoto

Log Message

(empty log message)

更改概述

差异

--- testarea/wakimoto-test/src/index.yaml (revision 58)
+++ testarea/wakimoto-test/src/index.yaml (revision 59)
@@ -10,6 +10,12 @@
1010 # automatically uploaded to the admin console when you next deploy
1111 # your application using appcfg.py.
1212
13+- kind: MyChip
14+ properties:
15+ - name: user
16+ - name: create_time
17+ direction: desc
18+
1319 - kind: MyData
1420 properties:
1521 - name: user
--- testarea/wakimoto-test/src/sample.py (revision 58)
+++ testarea/wakimoto-test/src/sample.py (revision 59)
@@ -9,11 +9,13 @@
99 from google.appengine.api import users
1010
1111 #自己参照型のツリーノード
12-class MyNode(db.Model):
12+class MyChip(db.Model):
1313 user = db.UserProperty(required=True)
14- parent_node = db.SelfReferenceProperty(required=False)
15- title = db.StringProperty(required=True,multiline=False)
16- content = db.StringProperty(multiline=True)
14+ parent_chip = db.SelfReferenceProperty(required=False)
15+ ref_type = db.IntegerProperty() #使用方法未定。訂正/追記などのステータス
16+ priority_type = db.IntegerProperty() #使用方法未定。
17+ security_type = db.IntegerProperty() #使用方法未定。
18+ content = db.StringProperty(multiline=False)
1719 create_time = db.DateTimeProperty(auto_now_add=True)
1820 update_time = db.DateTimeProperty(auto_now_add=True)
1921
@@ -24,54 +26,66 @@
2426 #あとでどっか移動させる
2527
2628 #parentがないノードは一つだけという仕様
27- def get_root_node(self, user):
28- node = MyNode.all().filter('user', user).filter('parent',None).get()
29- if node == None:
30- node = MyNode(user=user,title='root',content='',parent=None)
31- node.save()
32- return node
29+ def get_root_chip(self, user):
30+ chip = MyChip.all().filter('user', user).filter('parent_chip',None).get()
31+ if chip == None:
32+ chip = MyChip(user=user,content='root',parent_chip=None)
33+ chip.save()
34+ return chip
3335
3436 #------------------------------------------------------------------------------------
3537
3638 def get(self):
3739 user = users.get_current_user()
38- self.get_root_node(user) #初回の場合ここでroot作成
3940 if user == None:
4041 self.redirect(users.create_login_url(self.request.uri))
4142 return
43+ self.get_root_chip(user) #初回の場合ここでroot作成
4244
43- nodes = MyNode.all().filter('user', user).order('-create_time').fetch(10, 0)
45+ chips = MyChip.all().filter('user', user).order('-create_time').fetch(100, 0)
4446 logouturl = users.create_logout_url(self.request.uri)
45- params = {'nodes':nodes,'message':'ああああ','logouturl':logouturl}
47+# params = {'chips':chips,'message':'ああああ','logouturl':logouturl}
48+ params = {'chips':chips,'logouturl':logouturl}
4649 fpath = os.path.join(os.path.dirname(__file__),'views','sample.html')
4750 html = template.render(fpath,params)
4851 self.response.headers['Content-Type'] = 'text/html'
4952 self.response.out.write(html)
5053
51- def post(self):
54+ def post(self): #現時点ではすべてのchipがrootの直下
5255 user = users.get_current_user()
53- title = self.request.get('title')
5456 content = self.request.get('content')
55- parent_id = self.request.get('parent_id')
56-
57- #タイトル内が/で区切られていたらその階層の親を作る
58- title_tree = title.split('/')
59- #親の確認or生成
60- if parent_id=="0":
61- parent_node = self.get_root_node(user)
62- else:
63- parent_node = MyNode.get_by_id(long(parent_id))
64- #parent_idからたどってその子の中に同名ノードがある場合のみそれを目的の親ノードと見なす
65- for i in range (0,len(title_tree)-2):
66- p_node = MyNode.all().filter('user', user).filter('parent_node',parent_node).filter('title',title_tree[i]).get()
67- if p_node == None:
68- p_node = MyNode(user=user,title=title_tree[i],content='',parent_node=parent_node)
69- p_node.save()
70- parent_node = p_node
71- node = MyNode(user=user,title=title_tree[len(title_tree)-1],content=content,parent_node=parent_node)
72- node.save()
57+ parent_chip = self.get_root_chip(user)
58+ chip = MyChip(user=user,content=content,parent_chip=parent_chip)
59+ chip.save()
7360 self.redirect('/')
7461
62+ #===========================================================================
63+ # 旧ソース(タイトルで自動階層)
64+ # def post(self):
65+ # user = users.get_current_user()
66+ # title = self.request.get('title')
67+ # content = self.request.get('content')
68+ # parent_id = self.request.get('parent_id')
69+ #
70+ # #タイトル内が/で区切られていたらその階層の親を作る
71+ # title_tree = title.split('/')
72+ # #親の確認or生成
73+ # if parent_id=="0":
74+ # parent_chip = self.get_root_chip(user)
75+ # else:
76+ # parent_chip = MyChip.get_by_id(long(parent_id))
77+ # #parent_idからたどってその子の中に同名ノードがある場合のみそれを目的の親ノードと見なす
78+ # for i in range (0,len(title_tree)-2):
79+ # p_chip = MyChip.all().filter('user', user).filter('parent_chip',parent_chip).filter('title',title_tree[i]).get()
80+ # if p_chip == None:
81+ # p_chip = MyChip(user=user,title=title_tree[i],content='',parent_chip=parent_chip)
82+ # p_chip.save()
83+ # parent_chip = p_chip
84+ # chip = MyChip(user=user,title=title_tree[len(title_tree)-1],content=content,parent_chip=parent_chip)
85+ # chip.save()
86+ # self.redirect('/')
87+ #===========================================================================
88+
7589
7690 application = webapp.WSGIApplication([
7791 ('/', MainPage),
--- testarea/wakimoto-test/src/views/sample.html (revision 58)
+++ testarea/wakimoto-test/src/views/sample.html (revision 59)
@@ -2,50 +2,116 @@
22 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
33 <html xmlns="http://www.w3.org/1999/xhtml"
44 xml:lang="ja" lang="ja">
5- <head>
6- <meta http-equiv="Content-Type"
7- content="text/html; charset=UTF-8" />
8- <title>Home</title>
9- </head>
10- <body>
11- <h1>Home Page</h1>
12- <p>{{message}}</p>
5+ <head>
6+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
7+ <title>Home</title>
8+ <style type="text/css">
9+ div.main_area {
10+ width : 700px;
11+ }
12+ div.entry_area {
13+ border : 1px solid #666;
14+ padding : 5px;
15+ }
16+ div.timeline {
17+ border : 1px solid #666;
18+ }
19+ div.chip {
20+ border : 1px solid #669;
21+ padding : 5px;
22+ margin : 5px;
23+ }
24+ div.chip_id {
25+ font-size : 10pt;
26+ float : left;
27+ margin : 2px;
28+ }
29+ div.chip_parent {
30+ font-size : 10pt;
31+ margin : 2px;
32+ }
33+ div.chip_content {
34+ font-size : 12pt;
35+ margin : 2px;
36+ padding : 15px;
37+ }
38+ div.chip_datetime {
39+ font-size : 10pt;
40+ margin : 2px;
41+ }
42+ </style>
43+
44+ <script type="text/javascript">
45+
46+ //code from http://jsajax.com/Articles/formfieldlimiter/684
47+
48+ var ns6=document.getElementById&&!document.all
49+
50+ function restrictinput(maxlength,e,placeholder){
51+ if (window.event&&event.srcElement.value.length>=maxlength)
52+ return false
53+ else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
54+ var pressedkey=/[a-zA-Z0-9\.\,\/]/
55+ if (pressedkey.test(String.fromCharCode(e.which)))
56+ e.stopPropagation()
57+ }
58+ }
59+
60+ function countlimit(maxlength,e,placeholder){
61+ var theform=eval(placeholder)
62+ var lengthleft=maxlength-theform.value.length
63+ var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
64+ if (window.event||e.target&&e.target==eval(placeholder)){
65+ if (lengthleft<0)
66+ theform.value=theform.value.substring(0,maxlength)
67+ placeholderobj.innerHTML=lengthleft
68+ }
69+ }
70+
71+ function displaylimit(thename, theid, thelimit){
72+ var theform=theid!=""? document.getElementById(theid) : thename
73+ var limit_text='残り文字数: ' + '<b><span id="' + theform.toString() + '">' + thelimit + '</span></b>'
74+
75+ if (document.all||ns6)
76+ document.write(limit_text)
77+ if (document.all){
78+ eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
79+ eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
80+ }
81+ else if (ns6){
82+ document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
83+ document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
84+ }
85+ }
86+
87+ </script>
88+ </head>
89+ <body>
90+ <h1>独り言ツイート</h1>
91+ <p>{{message}}</p>
92+ <div class="main_area">
93+ <div class="entry_area">
1394 <form method="post" action="/">
14- <table>
15- <tr>
16- <th>タイトル:</th>
17- <td><input type="text" name="title" /></td>
18- </tr>
19- <tr>
20- <th>本文:</th>
21- <td><textarea name="content"></textarea></td>
22- </tr>
23- <tr><th></th>
24- <td><input type="submit" value="送信" /></td></tr>
25- </table>
95+ <textarea name="content" id="textarea1" rows="5" cols="60"></textarea>
96+ <script type="text/javascript">
97+ displaylimit("","textarea1",140)
98+ </script>
99+ <input type="submit" value="送信" />
26100 <input type="hidden" name="parent_id" value="0" />
27- </form>
28- <hr />
29- <table border="1" width="500px">
30- <tr>
31- <th width="50px">id</th>
32- <th width="50px">parent_id</th>
33- <th width="150px">タイトル</th>
34- <th width="350px">本文</th>
35- <th width="150px">作成日</th>
36- <th width="150px">更新日</th>
37- </tr>
38- {% for node in nodes %}
39- <tr>
40- <td>{{node.key.id}}</td>
41- <td>{{node.parent_node.key.id}}</td>
42- <td>{{node.title}}</td>
43- <td>{{node.content}}</td>
44- <td>{{node.create_time}}</td>
45- <td>{{node.update_time}}</td>
46- </tr>
101+ </form>
102+ </div><!-- entry_area -->
103+ <hr />
104+ <div class="timeline">
105+ {% for chip in chips %}
106+ <div class="chip">
107+ <div class="chip_id">{{chip.key.id}}</div>
108+ <div class="chip_parent">{{chip.parent_chip.key.id}}</div>
109+ <div class="chip_content">{{chip.content}}</div>
110+ <div class="chip_datetime">{{chip.create_time}}</div>
111+ </div><!-- chip -->
47112 {% endfor %}
48- </table>
49- <a href="{{logouturl}}">logout</a>
50- </body>
113+ </div><!-- timeline -->
114+ </div><!-- main_area -->
115+ <a href="{{logouturl}}">logout</a>
116+ </body>
51117 </html>
\ No newline at end of file
Show on old repository browser