def my_txn(): test_username = self.user.name self.write('<br>username is: ' + test_username) print('username is: ' + test_username) user = User.by_name(test_username) self.write('<br>user.id() is: ' + str(user.key().id())) print('user.id() is: ' + str(user.key().id())) # FOR DELETING delete_for_user(self, test_username) omlet1 = Omlet.make_omlet(test_username, 'amy1') print('omletparent', omlet1.parent().key().id()); print('user', user.key().id()) print('omlet:' + omlet1.name) key1 = omlet1.put() print('omlet1 newkey:', key1.id()) omlet2 = Omlet.get_by_id(key1.id(), parent = user, read_policy = db.STRONG_CONSISTENCY) print('omlet2: ' + omlet2.name) self.write('<br><br>put in omlet called "amy1" ') self.write('<br>list of omlets for this user is ' + string_list_omlet(Omlet.list_username(test_username))) self.write('<br>look, the omlet exists: ' + string_omlet(Omlet.by_name('amy1'))) self.write('<br><br>this should be empty: ' + string_list_bite(Bite.list_omlet_until_number('amy1', None))) make_bite_noduplicate('amy1', 'Bite AAAAA') make_bite_noduplicate('amy1', 'This is bite B of omlet1') self.write('<br>this should have two bites: ' + string_list_bite(Bite.list_omlet_until_number('amy1', None))) make_bite_noduplicate('amy1', 'Bite C') make_bite_noduplicate('amy1', 'Bite D, yay') make_bite_noduplicate('amy1', 'Nom, Bite E') self.write('<br><br> want up to bite C: ' + string_list_bite(Bite.list_omlet_until_number('amy1', 3))) self.write('<br> want bite D only: ' + string_bite(Bite.by_omlet_number('amy1', 4)))
def my_txn(): test_username = self.user.name self.write('<br>username is: ' + test_username) user = User.by_name(test_username) self.write('<br>user.id() is: ' + str(user.key().id())) # FOR DELETING delete_for_user(self, test_username) omlet1 = Omlet.make_omlet(test_username, 'amy1') if omlet1: omlet1.put() self.write('<br><br>put in omlet called "amy1" ') self.write('<br>list of omlets for this user is ' + string_list_omlet(Omlet.list_username(test_username))) self.write('<br>look, the omlet exists: ' + string_omlet(Omlet.by_name('amy1'))) self.write('<br><br>this should be empty: ' + string_list_bite(Bite.list_omlet_until_number('amy1', None))) make_bite_noduplicate('amy1', 'Bite AAAAA') make_bite_noduplicate('amy1', 'This is bite B of omlet1') self.write('<br>this should have two bites: ' + string_list_bite(Bite.list_omlet_until_number('amy1', None))) make_bite_noduplicate('amy1', 'Bite C') make_bite_noduplicate('amy1', 'Bite D, yay') make_bite_noduplicate('amy1', 'Nom, Bite E') self.write('<br><br> want up to bite C: ' + string_list_bite(Bite.list_omlet_until_number('amy1', 3))) self.write('<br> want bite D only: ' + string_bite(Bite.by_omlet_number('amy1', 4)))
def done(self): #make sure the user doesn't already exist u = User.by_name(self.username) if u: msg = 'That user already exists.' self.render('signup-form.html', error_username = msg) else: u = User.register(self.username, self.password, self.email) u.put() self.login(u) self.redirect('/welcome')
def make_omlet(cls, user_name, name): user = User.by_name(user_name) if not user: print('Tried to make Omlet - User does not exist.') return None omlet = Omlet.by_name(name) if omlet: print('Tried to make Omlet - Omlet already exists.') return None return Omlet(parent = user, name = name, user_id = user.key().id())
def omlet_bite_test(self): test_username = self.user.name self.write('<br>username is: ' + test_username) user = User.by_name(test_username) self.write('<br>user.id() is: ' + str(user.key().id())) # # FOR DELETING # delete_for_user(self, test_username) omlet1 = Omlet.make_omlet(test_username, 'first') if omlet1: omlet1.put() time.sleep(0.5) self.write('<br><br>put in omlet called "first" ') self.write('<br>list of omlets for this user is ' + string_list_omlet(Omlet.list_username(test_username))) self.write('<br>look, the omlet exists: ' + string_omlet(Omlet.by_name('first'))) self.write('<br><br>this should be empty: ' + string_list_bite(Bite.list_omlet_until_number('first', None))) make_bite_noduplicate('first', 'Bite AAAAA') time.sleep(0.5) make_bite_noduplicate('first', 'This is bite B of omlet1') time.sleep(0.5) self.write('<br>this should have two bites: ' + string_list_bite(Bite.list_omlet_until_number('first', None))) make_bite_noduplicate('first', 'Bite C') time.sleep(0.5) make_bite_noduplicate('first', 'Bite D, yay') time.sleep(0.5) make_bite_noduplicate('first', 'Nom, Bite E') time.sleep(0.5) self.write('<br><br> want up to bite C: ' + string_list_bite(Bite.list_omlet_until_number('first', 3))) self.write('<br> want bite D only: ' + string_bite(Bite.by_omlet_number('first', 4))) Bite.set_eaten('first', 2) time.sleep(0.5) self.write('<br>has bite B been eaten? should be yes: ' + string_bite(Bite.by_omlet_number('first', 2))) omlet2 = Omlet.make_omlet(test_username, 'second') if omlet2: omlet2.put() time.sleep(0.5) omlet3 = Omlet.make_omlet(test_username, 'third') if omlet3: omlet3.put() time.sleep(0.5) omlet4 = Omlet.make_omlet(test_username, 'fourth') if omlet4: omlet4.put() time.sleep(0.5) self.write('<br><br>list of omlets for this user should have 4: ' + string_list_omlet(Omlet.list_username(test_username)))
def list_username(cls, user_name): user = User.by_name(user_name) omlet_query = Omlet.all().ancestor(omlets_key()).filter('user_id =', user.key().id()).run() return omlet_query