def get(self): user_id = self.request.get('user_id') orders = [] if user_id is not None: #each subject pick up 5 orders. then randomly choose 5 from the set subjects = TutorSubject.query_by_tutor_id(user_id) for s in subjects: ods = Order.query_by_subject(str(s.subject)) for od in ods: userinfo = UserInfo.query_by_id(od.owner_id) if userinfo: orders.append({'subject': od.subject, 'title': od.title, \ 'comment': od.comment, 'status_code': od.status_code,\ 'order_id': od.key.id(), 'user_id': od.owner_id, 'name': userinfo.name,\ 'picture': getPictureURL(str(userinfo.picture))}) if orders == []: #randomly pick up ods = Order.query() for od in ods: userinfo = UserInfo.query_by_id(od.owner_id) if userinfo: orders.append({'subject': od.subject, 'title': od.title, \ 'comment': od.comment, 'status_code': od.status_code,\ 'order_id': od.key.id(), 'user_id': od.owner_id, 'name': userinfo.name,\ 'picture': getPictureURL(str(userinfo.picture))}) random.shuffle(orders) recommendOrders = orders[:5] self.response.write(json.dumps(recommendOrders))
def get(self): user_id = self.request.get('user_id') email = self.request.get('email') user = UserInfo.query_by_id(user_id) if user is None: #create the user user = UserInfo(user_id=user_id, name="", email=email, picture=None, tutor_rating=4.0, intro="") key = user.put() self.response.write(json.dumps({'status_code':0, 'user_id': user_id, 'name': '',\ 'email': email, 'tutor_rating': 4.0, \ 'intro':'', 'subjects': '', \ 'picture': 'None'})) return else: subjects = TutorSubject.query_by_tutor_id(user_id) subjects = ', '.join([p.subject for p in subjects]) self.response.write(json.dumps({'status_code':0, 'user_id': user_id, 'name': user.name,\ 'email': user.email, 'tutor_rating': user.tutor_rating, \ 'intro':user.intro, 'subjects': subjects, \ 'picture': str(user.picture)}))