diff options
Diffstat (limited to 'src')
-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 |
5 files changed, 41 insertions, 8 deletions
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: |