Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:boulder-python/boulderpython.org…
Browse files Browse the repository at this point in the history
… into develop

FIXES PyColorado#35, Add a top navigation link to Trello Board
  • Loading branch information
frankV committed Dec 1, 2018
1 parent 7d6351b commit ad2e0d8
Show file tree
Hide file tree
Showing 28 changed files with 511 additions and 476 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@ venv.bak/
appengine-generated/
node_modules/
application/local.cfg
dump.sql
dump.sql
.pytest_cache/
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.6
7 changes: 5 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sphinx-rtd-theme = "*"
ipython = "*"
livereload = "*"
click = "*"
black = "==18.9b0"

[packages]
flask = "*"
Expand All @@ -27,10 +28,12 @@ meetup-api = "*"
flask-caching = "*"
flask-wtf = "*"
flask-sqlalchemy = "*"
"psycopg2" = "*"
py-trello = {ref = "b929721397077f31a06603d7bb7843526d2a926b", git = "https://github.com/boulder-python/py-trello.git", editable = true}
py-trello = {ref = "b929721397077f31a06603d7bb7843526d2a926b",git = "https://github.com/boulder-python/py-trello.git",editable = true}
celery = "*"
flask-celery-helper = "*"
flask-sendgrid = "*"
"markdown2" = "*"
flask-migrate = "*"
psycopg2-binary = "*"
bugsnag = {extras = ["flask"],version = "*"}
blinker = "*"
116 changes: 84 additions & 32 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ another.

## Website Contributions

We welcome contributions, changes, and corrections to our website. Please submit a pull request.
We welcome contributions, changes, and corrections to our website. Please submit a pull request.

### Running

Expand Down Expand Up @@ -121,4 +121,12 @@ Celery requires a task broker. Either RabbitMQ or Redis are good choices.
To run Celery, use the following command:
```
$ FLASK_CONFIG=local.cfg flask celeryd
```


### Pre-Commit Hooks

Initialize pre-commit hooks for auto-Black'ing (you should already have ``pre-commit`` installed in your system python):
```
$ pre-commit install
```
25 changes: 16 additions & 9 deletions application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytz
from flask import Flask
import bugsnag.flask

from config import config
from application.extensions import db, migrate, cache, moment, celery
Expand All @@ -28,28 +29,34 @@ def create_app(config=None):


def configure(app, config_name):
app.config.from_object(config[config_name or 'default'])
app.config.from_envvar('FLASK_CONFIG', silent=True)
selected_config = config[config_name or "default"]
app.config.from_object(selected_config)
app.config.from_envvar("FLASK_CONFIG", silent=True)

db.init_app(app)
migrate.init_app(app)
cache.init_app(app)
moment.init_app(app)
celery.init_app(app)
# mail.init_app(app)

if selected_config.BUGSNAG_API_KEY:
# Configure Bugsnag
bugsnag.configure(api_key=selected_config.BUGSNAG_API_KEY, auto_capture_sessions=True)

bugsnag.flask.handle_exceptions(app)


def register_blueprints(app):
'''Register all blueprint modules'''
"""Register all blueprint modules"""
app.register_blueprint(bp)


def register_filters(app):
@app.template_filter('convert_ms')
def convert_ms(ms, offset=0, format='%B %d, %Y %I:%M%p'):
@app.template_filter("convert_ms")
def convert_ms(ms, offset=0, format="%B %d, %Y %I:%M%p"):
sec = ms / 1000.0

if os.name == 'nt':
if os.name == "nt":
# Windows has a "minimum allowed" timestamp: https://stackoverflow.com/a/45372194
sec = max(sec, 86400)

Expand All @@ -61,11 +68,11 @@ def convert_ms(ms, offset=0, format='%B %d, %Y %I:%M%p'):

return timestamp.strftime(format)

@app.template_filter('autoversion')
@app.template_filter("autoversion")
def autoversion_filter(filename):
return autoversion(filename)

@app.template_filter('markdown')
@app.template_filter("markdown")
def markdown_filter(value):
return markdown(value)

Expand Down
1 change: 1 addition & 0 deletions application/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from flask_moment import Moment
from flask_caching import Cache
from flask_celery import Celery

# from flask_sendgrid import SendGrid


Expand Down
19 changes: 10 additions & 9 deletions application/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
Jinja template filters
"""

import os, pathlib
import os
import pathlib
import markdown2

from flask import request


def autoversion(filename):
''' Returns a string matching the filename and a query param of the file's
""" Returns a string matching the filename and a query param of the file's
last modification time in milliseconds
Useful for agressive caching of static assets like app JavaScript and CSS.
Expand All @@ -22,17 +23,17 @@ def autoversion(filename):
Returns:
string: a filename plus it's version number query param
'''
"""
fullpath = os.path.join(pathlib.Path(__file__).parent, filename[1:])
try:
timestamp = str(os.path.getmtime(fullpath))
except OSError as e:
return filename
return '{0}?v={1}'.format(filename, timestamp)
return "{0}?v={1}".format(filename, timestamp)


def current_route(value, *args):
''' Returns the a string `current` if URL matches value.
""" Returns the a string `current` if URL matches value.
Useful for navigation elements in templates to add a class name if the current
page matches the nav element's target href.
Expand All @@ -42,18 +43,18 @@ def current_route(value, *args):
Returns:
string: 'current' if conditional is met, otherwise nothing
'''
"""
if value == str(request.url_rule):
return 'current'
return "current"


def markdown(value):
''' Converts the specified markdown string to HTML
""" Converts the specified markdown string to HTML
Args:
value (str): Markdown string
Returns:
string: HTML equivalent
'''
"""
return markdown2.markdown(value)
Loading

0 comments on commit ad2e0d8

Please sign in to comment.