diff --git a/.travis.yml b/.travis.yml index 93bdf9dcb..2ae0cae00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ python: - "3.6" cache: "pip" script: - - "python pyladies_cz.py freeze" + - "python -m pip install -r test-requirements.txt && pytest tests/ && + flake8 --ignore=E266,F811 --max-line-length=100 --exclude=original/ && + python pyladies_cz.py freeze" env: global: - secure: "N+iAAkw+nVaPyI/yPUr3LeHRlLgbmjcn58768zKdeHqBYjJGB+wLe54yE4a6ed5evT5wabHV6fc2XfYbjkjmWNh7XLbEYqzU1HfelhZogo7VZEL2txkpjx8MM37XDFb2BxXieDuX/Gs0myCJj+eoVNWmD9ia6Y3lKgryJmtdR+qRDrxvLpHrDhJ3bpbd0nk14O6LKQI5SW7fMm9wLx62xb9F94H5hWx/TPRuKq/txuda7eATbiWvsDGfH6TDmJD89DKmMiLdJkVms1BA9wi5fAetf8orsAD+CUdm0QZm368MexIxeRbIUDUkqsFgyQk3UOUny7sc4HyXxO6WBaAE7qsxFeiSTzBvAY0ZH+OfTG8QW26tZy7aGBwcbDWvsFUoZ7egX5GLJ83g14xd2tY63S0iNbKuQUAhz3FEUoCrLCzOeY3kP2q6X12BCYqJkcPw4ylUnQYnHKloeacw52ae1KCwm/JE3wq0/9yQ2NwlEY5QYAAi895Say/BIxMkIdJp8qXa0bIRmKLJlgArtoCEXOdwlMckP2aYS0YLF8dsOQpdvTp0+32dcfeaL8W3Cg9SAgic9yOq0GWH0L6kMkYLQRDj6iZU9mgpuMFkEebuV06BwO0795HB0QrqC2mW+EgpvY0kuSjsDGmloozSx0h4wWGHKQ6i+Ai6tgXxGSvO3Jw=" diff --git a/pyladies_cz.py b/pyladies_cz.py index 57fe8a150..1f844d77c 100755 --- a/pyladies_cz.py +++ b/pyladies_cz.py @@ -4,25 +4,26 @@ """ import sys -if sys.version_info < (3, 0): - raise RuntimeError('You need Python 3.') - import os import fnmatch import time import datetime import collections -from urllib.parse import urlencode - -from flask import Flask, render_template, url_for, send_from_directory -from flask_frozen import Freezer import yaml import jinja2 import markdown import random -from elsa import cli from functools import lru_cache +from urllib.parse import urlencode +from flask import Flask, render_template, url_for, send_from_directory, abort +from flask_frozen import Freezer + +from elsa import cli + +if sys.version_info < (3, 0): + raise RuntimeError('You need Python 3.') + app = Flask('pyladies_cz') app.config['TEMPLATES_AUTO_RELOAD'] = True @@ -32,6 +33,7 @@ v1_path = os.path.join(orig_path, 'v1/') MISSING = object() + def redirect(url): """Return a response with a Meta redirect""" @@ -67,7 +69,7 @@ def city(city_slug): current_meetups = [m for m in meetups if m['current']] past_meetups = [m for m in meetups if not m['current']] registration_meetups = [ - m for m in current_meetups if m.get('registration_status')=='running'] + m for m in current_meetups if m.get('registration_status') == 'running'] return render_template( 'city.html', city_slug=city_slug, @@ -80,44 +82,54 @@ def city(city_slug): team=read_yaml(os.path.join('cities', city_slug, 'team.yml'), default=()), ) + @app.route('/_course/') def course_redirect(city): return redirect(url_for('city', city_slug=city, _anchor='meetups')) + @app.route('/_info/') def info_redirect(city): return redirect(url_for('city', city_slug=city, _anchor='city-info')) + @app.route('/praha-cznic/') def praha_cznic(): return redirect('https://naucse.python.cz/2018/pyladies-praha-jaro-cznic/') + @app.route('/praha-ntk/') def praha_ntk(): return redirect('https://naucse.python.cz/2018/pyladies-praha-jaro-ntk/') + @app.route('/stan_se/') def stan_se(): return render_template('stan_se.html') + @app.route('/faq/') def faq(): return render_template('faq.html') + @app.route('/v1/') def v1(path): if path in REDIRECTS: return redirect(REDIRECTS[path]) return send_from_directory(v1_path, path) + @app.route('/index.html') def index_html(): return redirect(url_for('index')) + @app.route('/course.html') def course_html(): return send_from_directory(orig_path, 'course.html') + @app.route('/googlecc704f0f191eda8f.html') def google_verification(): # Verification page for GMail on our domain @@ -135,7 +147,8 @@ def inject_cities(): meetups_nonpermanent = [m for m in meetups if m.get('start')] cities[city_name] = { **city_info, - 'active_registration': any(m.get('registration_status') == 'running' for m in meetups_nonpermanent), + 'active_registration': any(m.get('registration_status') == 'running' + for m in meetups_nonpermanent), } return dict(cities=cities) @@ -145,6 +158,7 @@ def inject_cities(): md = markdown.Markdown(extensions=['meta', 'markdown.extensions.toc']) + @app.template_filter('markdown') def convert_markdown(text, inline=False): result = jinja2.Markup(md.convert(text)) @@ -152,6 +166,7 @@ def convert_markdown(text, inline=False): result = result[3:-4] return result + @app.template_filter('date_range') def date_range(dates, sep='–'): start, end = dates @@ -225,6 +240,7 @@ def read_yaml(filename, default=MISSING): data = yaml.safe_load(file) return data + def read_lessons_yaml(filename): data = read_yaml(filename) @@ -269,8 +285,8 @@ def read_meetups_yaml(filename): # Derive a URL for places that don't have one from the location if 'place' in meetup: - if ('url' not in meetup['place'] - and {'latitude', 'longitude'} <= meetup['place'].keys()): + if ('url' not in meetup['place'] and {'latitude', + 'longitude'} <= meetup['place'].keys()): place = meetup['place'] place['url'] = 'http://mapy.cz/zakladni?' + urlencode({ 'y': place['latitude'], @@ -294,6 +310,7 @@ def read_meetups_yaml(filename): return list(reversed(data)) + def read_news_yaml(filename): data = read_yaml(filename) today = datetime.date.today() @@ -305,6 +322,7 @@ def read_news_yaml(filename): return news + def pathto(name, static=False): if static: prefix = '_static/' @@ -342,8 +360,9 @@ def inject_context(): freezer = Freezer(app) + @freezer.register_generator -def v1(): +def v1(): # noqa: F811 IGNORE = ['*.aux', '*.out', '*.log', '*.scss', '.travis.yml', '.gitignore'] for name, dirs, files in os.walk(v1_path): if '.git' in dirs: @@ -357,17 +376,21 @@ def v1(): for path in REDIRECTS: yield url_for('v1', path=path) + OLD_CITIES = 'praha', 'brno', 'ostrava' + @freezer.register_generator -def course_redirect(): +def course_redirect(): # noqa: F811 for city in OLD_CITIES: yield {'city': city} + @freezer.register_generator -def info_redirect(): +def info_redirect(): # noqa: F811 for city in OLD_CITIES: yield {'city': city} + if __name__ == '__main__': cli(app, freezer=freezer, base_url='http://pyladies.cz')