def eventmatch_test(): eventId = "e2" eventOwnerId = "u5" reqUserId = "u1" m = EventMatchModel(eventId=eventId,eventOwnerId=eventOwnerId,reqUserId=reqUserId) m.save() return json_util.dumps(m.to_mongo())
def eventmatch_test(): eventId = "e2" eventOwnerId = "u5" reqUserId = "u1" m = EventMatchModel(eventId=eventId, eventOwnerId=eventOwnerId, reqUserId=reqUserId) m.save() return json_util.dumps(m.to_mongo())
def api_event_myrequest(_uid = None): match = EventMatchModel.objects().filter(reqUserId = _uid) eids = [d.eventId for d in match] matchDict = dict((key, value) for (key, value) in [(d.eventId,d.status) for d in match]) print matchDict print eids event = EventModel.objects(id__in=eids) for d in event: num = EventMatchModel.objects(eventId=str(d.id)).count() setattr(d, 'numOfRequests', num) photo = ProfileModel.objects.get(userID=d.userID).image setattr(d, 'image', photo) #return json_util.dumps([d.to_mongo() for d in doc],default=json_util.default) return render_template('event_list.html',events=event,matchDict=matchDict,paras={"title":"My Requests",'action':'myrequest'})
def eventmatch_mine(_userid=None): doc = EventMatchModel.objects( Q(eventOwnerId=_userid, status="matched") | Q(reqUserId=_userid, status="matched")) return json_util.dumps([d.to_mongo() for d in doc], default=json_util.default)
def api_event_mine(_uid = None): doc = EventModel.objects(userID=_uid) for d in doc: num = EventMatchModel.objects(eventId=str(d.id)).count() setattr(d, 'numOfRequests', num) photo = ProfileModel.objects.get(userID=d.userID).image setattr(d, 'image', photo) return render_template('event_list.html',events=doc,paras={"title":"My Events",'action':'mine'})
def eventmatch_join_request(): cnt = ProfileModel.objects(userID=str(current_user.id)).count() if cnt == 0: raise Exception("no profile") else: eventId = request.json['eventId'] eventOwnerId = request.json['eventOwnerId'] reqUserId = request.json['reqUserId'] count = EventMatchModel.objects(eventId=eventId, eventOwnerId=eventOwnerId, reqUserId=reqUserId).count() if count == 0: model = EventMatchModel(eventId=eventId, eventOwnerId=eventOwnerId, reqUserId=reqUserId) doc = model.save() print json_util.dumps(doc.to_mongo()) app.logger.info(doc) return json_util.dumps(doc.to_mongo()) else: pass
def api_event_demo(): doc = EventModel.objects(status='new') for d in doc: num = EventMatchModel.objects(eventId=str(d.id)).count() setattr(d, 'numOfRequests', num) photo = ProfileModel.objects.get(userID=d.userID).image setattr(d, 'image', photo) # docs = json_util.dumps([d.to_mongo() for d in doc],default=json_util.default) # app.logger.info(docs) return render_template('event_list.html',events=doc,paras={"title":"All Open Events",'action':'all'})
def api_event_myrequest(_uid=None): match = EventMatchModel.objects().filter(reqUserId=_uid) eids = [d.eventId for d in match] matchDict = dict((key, value) for (key, value) in [(d.eventId, d.status) for d in match]) print matchDict print eids event = EventModel.objects(id__in=eids) for d in event: num = EventMatchModel.objects(eventId=str(d.id)).count() setattr(d, 'numOfRequests', num) photo = ProfileModel.objects.get(userID=d.userID).image setattr(d, 'image', photo) #return json_util.dumps([d.to_mongo() for d in doc],default=json_util.default) return render_template('event_list.html', events=event, matchDict=matchDict, paras={ "title": "My Requests", 'action': 'myrequest' })
def api_event_view(_eid = None): doc = EventModel.objects.get(id=_eid) doc2 = EventMatchModel.objects(eventId=_eid) for d in doc2: doc3 = ProfileModel.objects.get(userID=d.reqUserId) setattr(d, "reqProfile", doc3) setattr(doc, "Requests", doc2) #for d in doc.Requests: # print d.reqProfile.name return render_template('event.html', ev=doc,paras={"action":"view"})
def api_event_demo(): doc = EventModel.objects(status='new').order_by('-createTime') print doc for d in doc: num = EventMatchModel.objects(eventId=str(d.id)).count() setattr(d, 'numOfRequests', num) photo = ProfileModel.objects.get(userID=d.userID).image setattr(d, 'image', photo) # docs = json_util.dumps([d.to_mongo() for d in doc],default=json_util.default) # app.logger.info(docs) return render_template('event_list.html', events=doc, paras={ "title": "All Open Events", 'action': 'all' })
def api_event_view(_eid=None): doc = EventModel.objects.get(id=_eid) doc2 = EventMatchModel.objects(eventId=_eid) # get profile info for all requesters for d in doc2: doc3 = ProfileModel.objects.get(userID=d.reqUserId) setattr(d, "reqProfile", doc3) setattr(doc, "Requests", doc2) #for d in doc.Requests: # print d.reqProfile.name return render_template('event.html', ev=doc, paras={"action": "view"})
def api_event_near(): """ http://mongoengine-odm.readthedocs.org/guide/querying.html#geo-queries """ print request if request.method == "POST": dist = float(request.json['dist']) _lat = float(request.json['lat']) _lng = float(request.json['lng']) doc = EventModel.objects(status='new') # for d in doc: # print request # lat = d.LatLng.get('coordinates')[0]; # lng = d.LatLng.get('coordinates')[1]; # if isWithin(_lat, _lng, lat, lng, dist) is not 1: # else: # pass nums = {} photos = {} return_doc = [ d.to_mongo() for d in doc if isWithin( d.LatLng.get('coordinates')[0], d.LatLng.get('coordinates')[1], _lat, _lng, dist) == 1 ] for d in doc: if isWithin( d.LatLng.get('coordinates')[0], d.LatLng.get('coordinates')[1], _lat, _lng, dist) == 1: num = EventMatchModel.objects(eventId=str(d.id)).count() # setattr(d, 'numOfRequests', num) nums[str(d.id)] = num #print d.numOfRequests photo = ProfileModel.objects.get(userID=d.userID) photos[str(d.id)] = photo.image #setattr(d, 'image', photo.image) print json_util.dumps(return_doc) return json_util.dumps( { 'doc': return_doc, "nums": nums, "photos": photos }, default=json_util.default)
def eventmatch_test_accept(): print request if request.method == "POST": _eventid = request.json['eventId'] _requserid = request.json['reqUserId'] doc = EventMatchModel.objects(eventId=_eventid) doc2 = EventModel.objects.get(id=_eventid) print doc for d in doc: if (d.reqUserId == _requserid): d.status = "matched" doc2.status = "closed" doc2.save() else: d.status = "declined" d.save() return json_util.dumps([d.to_mongo() for d in doc], default=json_util.default)
def api_event_mine(_uid=None): doc = EventModel.objects(userID=_uid) eventDict = dict( (key, value) for (key, value) in [(d.id, d.status) for d in doc]) for d in doc: num = EventMatchModel.objects(eventId=str(d.id)).count() setattr(d, 'numOfRequests', num) photo = ProfileModel.objects.get(userID=d.userID).image setattr(d, 'image', photo) return render_template('event_list.html', events=doc, eventDict=eventDict, paras={ "title": "My Events", 'action': 'mine' })
def api_event_near(): """ http://mongoengine-odm.readthedocs.org/guide/querying.html#geo-queries """ print request if request.method == "POST": dist = float(request.json['dist']) _lat = float(request.json['lat']) _lng = float(request.json['lng']) doc = EventModel.objects(LatLng__geo_within_center=[[_lat, _lng], dist],status='new') for d in doc: num = EventMatchModel.objects(eventId=str(d.id)).count() setattr(d, 'numOfRequests', num) print num print d.numOfRequests photo = ProfileModel.objects.get(userID=d.userID).image setattr(d, 'image', photo) #print len(doc) #print json_util.dumps([d.to_mongo() for d in doc],default=json_util.default) return json_util.dumps([d.to_mongo() for d in doc],default=json_util.default)
def api_event_near(): """ http://mongoengine-odm.readthedocs.org/guide/querying.html#geo-queries """ print request if request.method == "POST": dist = float(request.json['dist']) _lat = float(request.json['lat']) _lng = float(request.json['lng']) doc = EventModel.objects(status = 'new') # for d in doc: # print request # lat = d.LatLng.get('coordinates')[0]; # lng = d.LatLng.get('coordinates')[1]; # if isWithin(_lat, _lng, lat, lng, dist) is not 1: # else: # pass nums = {} photos = {} return_doc = [d.to_mongo() for d in doc if isWithin(d.LatLng.get('coordinates')[0], d.LatLng.get('coordinates')[1],_lat,_lng,dist) == 1] for d in doc: if isWithin(d.LatLng.get('coordinates')[0], d.LatLng.get('coordinates')[1],_lat,_lng,dist) == 1: num = EventMatchModel.objects(eventId=str(d.id)).count() # setattr(d, 'numOfRequests', num) nums[str(d.id)] = num #print d.numOfRequests photo = ProfileModel.objects.get(userID=d.userID) photos[str(d.id)] = photo.image #setattr(d, 'image', photo.image) print json_util.dumps(return_doc) return json_util.dumps({'doc':return_doc, "nums":nums, "photos":photos},default=json_util.default)
def eventmatch_view_joins(_eventid=None): doc = EventMatchModel.objects(eventId=_eventid) return json_util.dumps([d.to_mongo() for d in doc], default=json_util.default)
def eventmatch_mine(_userid = None): doc = EventMatchModel.objects(Q(eventOwnerId=_userid, status="matched") | Q(reqUserId=_userid, status="matched")) return json_util.dumps([d.to_mongo() for d in doc], default=json_util.default)
def eventmatch_view_joins(_eventid = None): doc = EventMatchModel.objects(eventId=_eventid) return json_util.dumps([d.to_mongo() for d in doc], default=json_util.default)