Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

when i run my python/flask program i get click able URL\'s in the console output

ID: 3871868 • Letter: W

Question

when i run my python/flask program i get click able URL's in the console output. I am trying to figure out why? Do i have a pycharm plugin installed or is it my source code somewhere??

see code and picture below

PYTHON/flask code here

#!/usr/bin/env python
# Based on: http://stackoverflow.com/questions/26057710/datepickerwidget-with-flask-flask-admin-and-wtforms
# Time picker stuff from: https://wtforms-components.readthedocs.io/en/latest/

import os
from datetime import datetime

from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms.fields.html5 import DateField
from wtforms_components import TimeField
from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

app = Flask(__name__)
app.secret_key = 'SHH!'


# db class
class DataBase(object):
basedir = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')

def __init__(self, db_url=SQLALCHEMY_DATABASE_URI):
self.engine = create_engine(db_url, convert_unicode=True)
self.db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=self.engine))
self.Base = declarative_base()
self.Base.query = self.db_session.query_property()

def init_db(self):
""" Create the database with all tables """
self.Base.metadata.create_all(bind=self.engine)

def fill_db(self):
"""Fill the database with test data"""
if not Image.query.all():
self.db_session.add(Image(
name='96-20170217202336-05',
date_time=datetime.strptime('20170217202336', '%Y%m%d%H%M%S')))
self.db_session.add(Image(
name='98-20170217202523-04',
date_time=datetime.strptime('20170217202523', '%Y%m%d%H%M%S')))
self.db_session.add(Image(
name='99-20170217202539-05',
date_time=datetime.strptime('20170217202539', '%Y%m%d%H%M%S')))
self.db_session.commit()

db = DataBase()


# model
class Image(db.Base):
""" Model for table Images """
__tablename__ = 'Images'
id = Column(Integer, index=True, primary_key=True, autoincrement=True)
name = Column(String(128))
date_time = Column(DateTime, default=datetime.now())

def __init__(self, name, date_time):
self.name = name
self.date_time = date_time


db.init_db()
db.fill_db()


class ExampleForm(FlaskForm):
dt_from = DateField('DatePicker', format='%Y-%m-%d')
tm_from = TimeField('TimePicker')
dt_to = DateField('DatePicker', format='%Y-%m-%d')
tm_to = TimeField('TimePicker')


@app.route('/', methods=['POST', 'GET'])
def hello_world():

form = ExampleForm()
if form.validate_on_submit():
start = ' '.join([request.form['dt_from'], request.form['tm_from']])
end = ' '.join([request.form['dt_to'], request.form['tm_to']])
result = Image.query.filter(
Image.date_time <= end).filter(Image.date_time >= start)
return render_template('date_picker.html',
form=form,
images_list=list(result))
return render_template('date_picker.html', form=form, images_list=False)


if __name__ == '__main__':
# app.run(host='192.168.33.10', port=8080, debug=True)
app.run(debug=True)

File templates/date-picker.html:

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Date Selection</h2>
<form action="#" method="post">
<label> Date from:
{{ form.dt_from(class='datepicker') }}
{{ form.tm_from( ) }}
</label>
<label>Date to:
{{ form.dt_to(class='datepicker') }}
{{ form.tm_to( ) }}
</label>
{{ form.hidden_tag() }}
<input type="submit"/>
</form>
{% if images_list %}
<h2>Files that were found:</h2>
<table class="table">
<thead>
<tr>
<th>Date&time</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{% for image in images_list %}
<tr>
<td>{{ image.date_time }}</td>
<td>{{ image.name }}</td>
</tr>
{% endfor %}
</tbody>

</table>
{% endif %}
</div>
</body>
</html>

A as 1270.0.1 XIE Decep UserschkDescenplaythontaseproject this categy Pharm community Edition 2017. O A 127.00 1 scoor. * A LA Desktop a a + 1 pm Boyer help-destest-coded Date Selection O126 AM Date from: 222015 Date to: 1262017 7:29 PM 0 V Desktop Adherence Cass B FALL 20 V python a palliatwhorses have seven years as it was a social has inspirin indust call from a hospelwater rear-weaponent matchesion in n/a test Port "TT. Ramrat key set land stains an object handir na path . shapesh (ne path. dirhams (file) JGALonen_DATABAaron ne - sal1to1// as path. in Ibadir, app de) Python Perhofia a pythonia " Butches scripting Seagate Scituate A descop Desktop 1L, "QualexMANAMAs Rolf, engine senator angina (All ri, PenrRatani and Stern) not disression - toopedression (Sarsformskar (autocortPales, autotush-Palse, ind-sic. engine a L. Has a resultative bowen Ani, Mann, piary sal. Ah _ransion guary reporty (I defiade to it 12 r, a at sti. ch 8 233Asset Python a Rantarsing with that - Deitage is activel E . Deluccex N : 270-07g-720 Bunting was a past 1ST... An POOL (ARMM ewe to ruit) 127..1 - - 12/simpa17 13241 aer 1 were 1.1" Aon - (R/ap/2012 1529a) poor / TTS1.17 00 17.0.0.1 - - 17/aep/eu.7 1 ) TOOT NETT / 1 0 - 107.0.0.1 - - (7/asp/2012 12: s: FOUR RE. 1" too - 11.0.0.1 - - 18/sup/2011 1:28.341 "year ear/1.1" too - - (23/sara17 16:4111 or I wrT11" (HR/Sep 7 16411Bs) TopTI TE/.1 vo 0 Pecharge installed sales will retailed package idio-T, becauPont, TL. Codey 24 PM a DP O Type there to search 02/2011

Explanation / Answer

#!/usr/bin/env python
# Based on: http://stackoverflow.com/questions/26057710/datepickerwidget-with-flask-flask-admin-and-wtforms
# Time picker stuff from: https://wtforms-components.readthedocs.io/en/latest/

import os
from datetime import datetime

from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from wtforms.fields.html5 import DateField
from wtforms_components import TimeField
from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

app = Flask(__name__)
app.secret_key = 'SHH!'


# db class
class DataBase(object):
basedir = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')

def __init__(self, db_url=SQLALCHEMY_DATABASE_URI):
self.engine = create_engine(db_url, convert_unicode=True)
self.db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=self.engine))
self.Base = declarative_base()
self.Base.query = self.db_session.query_property()

def init_db(self):
""" Create the database with all tables """
self.Base.metadata.create_all(bind=self.engine)

def fill_db(self):
"""Fill the database with test data"""
if not Image.query.all():
self.db_session.add(Image(
name='96-20170217202336-05',
date_time=datetime.strptime('20170217202336', '%Y%m%d%H%M%S')))
self.db_session.add(Image(
name='98-20170217202523-04',
date_time=datetime.strptime('20170217202523', '%Y%m%d%H%M%S')))
self.db_session.add(Image(
name='99-20170217202539-05',
date_time=datetime.strptime('20170217202539', '%Y%m%d%H%M%S')))
self.db_session.commit()

db = DataBase()


# model
class Image(db.Base):
""" Model for table Images """
__tablename__ = 'Images'
id = Column(Integer, index=True, primary_key=True, autoincrement=True)
name = Column(String(128))
date_time = Column(DateTime, default=datetime.now())

def __init__(self, name, date_time):
self.name = name
self.date_time = date_time


db.init_db()
db.fill_db()


class ExampleForm(FlaskForm):
dt_from = DateField('DatePicker', format='%Y-%m-%d')
tm_from = TimeField('TimePicker')
dt_to = DateField('DatePicker', format='%Y-%m-%d')
tm_to = TimeField('TimePicker')


@app.route('/', methods=['POST', 'GET'])
def hello_world():

form = ExampleForm()
if form.validate_on_submit():
start = ' '.join([request.form['dt_from'], request.form['tm_from']])
end = ' '.join([request.form['dt_to'], request.form['tm_to']])
result = Image.query.filter(
Image.date_time <= end).filter(Image.date_time >= start)
return render_template('date_picker.html',
form=form,
images_list=list(result))
return render_template('date_picker.html', form=form, images_list=False)


if __name__ == '__main__':
# app.run(host='192.168.33.10', port=8080, debug=True)
app.run(debug=True)

File templates/date-picker.html:

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Date Selection</h2>
<form action="#" method="post">
<label> Date from:
{{ form.dt_from(class='datepicker') }}
{{ form.tm_from( ) }}
</label>
<label>Date to:
{{ form.dt_to(class='datepicker') }}
{{ form.tm_to( ) }}
</label>
{{ form.hidden_tag() }}
<input type="submit"/>
</form>
{% if images_list %}
<h2>Files that were found:</h2>
<table class="table">
<thead>
<tr>
<th>Date&time</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{% for image in images_list %}
<tr>
<td>{{ image.date_time }}</td>
<td>{{ image.name }}</td>
</tr>
{% endfor %}
</tbody>

</table>
{% endif %}
</div>
</body>
</html>