私は新しい雇用に関するデータを取得し、その人に電子メールを送り、将来の使用のためにデータを保存するフォームを持つ小さなアプリケーションを持っています。すべて正常に動作していますが、私はdjangoformsとチェックボックスの使用に関する情報を見つけることができないようです。これらは明らかにブール値ですが、db.Boolean値をdb.Modelクラスに追加し、生成するdjangoforms.ModelFormクラスを持っていれば何も表示されません。私はそれを私のdb>モデルに追加し、レコードのデフォルトをfalseに作成しますが、フォームから変更する方法はありません。また、db.Textもfielを生成しません。私はおそらく、これが私の最初のGAEとDjangoプロジェクトであるため、ここでは十分明確ではないでしょう。コードはGoogle App EngineでdjangoTemplateとdb.Modelを使用する
import cgi
import wsgiref.handlers
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import mail
from google.appengine.ext.db import djangoforms
class Item(db.Model):
first_name = db.StringProperty()
last_name = db.StringProperty()
goes_by = db.StringProperty()
Studio = db.StringProperty()
Discipline = db.StringProperty()
position = db.StringProperty()
level = db.StringProperty(default='choice', choices=['choice', 'choice',
'choice', 'choice', 'choice', 'choice'])
start_date = db.DateTimeProperty()
buddy_name = db.StringProperty()
past_employee = bool()
email = db.EmailProperty()
cell_phone = db.PhoneNumberProperty()
phone = db.PhoneNumberProperty()
hire_type = db.StringProperty(default='Full Time',choices=[
'Temp', 'Intern', 'Contract', 'Full Time'])
seating_location = db.StringProperty()
additional_comments = db.Text()
entry_time = db.DateTimeProperty(auto_now_add=True)
added_by = db.UserProperty()
class ItemForm(djangoforms.ModelForm):
class Meta:
model = Item
exclude = ['added_by']
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('<html><body><head><link type="text/css" rel="stylesheet" href="/stylesheets/form.css"></head>'
'<div id=header><div id="logo><img src="/img/placeimg.gif"></div><div id ="headertxt"><h2>Place New Hire Portal</h2>'
'<p>Please filll out this form as accurately as possible, this information is used to create employee files and to setup IS equipment</div> '
'</div><div id="contain">'
'<form method="POST" '
'action="/">'
'<table>')
# This generates our fields and writes it in the response
self.response.out.write(ItemForm())
self.response.out.write('</table>'
'<input type="submit">'
'</form></div></body></html>')
def post(self):
data = ItemForm(data=self.request.POST)
if data.is_valid():
# Save the data, and redirect to the view page
entity = data.save(commit=False)
entity.added_by = users.get_current_user()
entity.put()
self.redirect('/items.html')
mailing_address = ("[email protected]")
sender_address = ("[email protected]")
subject = "A new hire has been made - Please begin Process"
body = ("""
The Following Person is scheduled to start at place on :
%s %s - %s \ %s - %s - %s
Please find the orientation template attached. In order to be sure all employees are oriented in the same way
please be sure to cover the items listed under your name.
In addition, afer the completion of your session, please escort the new hire to the next session and makle introductions. This will
ensure that the schedule continues in order.
Buddy, thank you very much for being a buddy to %s, Your time and lunch expenses should be charged to your Studio Operations number. Thank you
very much for helping %s with their transiton to Place."""
%(entity.first_name, entity.last_name, entity.Studio, entity.Discipline, entity.seating_location,
entity.buddy_name, entity.first_name, entity.first_name))
mail.send_mail(sender_address, mailing_address, subject, body)
else:
# Reprint the form
self.response.out.write('<html><body>'
'<form method="POST" '
'action="/">'
'<table>')
self.response.out.write(data)
self.response.out.write('</table>'
'<input type="submit">'
'</form></body></html>')
class ItemPage(webapp.RequestHandler):
def get(self):
self.response.out.write('</br></br><a href="/">Return to Form Entry</a></br></br>')
query = db.GqlQuery("SELECT * FROM Item ORDER BY first_name")
for item in query:
self.response.out.write('<a href="/edit?id=%d">Edit</a> - ' %
item.key().id())
self.response.out.write("%s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s </br>"%
(item.first_name, item.last_name, item.goes_by, item.Studio, item.Discipline, item.position,
item.level, item.start_date, item.past_employee, item.cell_phone, item.seating_location,
item.additional_comments, item.email, item.phone, item.hire_type))
class EditPage(webapp.RequestHandler):
def get(self):
id = int(self.request.get('id'))
item = Item.get(db.Key.from_path('Item', id))
self.response.out.write('<html><body>'
'<form method="POST" '
'action="/edit">'
'<table>')
self.response.out.write(ItemForm(instance=item))
self.response.out.write('</table>'
'<input type="hidden" name="_id" value="%s">'
'<input type="submit">'
'</form></body></html>' % id)
def post(self):
id = int(self.request.get('_id'))
item = Item.get(db.Key.from_path('Item', id))
data = ItemForm(data=self.request.POST, instance=item)
if data.is_valid():
# Save the data, and redirect to the view page
entity = data.save(commit=False)
entity.added_by = users.get_current_user()
entity.put()
self.redirect('/items.html')
else:
# Reprint the form
self.response.out.write('<html><body>'
'<form method="POST" '
'action="/edit">'
'<table>')
self.response.out.write(data)
self.response.out.write('</table>'
'<input type="hidden" name="_id" value="%s">'
'<input type="submit">'
'</form></body></html>' % id)
def main():
application = webapp.WSGIApplication(
[('/', MainPage),
('/edit', EditPage),
('/items.html', ItemPage),
],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__=="__main__":
main()
は 'TextProperty'と' BooleanProperty'でなければなりません。 'db.Text'は単に' Property'サブクラスではなく 'datastore_types.Text'へのエイリアスであり、' db.Boolean'は私が見る限り例外を発生させるべきです。 – geoffspear
@wooble db.Booleanはありましたが、bool()は実行しませんでした。 – Kevin