Skip to the content.

FRQ questions

FRQ questions Review

Procedure:

def update(self, data):
    """
    Updates the event with new data.
    """
    for key, value in data.items():  
        if hasattr(self, key):  
            if key == 'date' and isinstance(value, str):  
                value = datetime.strptime(value, '%Y-%m-%d').date()  
            setattr(self, key, value)  

    try:
        db.session.commit() 
    except IntegrityError as e:
        db.session.rollback() 
        logging.warning(f"IntegrityError: Could not update event '{self.title}' due to {str(e)}.")
        return None
    return self  # Return the updated event

  1. Defines the procedure’s name and return type (if necessary):

    • Procedure Name: update is the name of the procedure.
    • Return Type: It returns self (the updated event object), which suggests the return type is an Event object (or None if there’s an error).
  2. Contains and uses one or more parameters that have an effect on the functionality of the procedure:

    • Parameters: The parameter data is passed to the update method. This dictionary contains key-value pairs representing the fields and values to be updated in the Event object.

    • Effect on Functionality: The data parameter is central to the update operation iterates through the dictionary and updates the object.

  3. Implements an algorithm that includes sequencing, selection, and iteration:

    • Sequencing: The code follows a step-by-step approach where it first checks each key in data, updates the corresponding attribute of the Event object, and then commits the changes to the database.
    • Selection: The if hasattr(self, key) is a selection operation. It checks if the Event object has the attribute corresponding to the current key before attempting to update it.
    • Iteration: The for key, value in data.items() is an iteration. The code loops over all the key-value pairs in the data dictionary, which means iteration is being used here.
updated_event = event.update(data)

  • the update method is being called when the put endpoint is triggered, and it performs the update logic on the event record. If the update is successful, the updated event is returned in the response. If there’s an error, it returns a message indicating the failure.
  • calls the update method to modify the event object based on the provided data and handles the result accordingly.

List

def initEvents(): 
    """
    Initializes the Events table with test data.
    """
    with app.app_context():
        db.create_all() 
        events = [ # creates a list of Event objects
            Event(title='Tech Conference', description='A conference about the latest in technology.', date='2025-05-20'),
            Event(title='Music Festival', description='A festival featuring various music artists.', date='2025-06-15'),
            Event(title='Art Expo', description='An expo showcasing modern art.', date='2025-07-10'),
        ]
        for event in events: 
            try:
                event.create()
                print(f"Record created: {repr(event)}")
            except IntegrityError as e:
                db.session.rollback()
                print(f"Records exist or duplicate error: {event.title}, {str(e)}")

This segment stores multiple Event objects in a list, satisfying the first requirement.

@custom_cli.command('generate_data')
def generate_data():
    initEvents()
  • It retrieves data from the list (initEvents()).
  • It processes the list data by printing each event.

Explain how you used or could have used feedback, testing, or reflection in the development of your program.

  1. Feedback: Improving Based on User feedbacks

    • Feedback from N@tm suggested better frontend / the purpose is minimal
    • improvements like adding event descriptions and filtering events by date.
    • ensuring presidents could only modify their own events.
    • Ensure that an event cannot be created without a title, description, or date.
  2. Testing: Ensuring Functionality and usefulness

    • testing CRUD functions using postman
    • On deployed website, I checked with my friend if they can see what I typed on my conputer
    • I asked my friends if my feature looked okay.
    • I tested with using president account and user account to see if only president can add the events, edit, and delete.

    How Testing Improved the Code:

    • Identified and fixed issues where event updates failed due to improper data formatting.
    • Added better error messages when events were not found or when duplicate events were attempted.
    • Strengthened security by restricting event modifications to the event creator / president only.
  3. Reflection: Enhancing Future Development

    • After completing the initial version of the club events feature, I reflected on ways to improve efficiency and user experience
    • After testing, I realized that navigating between clubs and their events could be smoother. I plan to improve the UI with better navigation.
    • I considered future scalability—how the event system could support larger clubs or even public events outside clubs.
  4. Iterative Development: Making Continuous Improvements

    • I made so that instead of typing the club, club leader automatically gets to choose an option instead of typing it
    • I added dates and description for events
    • I added authentication to backend so only event creater can edit or delete it.
    • I also added dots to the calender when there is an event that day

Describe the problem that your program was created to address or the creative expression it pursues.

  • The Club Events Feature was developed to address the lack of organization and engagement in club-related activities. Many clubs struggle with effectively planning and managing events, leading to low participation and miscommunication among members.
  • So, by using club events, I hope to let club leaders help label different events in one space to make club members easier to see the announcements or events
  • the feature increases club engagement and encourages active participation.

Refer to your Personalized Project Reference when answering this question.

  1. Consider the first conditional statement included in the Procedure section of your Personalized Project Reference. Write an equivalent Boolean expression for this conditional statement.

The first conditional statement in the given function is:

if hasattr(self, key):

Equivalent Boolean Expression:

This checks if the object (self) has an attribute with the name specified by key. The equivalent Boolean expression can be written as:

key in dir(self)
  • hasattr(self, key): This function returns True if the attribute key exists in the object self, otherwise False.
  • key in dir(self): The dir(self) function returns a list of all attributes and methods of self, and checking if key is in this list achieves the same purpose as hasattr(self, key).
  1. The procedure solves the subproblem of updating event information in the Club Hub system. The subproblem is modifying event details like the title, description, or date without creating a new event. This allows users to edit existing events instead of deleting and making a new one. The procedure breaks down the update process into smaller tasks by checking each attribute individually.

  2. The function initEvents() is responsible for initializing an Events table with test data. It performs the following key tasks: Ensures the database table exists, Creates a list of predefined event records, and Iterates through each event and attempts to insert it into the database.