def post(self): parser = reqparse.RequestParser() parser.add_argument(Constants.k_user_id, type=int, help='User ID', location='form', required=True) parser.add_argument(Constants.k_user_token, type=str, help='User token', location='form', required=True) parser.add_argument(Constants.k_internal_id, type=str, help='Internal event ID', location='headers') parser.add_argument(Constants.k_event_id, type=str, help='Event ID', location='headers') parser.add_argument(EventModel.k_creator_id, type=str, help='Event creator ID', location='headers', required=True) parser.add_argument(EventModel.k_title, type=str, help='Event title', location='headers') parser.add_argument(EventModel.k_creation_date, type=str, help='Creation even date', location='headers') parser.add_argument(EventModel.k_end_date, type=str, help='End event date', location='headers') parser.add_argument(Constants.k_is_removed, type=str, help='Is event removed', location='headers') args = parser.parse_args() model = BaseResource.check_user_credentials_with_credentials(args[Constants.k_user_id], token=args[Constants.k_user_token]) if not isinstance(model, PersonModel): # Return error description return model event_id = args[Constants.k_event_id] event_model = EventModel.find_event(event_id) event_model.configure_with_dict(args) db.session.add(event_model) db.session.commit() return event_model.event_to_dict()
def post(self): parser = reqparse.RequestParser() parser.add_argument('userID', type=str, help='User ID', location='form', required=True) parser.add_argument('userData', type=str, help='User Data', location='form', required=True) parser.add_argument('userToken', type=str, help='User Token', location='form', required=True) args = parser.parse_args() user_id = args['userID'] token = args['userToken'] model = BaseResource.check_user_credentials_with_credentials(user_id, token) if not isinstance(model, PersonModel): # Some error happens here return model json_data = args['userData'] try: json_data = json.loads(json_data) except ValueError: return Constants.error_wrong_json_format() if not isinstance(json_data, list): return Constants.error_wrong_json_structure() print json_data result = [] for event_dict in json_data: if isinstance(event_dict, dict): event_model = EventModel.find_event(event_dict.get(EventModel.k_event_id)) event_model.creator_id = user_id event_model.configure_with_dict(event_dict) db.session.add(event_model) db.session.commit() event_json = event_model.to_dict() result.append(event_json) time_stamp = datetime.utcnow() response = dict() response[Constants.k_time_stamp] = time_stamp.isoformat() response['result'] = result # print response return response