fedora-python / fedoralovespython.org

Fedora Loves Python website
https://fedoralovespython.org/
MIT License
15 stars 7 forks source link

Alternative views #36

Closed encukou closed 7 years ago

encukou commented 7 years ago

I'd like to use some representative content in demos. Why not F♥P talking points?

This adds endpoints showing the data as JSON, text, and text with terminal color sequences.

hroncok commented 7 years ago

When freezing the index.txt has colorized header while it shouldn't have:

colors

When just serving, I see the following behavior:

  1. start server
  2. fetch txt as a first thing (no color)
  3. fetch term (header no color, rest color)
  4. fetch txt (no color)
  5. keeps repeating

And:

  1. start server
  2. fetch term as a first thing (all color)
  3. fetch txt (header color, rest no color)
  4. fetch term (all color)
  5. keeps repeating
hroncok commented 7 years ago

Is there some automagic caching involved?

@app.template_filter('term_color')
def term_color(text, color):
    print(g.colors)
    if g.colors:
        ...
False printed 22 times
127.0.0.1 - - [07/Aug/2017 16:59:15] "GET /index.txt HTTP/1.1" 200 -
True printed 17 times
127.0.0.1 - - [07/Aug/2017 16:59:24] "GET /index.term HTTP/1.1" 200 -
False printed 17 times
127.0.0.1 - - [07/Aug/2017 17:00:10] "GET /index.txt HTTP/1.1" 200 -
hroncok commented 7 years ago

Setting app.jinja_env.cache = None disables the cache and workarounds the issue.

However, if there is a way to either not use the g or mark that part of the template as not cachable or similar, I'd rather use that.

encukou commented 7 years ago

Thanks for the review! The jinja caching surprised me. I pushed fixes that should address your points.

encukou commented 7 years ago

Ah, I see what you meant. That's what I get for testing with less...