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 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_user(current_user): new_user = User() new_user.name = current_user.nickname() new_user.google_id = current_user.user_id() new_user.admin = users.is_current_user_admin() if new_user.put(): return new_user else: return False
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 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 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 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 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", key=ndb.Key(pairs=[(User, 1)])).put() Project(name="name123", creator=ndb.Key(pairs=[(User, 1)]), createdOn=datetime.datetime(2016, 4, 25), key=ndb.Key(pairs=[(Project, 1)])).put() Transaction(project=ndb.Key(pairs=[(Project, 1)]), user=ndb.Key(pairs=[(User, 1)]), time_stamp=datetime.datetime(2016, 4, 25), key=ndb.Key(pairs=[(Transaction, 1)])).put() self.transaction = Transaction.query(Transaction.key == ndb.Key(pairs=[(Transaction, 1)])).fetch()[0]
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() Project(description="desc").put() User(key=ndb.Key(pairs=[(User, 1)])).put() Project(name="name123", creator=ndb.Key(pairs=[(User, 1)]), createdOn=datetime.datetime(2016, 4, 25)).put() self.project = Project.query(Project.name == u'name123').fetch()[0]
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 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", key=ndb.Key(pairs=[(User, 1)])).put() Project(name="name123", creator=ndb.Key(pairs=[(User, 1)]), createdOn=datetime.datetime(2016, 4, 25), key=ndb.Key(pairs=[(Project, 1)])).put() File(project=ndb.Key(pairs=[(Project, 1)]), blobKey=ndb.BlobKey("someGreatKey")).put() self.project = Project.query(Project.key == ndb.Key( pairs=[(Project, 1)])).fetch()[0] self.file = File.query(File.key == ndb.Key(pairs=[(File, 1)])).fetch()[0]
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())