Skip to content

tadasant/Locust_Talk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Locust Talk

MADE CHANGES

Web app that allows visitors to post messages on a forum-style board.

VIEW THIS README ON GITHUB!

Github: https://github.com/tadas412/Locust_Talk
Heroku live app: locust-talk.herokuapp.com

Overview

This app uses Python's Flask library and some basic HTML to present a functional forum-style board, intended for use by Penn students. Backend data storage uses PostgreSQL.

The simplest way to use Locust Talk is to visit the live site on locust-talk.herokuapp.com. Use the buttons to navigate to the category that interests you. Then, you can either create a new topic, or enter an existing topic by clicking the corresponding hyperlink. You can then view messages, or post a new response by clicking the button at the buttom of the page.

Alternatively, see instructions below under "CIS 192 Final Project Requirements" for how to run the app locally.

Required Dependencies

(from requirements.txt virtual environment)

Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.9.6
gunicorn==19.1.1
itsdangerous==0.24
psycopg2==2.5.4
wsgiref==0.1.2

File Structure

Locust_Talk
  venv/ - includes all files for the virtual environment I used
  data/
    data_calls.py - most data management done here
    data_classes.py - custom classes, and some corresponding data pulling methods, can be found here
    utils.py - misc. utilities (e.g. custom decorator for debugging)
  static/ - includes media files for front end, and CSS
  templates/ - HTML templates for the app
  app.py - main orchestrator and router for the app
  Procfile - file that tells Heroku what to run
  requirements.txt - file that tells Heroku what dependencies we have

Features

  • Navigate through a hierarchy of categories
  • View both category topics and subcategory links on each page
  • Create new topics
  • View message streams for each topic
  • Add messages (responses) to topics
  • View messages in pages of 5 max, with the ability to go to other pages

CIS 192 Final Project Requirements

Your app should be callable from the command line, and should take as input at least two arguments/flags that determine its usage, which you should consume using the optparse module.

Locust Talk is callable from the command line on a local machine with the usage "python app.py [-d] [-p PORT]". The -d argument should be True or False based on if you want Flask to run in debugging mode - the application will be allowed to execute arbitrary Python code on your computer. If you're in debugging mode, the app will also print out a log of the functions it's using and associated times (in seconds) that they start. The -p PORT argument determines on which port to mount the app when it runs locally.

Define and use a custom class (okay to inherit from something else, as in wxpython).

There are two custom classes defined in data/data_classes.py.

The first one is Topic, which stores information about a particular conversation topic (topic name, topic ID, author, category, subcategories), and also has a couple methods for managing messages related to a topic (get_messages and add_message). The method get_num_pages checks how many messages are associated with the topic and returns the number of pages needed to hold them.

The other one is Message, which simply stores information about a particular message (message ID, message, author).

Define at least one magic method.

Each of the custom classes described above have init, repr, and eq methods.

Use at least two of the following modules: itertools, random, re, os

In app.py, I used os to add the relative path /data to the system path. In particular, os was used to grab the current directory name, and then /data was appended to that path, which was added to the system path. This allowed me to store python modules in /data.

Also in app.py, I used itertools to islice messages onto the correct pages corresponding to a topic. If there are more than 5 messages, islice selects the five (or fewer) that should be present on the current page.

Define and use a custom decorator.

My custom decorator is defined in /data/utils.py. It is a debugger decorator, with which I decorated all non-routing functions. If the -d flag is used when running the app, this will result in those decorated functions printing when they are called: their name, args, and time passed since start is printed.

Include documentation with a detailed explanation of how to use your app. Be sure to point out anything especially cool that you did!

This document explains usage of the app. The most relevant features to note:

  • Use of PostgreSQL usage to persistently store all data
  • Full integration and functionality with live Heroku app
  • Fully up and running on Heroku
  • Page counter / slicer is pretty cool

Development Process

I began by sketching out my vision for the product before beginning any coding. Using my final proposal as a guide, I hashed out the goal of the product, a hierarchy of categories I planned to integrate, and a map of general site flow. I split the work I would have to do into stages:

  1. Review material from class (e.g. Flask, SQL)
  2. Research where to host the app (I eventually came up with Heroku)
  3. Review and learn the relevant SQL (Heroku came with a PostgreSQL addon, so I used that)
  4. Write the Flask routing code for navigating through the categories
  5. Integrate / link together buttons on the various pages so that one could navigate through the categories
  6. Implement use of databases to store and display all the relevant data
  7. Enable ability for end-user to add to the databases through post topic/message system
  8. Review the final project specifications and add any features that did not come naturally through the development thus far
  9. Implement Bootstrap to make everything look nice

I ended up following this process fairly well through step 8 - unfortunately I did not find the time to get through step 9, the addition of Bootstrap (I am unsure how easily it is implemented, as I have not used it before).

I did not encounter any major walls throughout my development process. There were small hurdles relevant to each of the major aspects - Flask, SQL, and Heroku - that I passed by reviewing documentation and class notes. On the whole, I put about 19 hours of work into this project as it stands at submission.

Database Structure

Table: topics
    topic_id - bigint
    topic_name - varchar(128)
    author - varchar(32)
    category - varchar(32)
    subcat1 - varchar(32)
    subcat2 - varchar(32)
    subcat3 - varchar(32)

Table: messages
    message_id - bigint
    author - varchar(32)
    message - text
    topic_id (foreign key dependent on topics.topic_id) - bigint

Next Steps

I hope to continue this project over winter break - the next step is to integrate Bootstrap into it, so that it actually looks nice and is usable. Beyond that, some basic admin functions (e.g. delete responses or topics) would be useful, along with various features like displaying a preview of the latest post associated with a topic, the number of posts associated with a topic, having a widget on the homepage that points out hot topics, etc.

References

https://devcenter.heroku.com/articles/getting-started-with-python-o - Setting up Flask to work with Heroku

https://docs.python.org/3/ - Python Docs

http://www.postgresql.org/docs/ - Postgresql Docs

About

[Retired 3.18.15] Web app that allows visitors to post messages on a message board.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published