from app import app, db
from flask import render_template, url_for

# interests = {1 : {'area': 'Dragons', 'about': 'St. George in his famed battle \
# 				  against the Dragon.', 'image': True, 'FKUserId': 1}, 
# 			 2 : {'area': 'Hermits', 'about': 'Early Renaissance monastic life.',
# 			  	  'image': True, 'FKUserId': 1},
# 			 3 : {'area': 'Polyhedra', 'about': 'My stellated dodecahedron and more.',
# 			 	  'image': True, 'FKUserId': 1}
# 		}

# users = {1: {'name': 'Moon Flask', 'password': 'default', 'about': 'Moon Flask is \
# 			a simple content management system built on Flask. You can use it to \
# 			build a portfolio or personal website. Paolo Uccello serves as the \
# 			user for the sample app. Take a look at his interests below.'}}

# The FK_InterestIds should be changed to numbers, they match areas for now
# posts = {1: {'title': 'Dragons in our Times.', 'text': 'Aliquam ac mauris ante. Suspendisse \
# 			non tempor lectus, a dignissim felis. Nunc posuere, purus et \
# 			feugiat accumsan, lorem leo auctor turpis, quis vestibulum metus \
# 			magna id neque. Ut ac blandit odio. Praesent at elit vestibulum, \
# 			cursus erat luctus, aliquam eros. Mauris maximus dolor sed lorem \
# 			rhoncus, vel fringilla mi sagittis. Suspendisse faucibus nunc eu \
# 			enim pharetra, id lacinia elit venenatis. Integer interdum tellus \
# 			aliquam ipsum semper consequat. ', 'image': False, 'FK_InterestId': 'Dragons'},
# 		 2: {'title': 'St. George and the Dragon', 'text': 'Brave St.George.', 'image': True, 'FK_InterestId': 'Dragons'},
# 		 3: {'title': 'Episodes of the Hermit Life', 'text': 'Hermits and their role in monsatic life.', 'image': True, 'FK_InterestId': 'Hermits'},
# 		 4: {'title': 'Perspective Study of Mazzocchio', 'text': 'My famous sketch.', 'image': True, 'FK_InterestId': 'Polyhedra'},
# 		 5: {'title': 'More Shapes', 'text': 'Undiscovered polyhedra.', 'image': False, 'FK_InterestId': 'Polyhedra'}
# 	}


# Models
# Model names vary from list above. Need to translate to templates.
# todo: create FK reference between user and post
class User(db.Model):
	__tablename__ = "users"
	id = db.Column(db.Integer, primary_key=True)
	username = db.Column(db.String(64), unique=True, index=True)
	# password
	about = db.Column(db.Text)
	pages = db.relationship('Page', backref='author')
	posts = db.relationship('Post', backref='author')

	def __repr__(self):
		return '<User %r>' % self.username

class Page(db.Model):
	__tablename__ = "pages"
	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.String(64), unique=True, index=True)
	description = db.Column(db.Text)
	image = db.Column(db.Boolean, default=False)
	posts = db.relationship('Post', backref='page')
	user_id = db.Column(db.Integer, db.ForeignKey('users.id'))

	def __repr__(self):
		return '<Page %r>' % self.name

class Post(db.Model):
	__tablename__ = "posts"
	id = db.Column(db.Integer, primary_key=True)
	title = db.Column(db.String(64), index=True)
	body = db.Column(db.Text)	# Long enough? Use db.Text?
	image = db.Column(db.Boolean, default=False)
	user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
	page_id = db.Column(db.Integer, db.ForeignKey('pages.id'))

	def __repr__(self):
		return '<Post %r>' % self.title


@app.route('/')
def index():
	user = User.query.first()
	pages = Page.query.all()
	return render_template('index.html', user=user, pages=pages)

# Change interest to page for this route
@app.route('/page/<name>')
def page(name):
	pages = Page.query.all()
	posts = Post.query.all()
	return render_template('page.html', name=name, pages=pages, posts=posts)
@@ -67,2023 +67,14 @@
 %0A%0A# 
-interests = %7B1 : %7B'area': 'Dragons', 'about': 'St. George in his famed battle %5C%0A# %09%09%09%09  against the Dragon.', 'image': True, 'FKUserId': 1%7D, %0A# %09%09%09 2 : %7B'area': 'Hermits', 'about': 'Early Renaissance monastic life.',%0A# %09%09%09  %09  'image': True, 'FKUserId': 1%7D,%0A# %09%09%09 3 : %7B'area': 'Polyhedra', 'about': 'My stellated dodecahedron and more.',%0A# %09%09%09 %09  'image': True, 'FKUserId': 1%7D%0A# %09%09%7D%0A%0A# users = %7B1: %7B'name': 'Moon Flask', 'password': 'default', 'about': 'Moon Flask is %5C%0A# %09%09%09a simple content management system built on Flask. You can use it to %5C%0A# %09%09%09build a portfolio or personal website. Paolo Uccello serves as the %5C%0A# %09%09%09user for the sample app. Take a look at his interests below.'%7D%7D%0A%0A# The FK_InterestIds should be changed to numbers, they match areas for now%0A# posts = %7B1: %7B'title': 'Dragons in our Times.', 'text': 'Aliquam ac mauris ante. Suspendisse %5C%0A# %09%09%09non tempor lectus, a dignissim felis. Nunc posuere, purus et %5C%0A# %09%09%09feugiat accumsan, lorem leo auctor turpis, quis vestibulum metus %5C%0A# %09%09%09magna id neque. Ut ac blandit odio. Praesent at elit vestibulum, %5C%0A# %09%09%09cursus erat luctus, aliquam eros. Mauris maximus dolor sed lorem %5C%0A# %09%09%09rhoncus, vel fringilla mi sagittis. Suspendisse faucibus nunc eu %5C%0A# %09%09%09enim pharetra, id lacinia elit venenatis. Integer interdum tellus %5C%0A# %09%09%09aliquam ipsum semper consequat. ', 'image': False, 'FK_InterestId': 'Dragons'%7D,%0A# %09%09 2: %7B'title': 'St. George and the Dragon', 'text': 'Brave St.George.', 'image': True, 'FK_InterestId': 'Dragons'%7D,%0A# %09%09 3: %7B'title': 'Episodes of the Hermit Life', 'text': 'Hermits and their role in monsatic life.', 'image': True, 'FK_InterestId': 'Hermits'%7D,%0A# %09%09 4: %7B'title': 'Perspective Study of Mazzocchio', 'text': 'My famous sketch.', 'image': True, 'FK_InterestId': 'Polyhedra'%7D,%0A# %09%09 5: %7B'title': 'More Shapes', 'text': 'Undiscovered polyhedra.', 'image': False, 'FK_InterestId': 'Polyhedra'%7D%0A# %09%7D%0A%0A%0A# Models%0A# Model names vary from list above. Need to translate to templates.%0A# todo: create FK reference between user and post
+Models
 %0Acla
@@ -992,36 +992,8 @@
 ext)
-%09# Long enough? Use db.Text?
 %0A%09im
@@ -1362,48 +1362,8 @@
 s)%0A%0A
-# Change interest to page for this route
 %0A@ap

Clean up comments and remove test lists.