mikeizbicki / cmc-csci040

Computing for the Web
36 stars 59 forks source link

Lab today cancelled #304

Open mikeizbicki opened 1 year ago

mikeizbicki commented 1 year ago

I'm not feeling well today, so I have to cancel lab today.

Due to the inconvenience, I'm going to remove the deadline from the lab. You still need to complete it (since it is the first part of completing your last project), and I recommend you still try to complete it before Sunday. But if you can't figure out how to do it for whatever reason, then you won't be penalized in your grade.

Also, I'm providing some additional starter code for part 2 of the lab. In particular, you can use the following root route (inside project.py)

@app.route('/')     
def root():
    # connect to the database
    con = sqlite3.connect(args.db_file)

    # construct messages,
    # which is a list of dictionaries,
    # where each dictionary contains the information about a message
    messages = []
    sql = """
    SELECT sender_id,message
    FROM messages
    ORDER BY created_at DESC;
    """
    cur_messages = con.cursor()
    cur_messages.execute(sql)
    for row_messages in cur_messages.fetchall():

        # convert sender_id into a username
        sql=
        """
        SELECT username
        FROM users
        WEREE id="""+str(row_messages[0])+""";
        """
        cur_users = con.cursor()
        cur_users.execute(sql)
        for row_users in cur_users.fetchall():
            pass

        # build the message dictionary
        messages.append({
            'message': row_messages[1],
            'username': row_users[0],
            })

    # render the jinja2 template and pass the result to firefox
    return render_template('root.html', messages=messages)

and the following root.html:

{% extends 'base.html' %}

{% block content %}
<table>
    <tr><th>sender (age)</th><th>message</th><th>created_at</th></tr>
    {% for message in messages %}
    <tr>
        <td>{{message['username']}} (FIXME: insert age)</td>
        <td>{{message['message']}}</td>
        <td>FIXME: insert time</td>
    </tr>
    {% endfor %}
</table>
{% endblock %}

You just have to make some minor adjustments to the code above to extract a bit more information from SQL database in order to complete the lab.