def get(self): print "Get tags" parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) parser.add_argument('size', type=int, default=10) parser.add_argument('total', type=ArgumentValidator.create('boolTrue'),default=True) parser.add_argument('only_approved',default=True) parser.add_argument('collection',default='') parser.add_argument('toplevel',default='') parser.add_argument('count_greater',type=int,default=0) args = parser.parse_args() try: toplevel_key=ndb.Key(urlsafe=args.toplevel) except: toplevel_key=None try: collection_key=ndb.Key(urlsafe=args.collection) except: collection_key=None query = model.Tag.qry(toplevel=toplevel_key, collection=collection_key, only_approved=args.only_approved, count_greater=args.count_greater) tags_future = query.fetch_page_async(args.size, start_cursor=args.cursor) if args.total: total_count_future = query.count_async(keys_only=True) tags, next_cursor, more = tags_future.get_result() tags = [u.to_dict(include=model.Tag.get_public_properties()) for u in tags] #print next_cursor if args.total: total_count = total_count_future.get_result() else: total_count = None return make_list_response(tags, next_cursor, more, total_count)
def get(self, collection): print "Get waypoints" parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) parser.add_argument('size', type=int, default=10) parser.add_argument('noTotal', type=ArgumentValidator.create('boolTrue'),default=False) parser.add_argument('newer', default=None) parser.add_argument('offset', type=int, default=None) # newer date - offset (in seconds) #parser.add_argument('only_approved',default=True) #parser.add_argument('collection',default='') #parser.add_argument('toplevel',default='') #parser.add_argument('count_greater',type=int,default=0) args = parser.parse_args() args.total = not args.noTotal #try: #toplevel_key=ndb.Key(urlsafe=args.toplevel) #except: #toplevel_key=None #try: #collection_key=ndb.Key(urlsafe=args.collection) #except: #return make_bad_request_exception("Wrong collection key") query = model.WayPoint.qry(collection=g.col_key,compare_date='>modified',date=args.newer, time_offset=args.offset) wps_future = query.fetch_page_async(args.size, start_cursor=args.cursor) if args.total: total_count_future = query.count_async(keys_only=True) wps, next_cursor, more = wps_future.get_result() wps = [u.to_dict(include=model.WayPoint.get_public_properties()) for u in wps] if args.total: total_count = total_count_future.get_result() else: total_count = None return make_list_response(wps, next_cursor, more, total_count)
def get(self, username): parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) parser.add_argument('q', type=str,default='') parser.add_argument('size', type=int,default=10) args = parser.parse_args() # current user key user_key = g.user_db.key if auth.is_admin() or user_db.key == auth.current_user_key(): query = model.CollectionUser.qry(user=user_key) collection_keys_future = query.fetch_async(limit=args.size*4,keys_only=True) # do something else here? collection_keys = collection_keys_future.get_result() collection_keys = [key.parent() for key in collection_keys] # Search for users in this collections users = []; for key in collection_keys: query = model.CollectionUser.query(ancestor=key) if len(args.q) > 2: query = query \ .filter(model.CollectionUser.user.username >= args.q) \ .filter(model.CollectionUser.user.username <= unicode(args.q) + u"\ufffd")\ .order(model.CollectionUser.user.username) else: query = query.order(model.CollectionUser.modified) users_future = query.fetch_async( limit=args.size, projection=['modified','user.username','user.email','user.avatar_url','user_key']) users = users + users_future.get_result() #users = users + [{'key':u.key,'modified':u.modified} for u in users_future.get_result()] # check if a user with this name or email exists: user_db = model.User.get_by_email_or_username(args.q) if len(args.q)>2 else None if user_db: # create temp user with modified now -> first in list user = model.CollectionUser( user_key= user_db.key, user = model.User(username = user_db.username, email = user_db.email, avatar_url = user_db.avatar_url), name = "Just Temp User", modified = datetime.datetime.now(), created = datetime.datetime.now() ) users.append(user) # sort users after its last modification users = util.sort_uniq(users,'modified','user_key',reverse=False) #users = [u.urlsafe() for u in users] users = [u.to_dict(include=['modified','user','user_key']) for u in users] total = len(users) if total > args.size: users = users[:args.size] return make_list_response(users, None, total > args.size, total)
def get(self): parser = reqparse.RequestParser() parser.add_argument("cursor", type=ArgumentValidator.create("cursor")) args = parser.parse_args() users_future = User.query().order(-User.created).fetch_page_async(10, start_cursor=args.cursor) total_count_future = User.query().count_async(keys_only=True) users, next_cursor, more = users_future.get_result() users = [u.to_dict(include=User.get_public_properties()) for u in users] return make_list_response(users, next_cursor, more, total_count_future.get_result())
def get(self): parser = default_parser() args = parser.parse_args() compare, date = to_compare_date(args.newer, args.older, args.orderBy) sim_query = Simulation.qry(order_by_date=args.orderBy, compare_date=compare, date=date, time_offset=args.offset) sim_future = sim_query.fetch_page_async(args.size, start_cursor=args.cursor) total_count_future = sim_query.count_async(keys_only=True) if args.total else False simulations, next_cursor, more = sim_future.get_result() simulations = [s.to_dict(include=Simulation.get_public_properties()) for s in simulations] total_count = total_count_future.get_result() if total_count_future else False return make_list_response(simulations, next_cursor, more, total_count)
def get(self): parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) args = parser.parse_args() positions_future = Position.query() \ .order(-Position.created) \ .fetch_page_async(10, start_cursor=args.cursor) total_count_future = Position.query().count_async(keys_only=True) positions, next_cursor, more = positions_future.get_result() positions = [u.to_dict(include=Position.get_public_properties()) for u in positions] return make_list_response(positions, next_cursor, more, total_count_future.get_result())
def get(self): parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) args = parser.parse_args() items_future = Hackathon.query() \ .order(-Hackathon.modified) \ .fetch_page_async(10, start_cursor=args.cursor) total_count_future = Hackathon.query().count_async(keys_only=True) items, next_cursor, more = items_future.get_result() items = [u.to_dict(include=Hackathon.get_public_properties()) for u in items] return make_list_response(items, next_cursor, more, total_count_future.get_result())
def get(self): parser = default_parser() args = parser.parse_args() compare ,date = to_compare_date(args.newer, args.older, args.orderBy) query = model.ExpenseType.qry(order_by_date=args.orderBy, \ compare_date = compare, date = date, time_offset=args.offset) dbs_future = query.fetch_page_async(args.size, start_cursor=args.cursor) total_count_future = query.count_async(keys_only=True) if args.total else False dbs, next_cursor, more = dbs_future.get_result() dbs = [db.to_dict(include=model.ExpenseType.get_public_properties()) for db in dbs] total_count = total_count_future.get_result() if total_count_future else False return make_list_response(dbs, next_cursor, more, total_count)
def get(self): parser = default_parser() args = parser.parse_args() compare ,date = to_compare_date(args.newer, args.older, args.orderBy) users_query = User.qry(order_by_date=args.orderBy, \ compare_date = compare, date = date, time_offset=args.offset) users_future = users_query.fetch_page_async(args.size, start_cursor=args.cursor) total_count_future = users_query.count_async(keys_only=True) if args.total else False users, next_cursor, more = users_future.get_result() users = [u.to_dict(include=User.get_public_properties()) for u in users] total_count = total_count_future.get_result() if total_count_future else False return make_list_response(users, next_cursor, more, total_count)
def get(self): parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) parser.add_argument('description') parser.add_argument('location') args = parser.parse_args() positions_future = Position.query() \ .order(-Position.created) \ .fetch_page_async(10, start_cursor=args.cursor) total_count_future = Position.query().count_async(keys_only=True) positions, next_cursor, more = positions_future.get_result() positions = [p.to_json() for p in positions] positions = [p for p in positions if args.description.lower() in p["description"].lower()] positions = [p for p in positions if args.location.lower() in p["location"].lower()] return make_list_response(positions, next_cursor, more, total_count_future.get_result())
def get(self, key): parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) args = parser.parse_args() user_id = g.model_db.id() if auth.current_user_db().id() != user_id: # not allowed to access other registrations return ApiException.error(403) items_future = Hackathon.query(Hackathon.user_id==user_id) \ .order(-Hackathon.modified) \ .fetch_page_async(10, start_cursor=args.cursor) total_count_future = Hackathon.query(Hackathon.user_id==user_id).count_async(keys_only=True) items, next_cursor, more = items_future.get_result() items = [u.to_dict(include=Hackathon.get_public_properties()) for u in items] return make_list_response(items, next_cursor, more, total_count_future.get_result())
def put(self,collection): """Updates user's properties""" #update_properties = ['name', 'collection', 'toplevel', 'icon_key', 'color', 'force_new_icon','auto_incr'] #print request.json #data = _.pick(request.json, update_properties) data = request.json print "Data is:" print data if 'force_new_icon' not in data: data['force_new_icon'] = False if 'auto_incr' not in data: data['auto_incr'] = False if 'tag_details' not in data: data['tag_details'] = [] try: data['collection'] = ndb.Key(urlsafe=data['collection']) except: return make_bad_request_exception("Wrong collection key") #print data tag_list = [] # Check tag properties and add tag for tag in data['tag_details']: #if 'toplevel' not in tag: #tag['toplevel'] = None #else: #try: #tag['toplevel'] = ndb.Key(urlsafe=tag['toplevel']) #except: #tag['toplevel'] = None if 'icon_key' not in tag: tag['icon_key'] = None else: try: tag['icon_key'] = ndb.Key(urlsafe=tag['icon_key']) except: pass tag['collection'] = data['collection'] print "Arguments for add tag" print tag key = model.Tag.add(**tag) tag_list.append(tag['name']) tags = model.Tag.get_tag_infos(tag_list,data['collection']) return make_list_response(tags, False, False, len(tags))
def get(self,collection,names): """Updates user's properties""" tags = model.Tag.get_tag_infos(names.split(','),collection,True) return make_list_response(tags, False, False, len(tags))
def get(self, collection,query): parser = reqparse.RequestParser() parser.add_argument('cursor', type=ArgumentValidator.create('cursor')) #parser.add_argument('q', type=str,default='') parser.add_argument('size', type=int,default=30) parser.add_argument('only_names', type=ArgumentValidator.create('boolTrue'),default=False) args = parser.parse_args() tags = [] try: collection = ndb.Key(urlsafe=collection) except: collection = model.Collection.top_key() # Check if the user has read permission for the collection TODO if auth.is_admin(): # check if name is already a full tag key = model.Tag.tag_to_key(query,collection) try: db = key.get() except: key = model.Tag.tag_to_key(query) try: db = key.get() except: db = False if db: dbs_related, more = db.related(char_limit=200) #tags = [db.name] + db.related() tags = [r.related_to for r in dbs_related] tags = [db.name] + tags else: gae_qry = model.Tag.query(model.Tag.collection == collection) if len(query) > 1: gae_qry = gae_qry \ .filter(model.Tag.name >= query) \ .filter(model.Tag.name <= unicode(query) + u"\ufffd")\ .order(model.Tag.name) else: gae_qry = gae_qry.order(model.Tag.cnt) tags_future = gae_qry.fetch_async( limit=args.size, projection=['name']) tags = tags_future.get_result() tags = [r.name for r in tags] rel_tags = [] for tag in tags: key = model.Tag.tag_to_key(tag,collection) try: db = key.get() if db: dbs_related, more = db.related(char_limit=100) rel_tags = [r.related_to for r in dbs_related] tags = tags+rel_tags #[:5] except: pass if len(tags) > args.size+5: break #tags = list(set(tags)) tags = list(OrderedDict.fromkeys(tags)) total = len(tags) tags = tags[:args.size] if not args.only_names: tags = model.Tag.get_tag_infos(tags,collection) return make_list_response(tags, False, total > len(tags), total)
def get(self): crumbs = Crumb.query().fetch() crumbs = [ u.to_dict(include=Crumb.get_public_properties()) for u in crumbs ] return make_list_response(crumbs)
def get(self): crumbs = Crumb.query().fetch() crumbs = [u.to_dict(include=Crumb.get_public_properties()) for u in crumbs] return make_list_response(crumbs)
def get(self): parser = default_parser() parser.add_argument('expenses', type=ArgumentValidator.create('boolTrue'),default=False) parser.add_argument('travelers', type=ArgumentValidator.create('boolTrue'),default=False) parser.add_argument('locations', type=ArgumentValidator.create('boolTrue'),default=False) args = parser.parse_args() compare ,date = to_compare_date(args.newer, args.older, args.orderBy) query = model.Trip.qry(order_by_date=args.orderBy, \ compare_date = compare, date = date, time_offset=args.offset, \ ancestor=auth.current_user_key()) dbs_future = query.fetch_page_async(args.size, start_cursor=args.cursor) # Count how many results are available (only of prameter total is given!) total_count_future = query.count_async(keys_only=True) if args.total else False # Get result, this is needed to do the other things. dbs, next_cursor, more = dbs_future.get_result() # Create already a dictionary, this is used to add data instead of keys dbs = [db.to_dict(include=model.Trip.get_public_properties()) for db in dbs] # get locations async (only if not only keys are requested) if (args.locations): locs_future = [] for db in dbs: if db['locations']: locs_future.append(ndb.get_multi_async([ndb.Key(urlsafe=key) for key in db['locations']])) else: locs_future.append(None) i=0 for loc_future in locs_future: if loc_future: # is a locatio given? locs = [f.get_result() for f in loc_future] locs = [db.to_dict(include=model.Location.get_public_properties()) for db in locs] u=0 if (args.expenses or args.travelers or True): for loc in locs: for trans in ['trans_start','trans_end']: wayPt = locs[u][trans].get('waypoints',[]) locs[u][trans]['geo'] = wayPt[-1] if len(wayPt) > 0 else None if args.travelers: locs[u]['fellow_travelers'] = [ndb.Key(urlsafe=db).get().to_dict(include= model.FellowTraveler.get_public_properties()) for db in loc['fellow_travelers']] if args.expenses: #print "Get expenses" #print loc['expenses'] locs[u]['expenses'] = [{"amount": e['amount'] if 'amount' in e else 0, "note": e['note'] if 'note' in e else "", "type":ndb.Key(urlsafe=e['type']).get(). to_dict(include=model.ExpenseType.get_public_properties()) if 'type' in e and e['type'] else None} for e in loc['expenses']] u+=1 dbs[i]['locations'] = locs else: # empty locations dbs[i]['locations'] = [] i += 1 #dbs = [db.to_dict(include=model.Trip.get_public_properties()) for db in dbs] total_count = total_count_future.get_result() if total_count_future else False return make_list_response(dbs, next_cursor, more, total_count)