示例#1
0
def signals_are_emitted(context):
    """Signal is emitted when templates are generated"""

    app = current_app._get_current_object()
    with captured_templates(app) as templates:
        render_template('test.html', context)

    assert templates.__len__() == 1
    assert templates[0][0].filename == 'test.html'
    assert templates[0][1]['name'] == 'Rudolf'
def loads_module_templates(context):
    """Templates can be loaded from module packages"""

    rendered = Assert(
        render_template('package_mod/module-template.txt', context))

    assert rendered == 'Hello modular Rudolf\n'
def overrides_module_templates(context):
    """Module templates can be overridden with application templates"""

    rendered = Assert(
        render_template('package_mod/nonmodule-template.txt', context))

    assert rendered == 'Hello nonmodular Rudolf\n'
示例#4
0
def overrides_module_templates(context):
    """Module templates can be overridden with application templates"""

    rendered = Assert(render_template('package_mod/nonmodule-template.txt',
                                      context))

    assert rendered == 'Hello nonmodular Rudolf\n'
示例#5
0
def loads_module_templates(context):
    """Templates can be loaded from module packages"""

    rendered = Assert(render_template('package_mod/module-template.txt',
                                      context))

    assert rendered == 'Hello modular Rudolf\n'
示例#6
0
def index_days(year=None, month=None, day=None):
  tweetids = []
  idx = {}
  try:
    year = str(int(year))
    month = "%02d" % int(month)
    day = "%02d" % int(day)
  except:
    year = None
    month = None
    day = None
  if year is None:
    now = datetime.datetime.now()
    year = str(now.year)
    month = "%02d" % now.month
    day = "%02d" % now.day
  try:
    idx = update_index()
    tweetids = list(idx['tweets'][year][month][day])
  except Exception as e:
    print e
  return render_template(
    'index.html', 
    { 'year':year, 
      'month': month,
      'day': day,
      'title': config.track,
      'navigation': sorted(flatten([ [ [ (y, m, d) for d in idx['tweets'][y][m].keys() ] for m in idx['tweets'][y].keys() ] for y in idx['tweets'].keys() ])),
      'tweetids': json.dumps(tweetids),
    });
示例#7
0
def index(year=None, kw=None):
  if config.paginate_by_day:
    return index_days()
  tweetids = []
  idx = {}
  try:
    year = str(int(year))
    kw = str(int(kw))
  except:
    year = None
    kw = None
  if year is None:
    (year, kw, day) = [ str(x) for x in datetime.datetime.now().isocalendar() ]
  try:
    idx = update_index()
    tweetids = list(idx['tweets'][year][kw])
  except Exception as e:
    print e
  return render_template(
    'index.html', 
    { 'year':year, 
      'kw':kw,
      'title': config.track,
      'navigation': sorted(set(flatten([ [ (y, k) for k in idx['tweets'][y].keys() ] for y in idx['tweets'].keys() ])), key=lambda x: int(x[1])),
      'tweetids': json.dumps(tweetids),
    });
示例#8
0
def index(time=300, step=5, preset='screw', sound='nosound'):
    sound = not (sound == "nosound")
    if step < 2:
        step = 2
    slide_params = handlers[preset](time, step)
    return render_template('index.html', {
        'slide_params': slide_params,
        'sound': sound,
        'step': step
    })
示例#9
0
def collage(screenname):
  screenname = re.sub(r'[^a-z0-9_]+', '', screenname.lower())
  idx = update_user_tweetindex(screenname)
  return render_template(
    'collage.html', 
    { 
      'screenname': screenname,
      'title': config.track,
      'tweetids': json.dumps(sorted(idx['tweets'])),
    });
示例#10
0
def user(screenname):
  screenname = re.sub(r'[^a-z0-9_]+', '', screenname.lower())
  idx = update_user_index(screenname)
  return render_template(
    'index.html', 
    { 
      'screenname': screenname,
      'title': config.track,
      'tweetids': json.dumps(sorted(idx['tweets'], reverse=False)),
    });
示例#11
0
def filters_per_render():
    """Filters can be applied per rendering"""
    def prepend_title(template):
        return template | Transformer('head/title').append(' - Flask-Genshi')

    rendered = Assert(render_template('filter.html', filter=prepend_title))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<html><head><title>Hi! - Flask-Genshi</title></head></html>')

    assert rendered == expected
示例#12
0
def book():
    """This is the endpoint for the passenger's data. The POSTed data is stored in
       the 'confirmation' dictionary. The variable 'booking status' is set to either None
       or the confirmation code, whether or not the flight is available. The success.html
       or failure.html is then returned via AJAX depending on that result."""
    confirmation = {'first_name' : request.form['first_name'],
                    'last_name' :  request.form['last_name'],
                    'bags' : request.form['bags'],
                    'flight_number' : request.form['flight_number']}
    booking_status = confirmBooking(request.form['flight_number'])
    if booking_status:
        # Retrieves copy of requested flight's data, via the find_flight_by_number function
        booked_flight = find_flight_by_number(request.form['flight_number'])
        # Replaces copy's timestamps and cost with more human-readable notation
        booked_flight['arrives']['when'] = format_date(booked_flight['arrives']['when'])
        booked_flight['departs']['when'] = format_date(booked_flight['departs']['when'])
        booked_flight['cost'] = format_money(booked_flight['cost'])
        return render_template('success.html', dict(confirmation = confirmation, code = booking_status, flight = booked_flight), method=None)
    else:
        return render_template('failure.html')
示例#13
0
def filters_per_render():
    """Filters can be applied per rendering"""

    def prepend_title(template):
        return template | Transformer('head/title').append(' - Flask-Genshi')

    rendered = Assert(render_template('filter.html', filter=prepend_title))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<html><head><title>Hi! - Flask-Genshi</title></head></html>')

    assert rendered == expected
示例#14
0
文件: app.py 项目: Xion/visual-camxes
def index():
    text = request.args.get('text', "coi pilno mi'e camxes")
    try:
        ast = camxes.parse(text)
        grammatical = camxes.isgrammatical(text)
    except:
        return redirect(url_for('index'))
    if 'json' in request.args:
        return jsonify(html=render_template('box.html', dict(text=text, ast=ast)),
            grammatical=grammatical)
    return render_response('index.html',
        dict(ast=ast, text=text, grammatical=grammatical))
示例#15
0
def index():
    text = request.args.get('text', "coi pilno mi'e camxes")
    try:
        ast = camxes.parse(text)
        grammatical = camxes.isgrammatical(text)
    except:
        return redirect(url_for('index'))
    if 'json' in request.args:
        return jsonify(html=render_template('box.html', dict(text=text,
                                                             ast=ast)),
                       grammatical=grammatical)
    return render_response('index.html',
                           dict(ast=ast, text=text, grammatical=grammatical))
示例#16
0
def does_translations():
    """Callback interface is able to inject Translator filter"""

    genshi = current_app.extensions['genshi']
    @genshi.template_parsed
    def callback(template):
        Translator(lambda s: s.upper()).setup(template)

    rendered = Assert(render_template('i18n.html'))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<p>HELLO!</p>')

    assert rendered == expected
示例#17
0
def applies_method_filters():
    """Method filters are applied for generated and rendered templates"""

    genshi = current_app.extensions['genshi']
    @genshi.filter('html')
    def prepend_title(template):
        return template | Transformer('head/title').prepend('Flask-Genshi - ')

    rendered = Assert(render_template('filter.html'))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<html><head><title>Flask-Genshi - Hi!</title></head></html>')

    assert rendered == expected
示例#18
0
def provides_jinja_tests_and_filters():
    """Jinja tests and filters should be provided as context dictionaries."""

    rendered = Assert(render_template('jinja_tests_and_filters.html'))
    expected_data = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                     '"http://www.w3.org/TR/html4/strict.dtd">\n'
                     '<p class="odd">\n'
                     '    Hello ...\n'
                     '  <span class="even">\n'
                     '      Hello ...\n'
                     '  </span>\n'
                     '</p>')

    assert rendered == expected_data
示例#19
0
def works_with_flatland():
    """Filters can take the context and support flatland"""

    genshi = current_app.extensions['genshi']
    @genshi.template_parsed
    def callback(template):
        flatland_setup(template)

    context = dict(form=TestForm({'username': '******'}))
    rendered = Assert(render_template('flatland.html', context))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<input type="text" name="username" value="dag">')

    assert rendered == expected
示例#20
0
def applies_method_filters():
    """Method filters are applied for generated and rendered templates"""

    genshi = current_app.extensions['genshi']

    @genshi.filter('html')
    def prepend_title(template):
        return template | Transformer('head/title').prepend('Flask-Genshi - ')

    rendered = Assert(render_template('filter.html'))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<html><head><title>Flask-Genshi - Hi!</title></head></html>')

    assert rendered == expected
示例#21
0
def does_translations():
    """Callback interface is able to inject Translator filter"""

    genshi = current_app.extensions['genshi']

    @genshi.template_parsed
    def callback(template):
        Translator(lambda s: s.upper()).setup(template)

    rendered = Assert(render_template('i18n.html'))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<p>HELLO!</p>')

    assert rendered == expected
示例#22
0
def works_with_flatland():
    """Filters can take the context and support flatland"""

    genshi = current_app.extensions['genshi']

    @genshi.template_parsed
    def callback(template):
        flatland_setup(template)

    context = dict(form=TestForm({'username': '******'}))
    rendered = Assert(render_template('flatland.html', context))
    expected = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" '
                '"http://www.w3.org/TR/html4/strict.dtd">\n'
                '<input type="text" name="username" value="dag">')

    assert rendered == expected
示例#23
0
def welcome():
  return render_template('index.html', {'slide_params': [], 'presets': handlers.keys() })
示例#24
0
def welcome():
    return render_template('index.html', {
        'slide_params': [],
        'presets': handlers.keys()
    })
示例#25
0
def render(template, **kwargs):
    kwargs.update({
        'static': lambda res: url_for('static', filename=res),
        'jsescape': jsescape,
    })
    return render_template(template, kwargs)
示例#26
0
文件: views.py 项目: 0xquad/nyms
def render(template, **kwargs):
    kwargs.update({
        'static' : lambda res: url_for('static', filename=res),
        'jsescape' : jsescape,
    })
    return render_template(template, kwargs)
示例#27
0
def index(time=300, step=5, preset='screw', sound='nosound'):
  sound = not (sound == "nosound")
  if step < 2:
    step = 2
  slide_params = handlers[preset](time, step)
  return render_template('index.html', {'slide_params': slide_params, 'sound': sound, 'step': step })