From 828b597253fa7a76fd30795b7bed71919ada70a1 Mon Sep 17 00:00:00 2001 From: jieun Date: Tue, 11 Apr 2017 13:02:12 -0400 Subject: [PATCH] add option for location --- app/forms.py | 1 + app/models.py | 1 + app/templates/edit.html | 8 ++++++++ app/templates/user.html | 1 + app/views.py | 2 ++ 5 files changed, 13 insertions(+) diff --git a/app/forms.py b/app/forms.py index e1c7f59..0f16a31 100644 --- a/app/forms.py +++ b/app/forms.py @@ -13,6 +13,7 @@ class LoginForm(Form): class EditForm(Form): nickname = StringField('nickname', validators=[DataRequired()]) about_me = TextAreaField('about_me', validators=[Length(min=0, max=140)]) + location = TextAreaField('location', validators=[Length(min=0, max=100)]) def __init__(self, original_nickname, *args, **kwargs): Form.__init__(self, *args, **kwargs) diff --git a/app/models.py b/app/models.py index 263c541..36fda54 100644 --- a/app/models.py +++ b/app/models.py @@ -25,6 +25,7 @@ class User(db.Model): nickname = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) posts = db.relationship('Post', backref='author', lazy='dynamic') + location = db.Column(db.String(140)) about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime) followed = db.relationship('User', diff --git a/app/templates/edit.html b/app/templates/edit.html index ac218d0..5bb1612 100644 --- a/app/templates/edit.html +++ b/app/templates/edit.html @@ -16,6 +16,14 @@ {% endfor %} +
+ +
+ {{ form.location(cols=64, rows=4, class="span4") }} + {% for error in form.location.errors %} + [{{ error }}]
+ {% endfor %} +
diff --git a/app/templates/user.html b/app/templates/user.html index eebd6bb..3bf85be 100644 --- a/app/templates/user.html +++ b/app/templates/user.html @@ -8,6 +8,7 @@

{{ user.nickname }}

+ {% if user.location %}

{{ user.location }}

{% endif %} {% if user.about_me %}

{{ user.about_me }}

{% endif %} {% if user.last_seen %}

{{ _('Last login:') }} {{ momentjs(user.last_seen).calendar() }}

diff --git a/app/views.py b/app/views.py index d5987ab..acb770a 100644 --- a/app/views.py +++ b/app/views.py @@ -156,6 +156,7 @@ def edit(): form = EditForm(g.user.nickname) if form.validate_on_submit(): g.user.nickname = form.nickname.data + g.user.location = form.location.data g.user.about_me = form.about_me.data db.session.add(g.user) db.session.commit() @@ -163,6 +164,7 @@ def edit(): return redirect(url_for('edit')) elif request.method != "POST": form.nickname.data = g.user.nickname + form.location.data = g.user.location form.about_me.data = g.user.about_me return render_template('edit.html', form=form)