def post(self): data = api.payload activity = Activity(vin=data['vin'], scan_time=data['scan_time']) data['act_id'] = time.time() activity.act_id = int(data['act_id']) if Van.objects(vin=activity.vin).first(): activity.save() resp = Activity.objects.aggregate(*[ { '$match': { 'act_id' : activity.act_id } }, { '$project': { '_id': '$$REMOVE', 'vin': '$vin', 'act_id': '$act_id', 'scan_time': { '$dateToString': { 'format': '%Y-%m-%d %H:%M:%S', 'date': '$scan_time' } } } } ]) resp_string = encoder.encode(list(resp)) return json.loads(resp_string), 200 # return jsonify(Activity.objects(act_id=activity.act_id)) else: abort(400, 'This vin does not exist')
def post(self, idx): # activity_id is useful when all the activiteis to be shown ==>To be confirm use_id = idx user = User.objects(use_id=use_id).first() leader_id = user.user_id activities = Activity.objects.all() n = len(activities) activity_id = 0 if n != 0: activity_id = activities[n - 1].activity_id activity_id += 1 activity_name = request.form.get("activity") start_date_str = request.form.get("start") skills = request.form.get("skills") genre = request.form.get("genre") description = request.form.get("description") start_date_datetime = datetime.strptime(start_date_str, '%Y-%m-%d %H:%M:%S') #check if there is the same activity name isPresent = Activity.objects(activity_name=activity_name).first() if isPresent: return jsonify("Please select another name") activity = Activity(leader_id=leader_id, activity_id=activity_id, activity_name=activity_name, leader_name=username, open_date=datetime.utcnow(), start_date=start_date_datetime, genre=genre, skills=skills, description=description) activity.save() return (jsonify("Successfully build a new activity"))