更新0 因爲最初它是其中包括兩個複選框和文本輸入字段,而不僅僅是文本輸入域數字形式,這是在基地我def post()
代碼已經面目全非目前的設計更像紙張。但是,結果我還有其他問題可以通過提出的解決方案之一解決,但我不能完全遵循所提出的解決方案,所以讓我試着解釋新的設計和問題。我需要在谷歌的AppEngine使用交易
較小的問題是我的執行效率低下,因爲在def post()
我爲每個輸入時隙這是一個很長的字符串<courtname><timeslotstarthour><timeslotstartminute>
創建一個獨特的name
。在我的代碼中,這個name
在嵌套的for
循環中被讀取,下面的代碼片段[非常低效,我想]。
tempreservation=courtname+str(time[0])+str(time[1])
name = self.request.get('tempreservation',None)
更緊迫的嚴重問題是,我def post()
代碼是從來沒有讀過,我想不通爲什麼(也許它沒有被前閱讀,要麼,但我還沒有測試到這一步)。我想知道現在的問題是,我想同時發佈帖子和「完成」。下面的第一行是post(),第二行是get()。
return webapp2.redirect("/read/%s" % location_id)
self.render_template('read.html', {'courts': courts,'location': location, ... etc ...}
我的新帖子()如下。注意我在代碼中留下了logging.info
以查看我是否曾經到過那裏。
class MainPageCourt(BaseHandler):
def post(self, location_id):
logging.info("in MainPageCourt post ")
startTime = self.request.get('startTime')
endTime = self.request.get('endTime')
day = self.request.get('day')
weekday = self.request.get('weekday')
nowweekday = self.request.get('nowweekday')
year = self.request.get('year')
month = self.request.get('month')
nowmonth = self.request.get('nowmonth')
courtnames = self.request.get_all('court')
for c in courtnames:
logging.info("courtname: %s " % c)
times=intervals(startTime,endTime)
for courtname in courtnames:
for time in times:
tempreservation=courtname+str(time[0])+str(time[1])
name = self.request.get('tempreservation',None)
if name:
iden = courtname
court = db.Key.from_path('Locations',location_id,'Courts', iden)
reservation = Reservations(parent=court)
reservation.name = name
reservation.starttime = time
reservation.year = year
reservation.nowmonth = int(nowmonth)
reservation.day = int(day)
reservation.nowweekday = int(nowweekday)
reservation.put()
return webapp2.redirect("/read/%s" % location_id)
最後,我想與隱含的新的保留數據存儲上的現有的預訂數據進行比較,增加檢查/驗證上面的get()的代碼,並踢出來告訴任何潛在的用戶警報她可以解決的問題。
我也希望對這兩個問題有任何意見。
更新結束0
我的應用程序是一個社區網球場。我想用模擬紙張的在線數字表格替換紙張註冊表單。儘管看起來不太可能,但在兩次網球任命相撞時可能會出現「交易性」衝突。那麼,我該如何讓第二位預約製片人領導衝突,同時也讓成功的派對有機會像她在紙上(用橡皮擦)一樣改變她的任命。
每個半小時是窗體上的一個時間段。 「提交」之前,人們通常一次註冊多個半小時。
所以在我的代碼循環內我做了一個get_all。如果任何成功,我想讓用戶控制是否接受put()或不。我仍然認爲put()將是一個全部或全部,而不是選擇性的。
所以我的問題是,我需要使代碼的一部分使用明確的「交易」?
class MainPageCourt(BaseHandler):
def post(self, location_id):
reservations = self.request.get_all('reservations')
day = self.request.get('day')
weekday = self.request.get('weekday')
nowweekday = self.request.get('nowweekday')
year = self.request.get('year')
month = self.request.get('month')
nowmonth = self.request.get('nowmonth')
if not reservations:
for r in reservations:
r=r.split()
iden = r[0]
temp = iden+' '+r[1]+' '+r[2]
court = db.Key.from_path('Locations',location_id,'Courts', iden)
reservation = Reservations(parent=court)
reservation.starttime = [int(r[1]),int(r[2])]
reservation.year = int(r[3])
reservation.nowmonth = int(r[4])
reservation.day = int(r[5])
reservation.nowweekday = int(nowweekday)
reservation.name = self.request.get(temp)
reservation.put()
return webapp2.redirect("/read/%s" % location_id)
else:
... this important code is not written, pending ...
return webapp2.redirect("/adjust/%s" % location_id)
聽起來像交易會是需要的,你能更好地描述你的預期註冊流程?用戶看到未使用的時隙列表並選擇他們想要的列表,點擊提交以確認他們的選擇? – someone1
是的,你的描述是正確的,但除了「選擇」他們想要的,他們在每個這樣的文本框中輸入他們的名字,就是這樣。通常由社區編寫的規則並非由計算機系統進行真正的檢查,例如一次只有一次預訂單打一個小時,雙打兩個小時;預訂只能提前n天,其中n = 2或3;等等。但我認爲社會壓力會使這些規則大部分由社區執行。 – zerowords