diff options
-rw-r--r-- | migrations/versions/fa10b0bdd045_add_bio_column_to_user_table.py | 25 | ||||
-rw-r--r-- | src/web/forms.py | 1 | ||||
-rw-r--r-- | src/web/models/user.py | 8 | ||||
-rw-r--r-- | src/web/templates/profile.html | 3 | ||||
-rw-r--r-- | src/web/templates/profile_public.html | 26 | ||||
-rw-r--r-- | src/web/views/user.py | 11 |
6 files changed, 66 insertions, 8 deletions
diff --git a/migrations/versions/fa10b0bdd045_add_bio_column_to_user_table.py b/migrations/versions/fa10b0bdd045_add_bio_column_to_user_table.py new file mode 100644 index 00000000..2d839626 --- /dev/null +++ b/migrations/versions/fa10b0bdd045_add_bio_column_to_user_table.py @@ -0,0 +1,25 @@ +"""add bio column to user table + +Revision ID: fa10b0bdd045 +Revises: 8bf5694c0b9e +Create Date: 2016-10-07 10:43:04.428178 + +""" + +# revision identifiers, used by Alembic. +revision = 'fa10b0bdd045' +down_revision = '8bf5694c0b9e' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('user', sa.Column('bio', + sa.String(5000), default="")) + + +def downgrade(): + op.drop_column('user', 'bio') diff --git a/src/web/forms.py b/src/web/forms.py index d63394f7..a604897e 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -160,6 +160,7 @@ class ProfileForm(Form): password_conf = PasswordField(lazy_gettext("Password Confirmation")) automatic_crawling = BooleanField(lazy_gettext("Automatic crawling"), default=True) + bio = TextAreaField(lazy_gettext("Bio")) webpage = URLField(lazy_gettext("Webpage")) twitter = URLField(lazy_gettext("Twitter")) is_public_profile = BooleanField(lazy_gettext("Public profile"), diff --git a/src/web/models/user.py b/src/web/models/user.py index 2b069728..67181560 100644 --- a/src/web/models/user.py +++ b/src/web/models/user.py @@ -32,6 +32,7 @@ import hashlib from datetime import datetime from werkzeug import check_password_hash from flask_login import UserMixin +from sqlalchemy.orm import validates from bootstrap import db from web.models.right_mixin import RightMixin @@ -51,6 +52,7 @@ class User(db.Model, UserMixin, RightMixin): automatic_crawling = db.Column(db.Boolean(), default=True) is_public_profile = db.Column(db.Boolean(), default=False) + bio = db.Column(db.String(5000), default="") webpage = db.Column(db.String(), default="") twitter = db.Column(db.String(), default="") @@ -82,6 +84,12 @@ class User(db.Model, UserMixin, RightMixin): def make_valid_nickname(nickname): return re.sub('[^a-zA-Z0-9_\.]', '', nickname) + @validates('bio') + def validates_bio(self, key, value): + assert len(value) <= 5000, \ + AssertionError("maximum length for bio: 5000") + return value.strip() + def get_id(self): """ Return the id of the user. diff --git a/src/web/templates/profile.html b/src/web/templates/profile.html index 39834ca5..58d907ef 100644 --- a/src/web/templates/profile.html +++ b/src/web/templates/profile.html @@ -33,6 +33,9 @@ </div> <div class="col-md-6"> + {{ form.bio.label }} + {{ form.bio(class_="form-control") }} {% for error in form.bio.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.webpage.label }} {{ form.webpage(class_="form-control") }} {% for error in form.webpage.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} diff --git a/src/web/templates/profile_public.html b/src/web/templates/profile_public.html index aed5bfcc..5bd002e0 100644 --- a/src/web/templates/profile_public.html +++ b/src/web/templates/profile_public.html @@ -4,18 +4,34 @@ <h1>{{ user.nickname }}</h1> <div class="row"> <div class="col-md-12"> - <p>{{ _('Member since') }}: {{ user.date_created | datetime }}</p> - <p>{{ _('Last seen') }}: {{ user.last_seen | datetime }}</p> + <p> + <span class="glyphicon glyphicon-time" aria-hidden="true"></span> + {{ _('Member since') }}: {{ user.date_created | datetime }} + </p> + <p> + <span class="glyphicon glyphicon-time" aria-hidden="true"></span> + {{ _('Last seen') }}: {{ user.last_seen | datetime }} + </p> {% if user.webpage %} - <p>{{ _('Webpage') }}: <a href="{{ user.webpage | safe }}">{{ user.webpage | safe }}</a></p> + <p> + <span class="glyphicon glyphicon-link" aria-hidden="true"></span> + {{ _('Webpage') }}: <a href="{{ user.webpage | safe }}">{{ user.webpage | safe }}</a> + </p> {% endif %} {% if user.twitter %} - <p>{{ _('Twitter') }}: <a href="{{ user.twitter | safe }}">{{ user.twitter | safe }}</a></p> + <p> + <span class="glyphicon glyphicon-link" aria-hidden="true"></span> + {{ _('Twitter') }}: <a href="{{ user.twitter | safe }}">{{ user.twitter | safe }}</a> + </p> {% endif %} </div> </div> - <div class="row"> + <div class="col-md-5"> + {% if user.bio %} + <p align="justify">{{ user.bio }}</p> + {% endif %} + </div> <div class="col-md-6 pull-right"> <div>{{ tag_cloud|safe }}</div> </div> diff --git a/src/web/views/user.py b/src/web/views/user.py index 26d65de3..3e203b3e 100644 --- a/src/web/views/user.py +++ b/src/web/views/user.py @@ -103,16 +103,21 @@ def profile(): if request.method == 'POST': if form.validate(): - user_contr.update({'id': current_user.id}, + try: + user_contr.update({'id': current_user.id}, {'nickname': form.nickname.data, 'email': form.email.data, 'password': form.password.data, 'automatic_crawling': form.automatic_crawling.data, 'is_public_profile': form.is_public_profile.data, + 'bio': form.bio.data, 'webpage': form.webpage.data, 'twitter': form.twitter.data}) - - flash(gettext('User %(nick)s successfully updated', + except Exception as error: + flash(gettext('Problem while updating your profile: ' + '%(error)s', error=error), 'danger') + else: + flash(gettext('User %(nick)s successfully updated', nick=user.nickname), 'success') return redirect(url_for('user.profile')) else: |