From 66be71f94f09824840ad7317f84e72b20da3099f Mon Sep 17 00:00:00 2001 From: aboud20-meet Date: Thu, 26 Jul 2018 16:12:30 +0300 Subject: [PATCH] MVP --- project/models.py | 22 +++++++------- project/templates/apply.html | 9 ++++-- project/templates/browse.html | 10 +++--- project/templates/index.html | 2 +- project/templates/journey.html | 11 ++++--- project/templates/journey_table_test.html | 19 ------------ project/templates/layout.html | 2 ++ project/users.py | 7 +++-- project/views.py | 37 ++++++++++++++--------- 9 files changed, 59 insertions(+), 60 deletions(-) delete mode 100644 project/templates/journey_table_test.html diff --git a/project/models.py b/project/models.py index 7b6c32d..f185efb 100644 --- a/project/models.py +++ b/project/models.py @@ -64,17 +64,17 @@ class Journey(UserMixin, db.Model): price = db.Column(db.String, nullable=False) picture = db.Column(db.String, nullable=False) - def __init__(self, creator_id='', title='', description='', location='', duration='', category='', requirements='', people_range='' ): - self.creator_id = creator_id - self.title = title - self.description = description - self.location = location - self.duration = duration - self.category = category - self.requirements = requirements - self.people_range = people_range - self.picture = picture - self.price = price + def __init__(self, creator_id='', title='', description='', location='', duration='', category='', requirements='', people_range='', picture='', price=''): + self.creator_id = creator_id + self.title = title + self.description = description + self.location = location + self.duration = duration + self.category = category + self.requirements = requirements + self.people_range = people_range + self.picture = picture + self.price = price def __repr__(self): diff --git a/project/templates/apply.html b/project/templates/apply.html index a44fe9f..ab851cc 100644 --- a/project/templates/apply.html +++ b/project/templates/apply.html @@ -1,3 +1,6 @@ +{% extends "layout.html" %} +{% block content %} + @@ -5,7 +8,8 @@

Become A StoryTeller

- Hi____, + + Hi {{ current_user.name }},


Becoming a storyteller means you will get to share your ambitious insipring story of your life. you will be free to take people on a journey in the places you grew in or places you would like.

@@ -68,4 +72,5 @@

add image url

- \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/project/templates/browse.html b/project/templates/browse.html index e881c60..d1322c9 100644 --- a/project/templates/browse.html +++ b/project/templates/browse.html @@ -3,15 +3,15 @@ -
- {% for journey in journeys %} + {% for journey in all_journeys %}
- -
{{ journey.start_location }}

-

{{ journey.title }}


+ +
{{ journey.title }}

+

{{ journey.location }}


{{ journey.price }}


{{ journey.category }}


+ View Details
{% endfor %} diff --git a/project/templates/index.html b/project/templates/index.html index 0eba06c..6ae1cf7 100644 --- a/project/templates/index.html +++ b/project/templates/index.html @@ -1,4 +1,4 @@ {% extends "layout.html" %} {% block content %} -

Hello world!

+

ROOTS

{% endblock %} diff --git a/project/templates/journey.html b/project/templates/journey.html index afeddcf..cacc38b 100644 --- a/project/templates/journey.html +++ b/project/templates/journey.html @@ -1,16 +1,17 @@ + + {% extends "layout.html" %} {% block content %} -
+

{{journey.title}}

-

start location : {{journey.start_location}}

-

storyteller : {{creator.name}}

-

end location : {{journey.end_location}}

+

storyteller : {{ creator.name }}

+

location : {{journey.location}}

description : {{journey.description}}

duration : {{journey.duration}}

price : {{journey.price}}

category : {{journey.category}}

-

requirments : {{journey.requirments}}

+

requirements : {{journey.requirements}}

people range : {{journey.people_range}}

diff --git a/project/templates/journey_table_test.html b/project/templates/journey_table_test.html deleted file mode 100644 index 2a6e3e0..0000000 --- a/project/templates/journey_table_test.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - TEST - - - -Title: {{ journey.title }} -Description: {{ journey.description }} -Location: -Duration: -Category: -Requirements -People range: -Price: -Picture: - - - \ No newline at end of file diff --git a/project/templates/layout.html b/project/templates/layout.html index 25f5f3e..c0d0993 100644 --- a/project/templates/layout.html +++ b/project/templates/layout.html @@ -10,6 +10,8 @@ + + current user: {{ current_user.name }} {% block content %} {% endblock %} diff --git a/project/users.py b/project/users.py index a8f1b1e..ce86ea1 100644 --- a/project/users.py +++ b/project/users.py @@ -20,7 +20,7 @@ users_bp = Blueprint('users', __name__) -current_user = 'Not Logged In' +# current_user = 'Not Logged In' @users_bp.route('/register', methods=['GET', 'POST']) def register(): @@ -61,9 +61,12 @@ def login(): if user is None or not user.check_password(password): return Response("

Incorrect email or password

") login_user(user, remember=True) + # global current_user + # current_user = 'this' next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': - next_page = url_for('private_route') + #return render_template('browse.html', current_user=user) + next_page = url_for('browse') return redirect(next_page) else: diff --git a/project/views.py b/project/views.py index 6169e9d..1b9d3ac 100644 --- a/project/views.py +++ b/project/views.py @@ -18,11 +18,13 @@ def private_route(): @app.route('/apply', methods=['GET', 'POST']) @login_required def apply(): + # global current_user + # print(current_user) + user_id = session['user_id'] + user = User.query.filter_by(id=user_id).first() + print(user.name) if request.method=='POST': user_info = User.query.filter_by(id=request.form.get('user_id')).first() - #print(user_info) - #print(request) - #print(user_info.one()) user_info.country = request.form.get('country') user_info.profession = request.form.get('profession') user_info.birthday = request.form.get('birthday') @@ -30,10 +32,9 @@ def apply(): user_info.number = request.form.get('number') db.session.add(user_info) db.session.commit() -############################################### CONNECT THIS TO CURRENT USER ######################################################## - + ################# JOURNEY TABLE ################### new_journey = Journey() - #new_journey.creator_id = current_user.id + new_journey.creator_id = request.form.get('user_id') new_journey.title = request.form.get('title') new_journey.description = request.form.get('description') new_journey.location = request.form.get('location') @@ -46,30 +47,36 @@ def apply(): print(new_journey.description) db.session.add(new_journey) db.session.commit() - return render_template('journey_table_test.html', journey=new_journey) + return render_template('journey.html', journey=new_journey, current_user=user) else: - return render_template('apply.html') + return render_template('apply.html', current_user=user) @app.route('/journeys/') def display_journey(journey_id): journey = Journey.query.filter_by(id=journey_id).first() - creator = User.query.filter_by( id=journey.creator_id).first() + creator = User.query.filter_by(id=journey.creator_id).first() return render_template('journey.html', journey=journey, creator= creator) @app.route('/profile/') def profile(user_id): user=User.query.filter_by (id=user_id).first() is_user=False - # if user_email==current_user.email: - # is_user=True - return render_template('profile.html',user=user, is_user=is_user) + user_id = session['user_id'] + current_user = User.query.filter_by(id=user_id).first() + if user.id==current_user.id: + is_user=True + return render_template('profile.html',user=user, is_user=is_user, current_user=current_user) @app.route('/browse') -def block_journey(): - all_journeys = db.session.query(Journey).all() - return render_template('browse.html', journey=all_journeys) +def browse(): + user_id = session['user_id'] + current_user = User.query.filter_by(id=user_id).first() + # WHAT ZAIN DID ===> all_journeys = db.session.query(Journey).all() + all_journeys = Journey.query.all() + return render_template('browse.html', all_journeys=all_journeys, current_user=current_user) # we need to now how to filter + if __name__ == "__main__": app.run()