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_event_id, type=int, help="Event ID", location="headers", required=True) parser.add_argument(Constants.k_internal_id, type=int, help="Internal event ID", location="headers") parser.add_argument(ExpenseModel.k_expense_id, type=int, help="Expense ID", location="headers") parser.add_argument( ExpenseModel.k_creator_id, type=int, help="Expense creator ID", location="headers", required=True ) parser.add_argument(ExpenseModel.k_title, type=str, help="Expense title", location="headers") parser.add_argument(ExpenseModel.k_value, type=float, help="Expense value", location="headers") parser.add_argument(Constants.k_is_removed, type=str, help="Is expense removed", location="headers") parser.add_argument(ExpenseModel.k_creation_date, type=str, help="Expense creation date", 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 expense_id = args[ExpenseModel.k_expense_id] expense_model = ExpenseModel.find_expense(expense_id) expense_model.configure_with_dict(args) db.session.add(expense_model) db.session.commit() return expense_model.to_dict()
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 get(self): parser = reqparse.RequestParser() parser.add_argument('userID', type=str, help='User ID', location='headers', required=True) parser.add_argument('timeStamp', type=str, help='Time Stamp', location='headers', required=True) parser.add_argument('userToken', type=str, help='User token', location='headers', 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 time = args['timeStamp'] time_stamp = None if len(time) > 0: time_stamp = parse(time) items = EventModel.time_stamp_difference(user_id, time_stamp) result = [result_model.to_dict() for result_model in items] response = dict() time_stamp = datetime.utcnow() response['timeStamp'] = time_stamp.isoformat() response['result'] = result print response return response
def get(self): model = BaseResource.check_user_credentials() if not isinstance(model, PersonModel): return model return model.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
def get(self): # Get userID from URL query request_parser = reqparse.RequestParser() request_parser.add_argument("userID", type=str) args = request_parser.parse_args() user_id = args["userID"] token = request.form["userToken"] event_id = request.form["eventID"] model = BaseResource.check_user_credentials_with_credentials(user_id, token) if not isinstance(model, PersonModel): # Some error happens here return model # person_model = EventModel.query.filter_by(creator_id=email).all() return {"event": "all"}
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(PersonModel.k_person_id, type=str, help='Person ID', location='headers') parser.add_argument(Constants.k_internal_id, type=str, help='Internal event ID', location='headers') parser.add_argument(Constants.k_is_removed, type=str, help='Is event removed', location='headers') parser.add_argument(Constants.k_event_id, type=int, help='Event ID', location='headers', required=True) parser.add_argument(PersonModel.k_first_name, type=str, help='First name', location='headers') parser.add_argument(PersonModel.k_last_name, type=str, help='Last name', location='headers') parser.add_argument(PersonModel.k_email, type=str, help='Email', location='headers') parser.add_argument(PersonModel.k_facebook_id, type=str, help='Facebook ID', location='headers') args = parser.parse_args() user_id = args[Constants.k_user_id] token = args[Constants.k_user_token] current_user = BaseResource.check_user_credentials_with_credentials(user_id, token=token) if not isinstance(current_user, PersonModel): # Return error description return current_user email = args.get(PersonModel.k_email) # Is person has email? if email is not None and len(email) > 0: # Yes: try to find person by email person = PersonModel.find_person_by_email(email) if person is not None: # Person with this email is exist person.configure_with_dict(args) else: # Person with current email doesn't exist person = PersonModel() else: # No: try to find the person by ID person_id = args.get(PersonModel.k_person_id) person = PersonModel.find_person(person_id) person.configure_with_dict(args) db.session.add(person) db.session.commit() event_id = args.get(Constants.k_event_id) team_member_event_row = EventTeamMembers.find_team_member_for_event(event_id, person.person_id) team_member_event_row.event_id = event_id team_member_event_row.person_id = person.person_id is_removed = args.get(Constants.k_is_removed) if is_removed is not None: team_member_event_row.is_removed = bool(is_removed) team_member_event_row.time_stamp = datetime.utcnow() db.session.add(team_member_event_row) db.session.commit() return person.to_dict()