Skip to content

Instantly share code, notes, and snippets.

@ondoheer
Created November 20, 2014 20:19
Show Gist options
  • Select an option

  • Save ondoheer/1287ceff42e11f337b59 to your computer and use it in GitHub Desktop.

Select an option

Save ondoheer/1287ceff42e11f337b59 to your computer and use it in GitHub Desktop.
Flask-Stormpath-Wedding login function
@frontend.route('/')
@frontend.route('/index')
@login_required
@pony.db_session
def index():
# We check if the user exists in the database we load it,
# otherwise we create a new one.
user_id = user.get_id()
if database.exists("* from guest where stp_id ='{}'".format(user_id)):
guest = Guest.get(stp_id=user_id)
elif database.exists("* from guest where email = '{}'".format(user.email)):
guest = Guest.get(email=user.email)
else:
# we need to assing a color to the oser so his profile pic is always
# the same
colors = ['yellow', 'green', 'blue',
'violet', 'grey', 'white', 'orange']
guest = Guest(
stp_id=user_id,
nickname=user.full_name,
email=user.email,
role=ROLE_USER,
color=choice(colors)
)
bowlForm = MessageBowlForm()
musicForm = AddSongForm()
commentForm = CommentForm()
replyForm = ReplyForm()
# define number of items to get (it must be a string
# if it's going to be used as a SQL statement)
numberComments = 5
numberSongs = '5'
# get all items to list
posts = Post.select_by_sql('SELECT * FROM "post" ORDER BY "post"."id"')
songs = Song.select_by_sql(
'SELECT * FROM song LIMIT 0,' + numberSongs + '') # ORDER BY genre
guests = Guest.select_by_sql('SELECT * FROM guest')
return render_template(
'index.html',
title='Home',
guest=guest,
guests=guests,
songs=songs,
posts=posts,
numberComments=numberComments,
bowlForm=bowlForm,
musicForm=musicForm,
commentForm=commentForm,
replyForm=replyForm,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment