Anonymous avatar Anonymous committed 233bef8

Add: account.html は終了、home_timeline 作業中。

Comments (0)

Files changed (7)

 # vim: fileencoding=utf8
 
+from django import newforms as forms
+
+from google.appengine.api import users
 from google.appengine.ext.db import djangoforms
 
 from models import Account, Status
 
 class AccountForm(djangoforms.ModelForm):
+  user = djangoforms.UserProperty().get_form_field(initial=None, label='Email')
   class Meta:
     model = Account
     exclude = ['user', 'created']
   >>> account = Account()
   >>> account.user = user
   >>> account.account_name = u'test'
-  >>> db.save(account)
+  >>> db.put(account)
   """
   user = db.UserProperty(required=True)
   account_name = db.StringProperty(required=True)
   >>> db.save(account)
   >>> status = Status()
   >>> status.text = u'test message.'
-  >>> db.save(status)
+  >>> db.put(status)
   """
-#  status_id = db.IntegerProperty(required=True)
   account = db.ReferenceProperty(Account)
   text = db.StringProperty(required=True)
   created = db.DateTimeProperty(auto_now_add=True)

templates/account.html

-<form>
-  {{ form }}
+<form method="POST" action="/account/">
+  <table>
+    {{ form }}
+  </table>
+  <p><input type="submit" value="submit" /></p>
 </form>
 {% for account in accounts %}
-  {{ account.created }}, {{ account.account_name }}
+<div>{{ account.created }}, {{ account.account_name }}, {{ account.user.email }}</div>
 {% endfor %}

templates/base.html

+<html>
+<head>
+  <title>{{ }}</title>
+</head>
+<body>
+{% if not public_timeline %}
+まだステータスが一つも存在しません
+{% endif %}
+{% for status in public_timeline %}
+  {{ status.account.account_name }}, {{ status.text }} <br />
+{% endfor %}
+</body>
+</html>
+

templates/home_timeline.html

-<form>
+<form method="POST" action="/home/">
   {{ form }}
+  <input type="submit" value="submit" /><br />
 </form>
+{% for status in home_timeline %}
+  {{ status.account.account_name }}, {{ status.text }} <br />
+{% endfor %}

templates/public_timeline.html

+<html>
+<head>
+  <title>monologista</title>
+</head>
+<body>
 {% for status in public_timeline %}
   {{ status.account.account_name }}, {{ status.text }} <br />
 {% endfor %}
+</body>
+</html>
 import os
 
 from google.appengine.ext import webapp
+from google.appengine.ext import db
 from google.appengine.api import users
 from google.appengine.ext.webapp import template
 
 class AccountHandler(webapp.RequestHandler):
   def get(self):
     """
-    {{ account.form }}
+    {{ form }}
     {% for account in accounts %}
       {{ account.account_name }}: {{ account.user.mail }}<br />
     {% endfor %}
     """
     user = users.get_current_user()
     if not users.is_current_user_admin():
-      return self.redirect("/")
+      return self.redirect('/')
     accounts = Account.all()
     form = AccountForm()
     dictionary = {
     form = AccountForm(data=self.request.POST)
     if form.is_valid():
       account = form.save(commit=False)
-      account.user = user
       db.put(account)
-      return self.redirect('/home/')
-    else:
-      accounts = Account.all()
-      form = AccountForm()
-      dictionary = {
-        'accounts': accounts,
-        'form': form,
-      }
-      return render_to_response(self, dictionary, 'account.html')
+      return self.redirect('/account/')
+    accounts = Account.all()
+    dictionary = {
+      'accounts': accounts,
+      'form': form,
+    }
+    return render_to_response(self, dictionary, 'account.html')
 
 class PublicTimelineHandler(webapp.RequestHandler):
   """
     user = users.get_current_user()
     oneself = get_account_from_user(user)
     if not user or not oneself:
-      return self.redirect("/")
+      return self.redirect('/')
+    form = AccountForm(data=self.request.POST)
+    if form.is_valid():
+      status = form.save(commit=False)
+      db.put(status)
+      return self.redirect('/home/')
+    home_timeline = Status.all()
     dictionary = {
       'home_timeline': home_timeline,
       'oneself': oneself,
+      'form': form,
     }
-    return render_to_response(self, dictionary, 'home_timeline.html')
+    return self.redirect('/home/')
 
 class StatusDetailHandler(webapp.RequestHandler):
   def get(self, account_name, status_id):
     """
     {{ oneself.account_name }}
+    {{ status.account.account_name }}
     {{ status.key.id }}
     """
-    #status_account = Account.get_by_key_name(key_name=account_name)
     status = Status.get_by_id(status_id)
     if not status:
       self.error(404)
   def get(self, account_name):
     user = users.get_current_user()
     oneself = Account.all().filter('user =', user).get()
-    if not oneself:
+    account = get_account_from_account_name(account_name)
+    if not account:
       self.error(404)
       return self.response.out.write('404')
-    account = Account.get_by_key_name(account_name)
     user_timeline = Status.all().filter('account =', account)
     dictionary = {
       'oneself': oneself,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.