SSDP Chapter Activity Tracker
v3.0.0 - Flask Rebuild
A web application to track activity in the Students For Sensible Drug Policy network The Flask CAT was built with Flask v1.0 and Python 3.
These instructions apply to our setup on Dreamhost and may vary depending on your web hosting services.
- Set up and fully host a new domain with Dreamhost. Make sure the server can run Python apps. For DH, just check off the "Passenger" setting.
- Clone the repository into the directory that looks like something.domain.com. I set mine up as
git clone https://github.com/SSDP-Dev/flask-cat.git cat
- Install a custom version of Python 3.
- Set up a new virtualenv in a separate directory inside something.domain.com/cat. I set mine up as
- With your virtualenv activated (refer to step 4 for help), install Flask with
pip3 install Flask
- You'll want to create a
passenger_wsgi.pyfile. There's an example in the root of this repo, which you should be able to move into
something.domain.com/. You may need to change some of the settings in there, like the INTERP variable (set it to the python3 interpreter you want to use - most likely
cat/venv/bin/python3) and the systempath (make sure you append it with the app name, most likely
- In that same directory, do the following
mkdir tmp touch tmp/restart.txt
- Every time you make changes to your Passenger config, touch
That should do the trick.
Important Notes This repo ships with a standard database. It includes only one entry: a user with username 'admin' and password 'admin'. For privacy reasons, we don't list anything else in there. You'll have to fill in the rest, but you'll definitely want to change your password.
You'll want to set up a Flask development environment to work on this. You can learn more about the steps to do so in the Flask Documentation.
├── admin.py ├── auth.py ├── blog.py ├── chapters.py ├── db.py ├── __init__.py ├── schema.sql ├── static │ ├── bootstrap.css │ ├── bootstrap.min.js │ ├── custom.css │ ├── logo-transparent.png │ └── SSDP20-logo-transparent.png └── templates ├── admin │ ├── activities.html │ ├── categories.html │ ├── index.html │ ├── spending.html │ ├── stats.html │ ├── user-edit.html │ ├── user-list.html │ └── users.html ├── auth │ ├── login.html │ └── register.html ├── base.html ├── blog │ ├── available-activities.html │ ├── create.html │ ├── faq.html │ ├── index.html │ ├── leaderboard.html │ ├── store.html │ └── update.html └── chapters ├── chapter.html └── index.html
This is where all the administrative functions and pages live. The index, at /admin, is a landing page for all those pages and functions. It should just be a column of buttons that include links and fuctions for users to control their CAT experience.
Users with the permissions 'Admin' can see all of the controls. 'Staffer' gets fewer. 'Chapter' gets the least.
This class controls:
- Creating unique URLs for user pages with
- Generating the stats page with
- Adding users with
- Adding point categories with
- Logging points with
- Spending points with
- One-off commands with
RESETwill reset the stats in the user table
BACKUPwill create a backup of the database. There's notes in the documentation in this class, but for good measure: you need to have a folder called
/backupsin your root directory for this to work. Otherwise it won't. Planning some funcationality to hook into a Google Drive or DropBox or something
- Editing user information through the
This class controls logging in and logging out. It's almost a direct duplicate of the Flaskr tutorial login system.
I pretty much didn't change anything from the tutorial here - so not much to say about it. If you want to dig in to how things are working, check out the tutorial and feel free to make changes there. Login systems are beyond my abilities at the moment, so I won't make many changes here.
This class came from the Flaskr tutorial as well.
The tutorial gave me a few things like creating 'blog posts' and editing them, so I kept the bulk of that to use with actions.
I never changed it from
blog because I didn't want to create any weird bugs. Maybe later on down the road we'll clean it up in refactoring. For now, here's what we do:
- Control the homepage for the entire site with
- Control the creation of action with
- This is not how we're creating actions. We could, but we're doing it better in admin.activities(). Leaving this in for now, but will come back and remove it during refactoring and cleanup
- Retrieve actions through
- Update actions with
- Delete actions with
- Render a leaderboard with
- Render the available activities page through
- Render the FAQ with
- Render the store with
- This may need to get merged or changed with the spending function in the admin class
Lots of these methods are good boilerplates for manipulating the database in other ways, so I've kept a lot of it pretty close to the tutorial.
This class provides methods to work with chapter data. It's a bit more front facing.
Here's what this class does:
- Displays all of the chapters in a page with
- Return a chapter from the database with
- Displays a chapter page with
This class was also provided by the Flaskr tutorial. In the same fashion, I really didn't make any changes here.
The biggest thing to note is that I was having trouble getting click to work and couldn't make new CLI commands. That was a hassle during development, so I just overrode the one CLI command that did work.
There are some comments in
init_db() that go over those overrides and how I used them.
Another class that came from the Flaskr tutorial. My understanding is this class initializes the Flask app and registers blueprints and URL rules. I've only added here what I needed for Blueprints and URLs.
This is the SQL schema for the SQLite database. It's the first database I've ever designed from the ground up, so could be refined. I'm somewhat hopeful I built it in such a way that it's at least easy to extend.
We've got the bootstrap CSS and JS, along with a custom CSS file here and other assets. Pretty straightforward. Any other required assets should live in this directory.
Flask uses the Jinja2 templating language for HTML templates.
This template provides the
<html> tags, along with the nav bar.
In the future, we might pull out some of those components for better structure.
This template is where we log activities.
This page allows us to create new types of actions
Landing page for the control panel for all types of users.
This template allows us to create new spending.
Renders a stats page. Most of the interesting work is done on the Python side for this one, and the HTML just renders the values.
Allows us to edit some values for each user.
Renders a list of users and their user-edit links. In the future this will include a search function. For now, ctrl+f will have to do.
Allows us to add new users.
Login page - provided by Flask tutorial
Register page - disabled in our app for now. Will likely need to remove or consider enabling this in the future.
Lists the available activities
Used to create blog posts/actions. Disabled in our app, and should consider re-enabling it or removing it in a refactor.
Displays the FAQ page.
Default home page of the site. Right now displays an activity feed. In the future, it could display more. One TODO here is adding links to the chapter pages and links to the activity descriptions in the feed.
Displays the leaderboard
Displays the store. As stated in the control documentation for this - we have duplicative code here and could probably stand to remove either this or the control panel option.
Allows us to update action information.
Single chapter page, displays stats and an activity feed for that chapter.
Displays a list of all the chapters and includes links to their chapter pages.
- PEP8 standards
- WCAG standards
- Email notifications for staffers, chapters, etc.
- Twitter integration for activity feed
- Mozilla Observatory changes
- Automate points to Master List and/or NationBuilder
- Consistent login reqs across pages
- Learn D3 and use it to render cool stats and stuff
- Added Flask-SSLify requirement. May need to add that in setup instructions
- Clean up the database that we ship with, figure out good way to distribute venv, etc.
- Document new templates, methods, etc. that haven't made it in since the first documentation session.
- Add note about Google Analytics