44"""
55
66import sys
7- if sys .version_info < (3 , 0 ):
8- raise RuntimeError ('You need Python 3.' )
9-
107import os
118import fnmatch
129import time
1310import datetime
1411import collections
15- from urllib .parse import urlencode
16-
17- from flask import Flask , render_template , url_for , send_from_directory
18- from flask_frozen import Freezer
1912import yaml
2013import jinja2
2114import markdown
2215import random
2316
24- from elsa import cli
2517from functools import lru_cache
18+ from urllib .parse import urlencode
19+ from flask import Flask , render_template , url_for , send_from_directory , abort
20+ from flask_frozen import Freezer
21+
22+ from elsa import cli
23+
24+ if sys .version_info < (3 , 0 ):
25+ raise RuntimeError ('You need Python 3.' )
26+
2627
2728app = Flask ('pyladies_cz' )
2829app .config ['TEMPLATES_AUTO_RELOAD' ] = True
3233v1_path = os .path .join (orig_path , 'v1/' )
3334MISSING = object ()
3435
36+
3537def redirect (url ):
3638 """Return a response with a Meta redirect"""
3739
@@ -67,7 +69,7 @@ def city(city_slug):
6769 current_meetups = [m for m in meetups if m ['current' ]]
6870 past_meetups = [m for m in meetups if not m ['current' ]]
6971 registration_meetups = [
70- m for m in current_meetups if m .get ('registration_status' )== 'running' ]
72+ m for m in current_meetups if m .get ('registration_status' ) == 'running' ]
7173 return render_template (
7274 'city.html' ,
7375 city_slug = city_slug ,
@@ -80,44 +82,54 @@ def city(city_slug):
8082 team = read_yaml (os .path .join ('cities' , city_slug , 'team.yml' ), default = ()),
8183 )
8284
85+
8386@app .route ('/<city>_course/' )
8487def course_redirect (city ):
8588 return redirect (url_for ('city' , city_slug = city , _anchor = 'meetups' ))
8689
90+
8791@app .route ('/<city>_info/' )
8892def info_redirect (city ):
8993 return redirect (url_for ('city' , city_slug = city , _anchor = 'city-info' ))
9094
95+
9196@app .route ('/praha-cznic/' )
9297def praha_cznic ():
9398 return redirect ('https://naucse.python.cz/2018/pyladies-praha-jaro-cznic/' )
9499
100+
95101@app .route ('/praha-ntk/' )
96102def praha_ntk ():
97103 return redirect ('https://naucse.python.cz/2018/pyladies-praha-jaro-ntk/' )
98104
105+
99106@app .route ('/stan_se/' )
100107def stan_se ():
101108 return render_template ('stan_se.html' )
102109
110+
103111@app .route ('/faq/' )
104112def faq ():
105113 return render_template ('faq.html' )
106114
115+
107116@app .route ('/v1/<path:path>' )
108117def v1 (path ):
109118 if path in REDIRECTS :
110119 return redirect (REDIRECTS [path ])
111120 return send_from_directory (v1_path , path )
112121
122+
113123@app .route ('/index.html' )
114124def index_html ():
115125 return redirect (url_for ('index' ))
116126
127+
117128@app .route ('/course.html' )
118129def course_html ():
119130 return send_from_directory (orig_path , 'course.html' )
120131
132+
121133@app .route ('/googlecc704f0f191eda8f.html' )
122134def google_verification ():
123135 # Verification page for GMail on our domain
@@ -135,7 +147,8 @@ def inject_cities():
135147 meetups_nonpermanent = [m for m in meetups if m .get ('start' )]
136148 cities [city_name ] = {
137149 ** city_info ,
138- 'active_registration' : any (m .get ('registration_status' ) == 'running' for m in meetups_nonpermanent ),
150+ 'active_registration' : any (m .get ('registration_status' ) == 'running'
151+ for m in meetups_nonpermanent ),
139152 }
140153 return dict (cities = cities )
141154
@@ -145,13 +158,15 @@ def inject_cities():
145158
146159md = markdown .Markdown (extensions = ['meta' , 'markdown.extensions.toc' ])
147160
161+
148162@app .template_filter ('markdown' )
149163def convert_markdown (text , inline = False ):
150164 result = jinja2 .Markup (md .convert (text ))
151165 if inline and result [:3 ] == '<p>' and result [- 4 :] == '</p>' :
152166 result = result [3 :- 4 ]
153167 return result
154168
169+
155170@app .template_filter ('date_range' )
156171def date_range (dates , sep = '–' ):
157172 start , end = dates
@@ -225,6 +240,7 @@ def read_yaml(filename, default=MISSING):
225240 data = yaml .safe_load (file )
226241 return data
227242
243+
228244def read_lessons_yaml (filename ):
229245 data = read_yaml (filename )
230246
@@ -269,8 +285,8 @@ def read_meetups_yaml(filename):
269285
270286 # Derive a URL for places that don't have one from the location
271287 if 'place' in meetup :
272- if ('url' not in meetup ['place' ]
273- and { 'latitude' , 'longitude' } <= meetup ['place' ].keys ()):
288+ if ('url' not in meetup ['place' ] and { 'latitude' ,
289+ 'longitude' } <= meetup ['place' ].keys ()):
274290 place = meetup ['place' ]
275291 place ['url' ] = 'http://mapy.cz/zakladni?' + urlencode ({
276292 'y' : place ['latitude' ],
@@ -294,6 +310,7 @@ def read_meetups_yaml(filename):
294310
295311 return list (reversed (data ))
296312
313+
297314def read_news_yaml (filename ):
298315 data = read_yaml (filename )
299316 today = datetime .date .today ()
@@ -305,6 +322,7 @@ def read_news_yaml(filename):
305322
306323 return news
307324
325+
308326def pathto (name , static = False ):
309327 if static :
310328 prefix = '_static/'
@@ -342,8 +360,9 @@ def inject_context():
342360
343361freezer = Freezer (app )
344362
363+
345364@freezer .register_generator
346- def v1 ():
365+ def v1 (): # noqa
347366 IGNORE = ['*.aux' , '*.out' , '*.log' , '*.scss' , '.travis.yml' , '.gitignore' ]
348367 for name , dirs , files in os .walk (v1_path ):
349368 if '.git' in dirs :
@@ -357,17 +376,21 @@ def v1():
357376 for path in REDIRECTS :
358377 yield url_for ('v1' , path = path )
359378
379+
360380OLD_CITIES = 'praha' , 'brno' , 'ostrava'
361381
382+
362383@freezer .register_generator
363- def course_redirect ():
384+ def course_redirect (): # noqa
364385 for city in OLD_CITIES :
365386 yield {'city' : city }
366387
388+
367389@freezer .register_generator
368- def info_redirect ():
390+ def info_redirect (): # noqa
369391 for city in OLD_CITIES :
370392 yield {'city' : city }
371393
394+
372395if __name__ == '__main__' :
373396 cli (app , freezer = freezer , base_url = 'http://pyladies.cz' )
0 commit comments