Skip to the content.
CPT Project Home Personalized Project Reference (PPR) CPT Requirements

CPT Requirements

Component A- Program Code

List of CPT Requirements:

  1. Use of at least one list (or other collection type) to represent a collection of data that is stored and used to manage program complexity and help fulfill the program’s purpose
  2. At least one procedure that contributes to the program’s intended purpose, where you have defined:
    • the procedure’s name
    • the return type (if necessary)
    • one or more parameters
  3. An algorithm that includes sequencing, selection, and iteration that is in the body of the selected procedure
  4. Calls to your student-developed procedure
  5. Instructions for output (tactile, audible, visual, or textual) based on input and program functionality

1. Lists

camping_posts = camping.query.filter_by(_channel_id=data['channel_id']).all()  # Collect posts from databse by channel id
json_ready = [campingPost.read() for campingPost in camping_posts]  # stores result as a list of dictionaries
return jsonify(json_ready)  # return list as JSON response

This snippet is located in class _FILTER

  • collection of data are the camping posts
  • fulfills purpose to communicate with camping enthusiasts so that the user posts can be displayed

2. Procedure

@token_required()
def post(self):
    current_user = g.current_user
    data = request.get_json()

    if not data:
        return {'message': 'No input data provided'}, 400
    if 'title' not in data or 'comment' not in data or 'channel_id' not in data:
        return {'message': 'Missing required fields'}, 400

    campingPost = camping(data['title'], data['comment'], current_user.id, data['channel_id'])
    campingPost.create()
    
    return jsonify(campingPost.read())

Snippet from class _CRUD

  • Procedure name: post
  • Parameters: title, comment, channel id

3. Algorithm with Sequencing, Selection, Iteration

if not data:
    return {'message': 'No input data provided'}, 400  
if 'title' not in data or 'comment' not in data or 'channel_id' not in data:
    return {'message': 'Missing required fields'}, 400  

campingPost = camping(data['title'], data['comment'], current_user.id, data['channel_id'])
campingPost.create()  

camping_posts = camping.query.filter_by(_channel_id=data['channel_id']).all()  
json_ready = [campingPost.read() for campingPost in camping_posts]  

Snippet from class _CRUD

  • Selection (if else statements): checks if data exists, if not return error message
  • Sequencing (step by step): step by step to collect data then create post
  • Iteration (for loops): repeatedly going through each camping post in the list of posts and converting each post into JSON format

4. Call to Procedure

campingPost.create()

Snippet from class _CRUD

  • calls to campingPost model to save post into database

5. Instructions for output

return jsonify(campingPost.read()) 

Snippet from class _CRUD

  • Returns data in JSON format, which the frontend uses to dynamically display HTML content