示例#1
0
def friends():
	#Check that user has logged in before you let execute this route
	#if not('isLogged in session') or (session['isLogged'] == False):
	#	return redirect('/')
	form = FriendForm()
	if request.method == 'GET':
		return render_template('template_friends.html',form=form, isLogged=True)
	else:
		if form.validate_on_submit():

			temp = Friends(form.name.data,form.address.data,form.age.data,session['user_id'])

			#Save the image if present
			if form.upload_file.data:
				filename = secure_filename(form.upload_file.data.filename)
				form.upload_file.data.save('app/static/images' + form.upload_file.data.filename)			
				temp.filename ='/static/images/' + filename
			
			db.session.add(temp)
			db.session.commit()	
			#tapa 2
			user = Users.query.get(session['user_id'])
			print(user.friends)
			return render_template('template_user.html',isLogged=True,friends=user.friends)			            
		else:
			flash('At least one field is empty')
			return render_template('template_friends.html',isLogged=True,form=form)			
示例#2
0
def friends():
	form = FriendForm()
	if request.method == 'GET':
		return render_template('template_friends.html',form=form,isLogged=True)
	else:
		if form.validate_on_submit():
		
			temp = Friends(form.name.data,form.address.data,form.age.data,session['user_id'])
			#Save the image if present
			if form.upload_file.data:
				filename = secure_filename(form.upload_file.data.filename)
				form.upload_file.data.save('app/static/images/' + filename)
				temp.filename = '/static/images/' + filename
			db.session.add(temp)
			db.session.commit()
			#tapa 2
			user = Users.query.get(session['user_id'])
			friends = Friends.query.filter_by(user_id=user.id).paginate(1,10,False)
			return render_template('template_user.html',isLogged=True,friends=friends)
		else:
			flash('Give proper values to all fields')
			return redirect(url_for('ud.friends'))
示例#3
0
def friends():
    form = FriendForm()
    if request.method == 'GET':
        return render_template('template_friends.html',form=form,isLogged=True)
    else:
        if form.validate_on_submit():
            temp = Friends(form.name.data,form.address.data,form.age.data,session['user_id'])
            #Save the image if present
            if form.upload_file.data:
                filename = secure_filename(form.upload_file.data.filename)
                form.upload_file.data.save('app/static/images/' + filename)
                temp.filename = '/static/images/' + filename
            db.session.add(temp)
            db.session.commit()
            #tapa 2: 
                #Users -modeliin on määritetty db.relationship -> sisältää friends -tiedot
            user = Users.query.get(session['user_id']) #Luo päivitetyn friends -listan ja alla renderöi sen uudelleen
            print(user.friends)
            return render_template('template_user.html',isLogged=True,friends=user.friends)
        else:
            flash('Give proper values to all fields')
            return render_template('template_friends.html',form=form,isLogged=True)
示例#4
0
def friends():
    form = FriendForm()
    if request.method == 'GET':
        return render_template('template_friends.html',form=form,isLogged=True)
    else:
        if form.validate_on_submit():
            print('friends from submit ok')
            temp = Friends(form.name.data,form.address.data,form.age.data,session['user_id'])
            
            # save the image if present
            if form.upload_file.data:
                filename = secure_filename(form.upload_file.data.filename)
                form.upload_file.data.save('app/static/images/' + filename)
                temp.filename = '/static/images/' + filename
            
            db.session.add(temp)
            db.session.commit()
            #2. tapa listata ystävät. Kts db_models.py
            user = Users.query.get(session['user_id'])
            print(user.friends)
            return render_template('template_user.html',isLogged=True,friends=user.friends)
        else:
            flash('Give proper values to all fields')
            return render_template('template_friends.html',form=form,isLogged=True)