def create_transaction_from_params(self): new_transaction = Transaction() new_transaction.project = Project.get_by_id(int(str(self.request.get("projectId")))).key new_transaction.user = User.query(User.google_id == str(self.request.get("userId"))).get().key new_transaction.money = int(self.request.get("money")) return new_transaction
def get(self): current_user = User.query(User.name == users.get_current_user().nickname()).get() if users.is_current_user_admin() or current_user.admin: current_user.make_admin() users_json = User.get_all_as_json() self.response.out.write(json.dumps(users_json)) else: self.response.status = 401
def create_project_from_params(params): new_project = Project() new_project.name = unicode(params.name) new_project.description = unicode(params.description) new_project.creator = User.query( User.google_id == str(params.creator_id)).get().key return new_project
def get(self): current_user = User.query( User.name == users.get_current_user().nickname()).get() if users.is_current_user_admin() or current_user.admin: current_user.make_admin() users_json = User.get_all_as_json() self.response.out.write(json.dumps(users_json)) else: self.response.status = 401
def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() ndb.get_context().clear_cache() User(name="FancyName", google_id="123id").put() self.user = User.query(User.name == u'FancyName').fetch()[0]
def create_transaction_from_params(self): new_transaction = Transaction() new_transaction.project = Project.get_by_id( int(str(self.request.get("projectId")))).key new_transaction.user = User.query( User.google_id == str(self.request.get("userId"))).get().key new_transaction.money = int(self.request.get("money")) return new_transaction
def get_user(): current_user = users.get_current_user() if current_user: query_user = User.query(User.name == current_user.nickname()).get() if query_user is None: return create_user(current_user) else: return query_user else: return False
def get_user(): current_user = users.get_current_user() if current_user: query_user = User.query(User.name == current_user.nickname()).get() if query_user is None: return create_user(current_user) else: return query_user else: return False
def money_operation(self, function): user = User.query(User.google_id == str(self.request.get("userId"))).get() amount = int(self.request.get("amount")) if amount <= 0: self.response.status = 400 elif function == "substract": user.substract_money(amount) self.response.out.write(user.to_json_obj()) elif function == "substract_all": all_users = User.query().fetch() for user in all_users: user.substract_money(amount) elif function == 'add': user.add_money(amount) self.response.out.write(user.to_json_obj()) elif function == 'add_all': all_users = User.query().fetch() for user in all_users: user.add_money(amount) elif function == 'set': user.set_money(amount) self.response.out.write(user.to_json_obj())
def post(self): current_user = User.query(User.name == users.get_current_user().nickname()).get() if users.is_current_user_admin() or current_user.admin: current_user.make_admin() function = self.request.get("function") if function == "hide": self.hide() elif function == 'make_admin': self.make_admin() else: self.money_operation(function) else: self.response.status = 401
def money_operation(self, function): user = User.query( User.google_id == str(self.request.get("userId"))).get() amount = int(self.request.get("amount")) if amount <= 0: self.response.status = 400 elif function == "substract": user.substract_money(amount) self.response.out.write(user.to_json_obj()) elif function == "substract_all": all_users = User.query().fetch() for user in all_users: user.substract_money(amount) elif function == 'add': user.add_money(amount) self.response.out.write(user.to_json_obj()) elif function == 'add_all': all_users = User.query().fetch() for user in all_users: user.add_money(amount) elif function == 'set': user.set_money(amount) self.response.out.write(user.to_json_obj())
def post(self): current_user = User.query( User.name == users.get_current_user().nickname()).get() if users.is_current_user_admin() or current_user.admin: current_user.make_admin() function = self.request.get("function") if function == "hide": self.hide() elif function == 'make_admin': self.make_admin() else: self.money_operation(function) else: self.response.status = 401
def make_admin(self): user = User.query( User.google_id == str(self.request.get("userId"))).get() user.make_admin()
def make_admin(self): user = User.query(User.google_id == str(self.request.get("userId"))).get() user.make_admin()
def get_usernames_for_phrase(phrase): return filter(lambda u: phrase in u.name, User.query().fetch())