diff options
-rw-r--r-- | pyaggr3g470r/forms.py | 47 | ||||
-rw-r--r-- | pyaggr3g470r/templates/admin/create_user.html | 3 | ||||
-rw-r--r-- | pyaggr3g470r/templates/layout.html | 13 | ||||
-rw-r--r-- | pyaggr3g470r/templates/management.html | 15 | ||||
-rw-r--r-- | pyaggr3g470r/templates/profile.html | 16 | ||||
-rw-r--r-- | pyaggr3g470r/views/views.py | 14 |
6 files changed, 75 insertions, 33 deletions
diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py index fb4a829c..080e9066 100644 --- a/pyaggr3g470r/forms.py +++ b/pyaggr3g470r/forms.py @@ -37,6 +37,9 @@ from flask_wtf import RecaptchaField from pyaggr3g470r.models import User class SignupForm(Form): + """ + Sign up form (registration to pyAggr3g470r). + """ nickname = TextField(lazy_gettext("Nickname"), [validators.Required(lazy_gettext("Please enter your nickname."))]) email = EmailField(lazy_gettext("Email"), @@ -59,7 +62,7 @@ class SignupForm(Form): class SigninForm(Form): """ - Sign in form. + Sign in form (connection to pyAggr3g470r). """ email = EmailField("Email", [validators.Length(min=6, max=35), validators.Required(lazy_gettext("Please enter your email address."))]) @@ -85,20 +88,33 @@ class SigninForm(Form): return False -class AddFeedForm(Form): - title = TextField(lazy_gettext("Title"), [validators.Optional()]) - link = TextField(lazy_gettext("Feed link")) - site_link = TextField(lazy_gettext("Site link"), [validators.Optional()]) - enabled = BooleanField(lazy_gettext("Check for updates"), default=True) +class UserForm(Form): + """ + Create or edit a user (for the administrator). + """ + nickname = TextField(lazy_gettext("Nickname"), + [validators.Required(lazy_gettext("Please enter your nickname."))]) + email = EmailField(lazy_gettext("Email"), + [validators.Length(min=6, max=35), + validators.Required(lazy_gettext("Please enter your email."))]) + password = PasswordField(lazy_gettext("Password")) + refresh_rate = IntegerField(lazy_gettext("Feeds refresh frequency " + "(in minutes)"), + default=60) submit = SubmitField(lazy_gettext("Save")) def validate(self): - if not super(AddFeedForm, self).validate(): - return False - return True + validated = super(UserForm, self).validate() + if self.nickname.data != User.make_valid_nickname(self.nickname.data): + self.nickname.errors.append(lazy_gettext('This nickname has invalid characters. Please use letters, numbers, dots and underscores only.')) + validated = False + return validated class ProfileForm(Form): + """ + Edit user information. + """ nickname = TextField(lazy_gettext("Nickname"), [validators.Required(lazy_gettext("Please enter your nickname."))]) email = EmailField(lazy_gettext("Email"), @@ -126,6 +142,19 @@ class ProfileForm(Form): return validated +class AddFeedForm(Form): + title = TextField(lazy_gettext("Title"), [validators.Optional()]) + link = TextField(lazy_gettext("Feed link")) + site_link = TextField(lazy_gettext("Site link"), [validators.Optional()]) + enabled = BooleanField(lazy_gettext("Check for updates"), default=True) + submit = SubmitField(lazy_gettext("Save")) + + def validate(self): + if not super(AddFeedForm, self).validate(): + return False + return True + + class InformationMessageForm(Form): subject = TextField(lazy_gettext("Subject"), [validators.Required(lazy_gettext("Please enter a subject."))]) diff --git a/pyaggr3g470r/templates/admin/create_user.html b/pyaggr3g470r/templates/admin/create_user.html index 1d6d6c11..64387dce 100644 --- a/pyaggr3g470r/templates/admin/create_user.html +++ b/pyaggr3g470r/templates/admin/create_user.html @@ -18,6 +18,9 @@ {{ form.password.label }} {{ form.password(class_="form-control") }} {% for error in form.password.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.refresh_rate.label }} + {{ form.refresh_rate(class_="form-control") }} {% for error in form.refresh_rate.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + <br /> {{ form.submit(class_="btn btn-default") }} </form> diff --git a/pyaggr3g470r/templates/layout.html b/pyaggr3g470r/templates/layout.html index 94d3fdc6..e3d3be38 100644 --- a/pyaggr3g470r/templates/layout.html +++ b/pyaggr3g470r/templates/layout.html @@ -79,16 +79,21 @@ </ul> </li> <li class="dropdown"> - <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ _('Tools') }} <b class="caret"></b></a> + <a href="#" class="dropdown-toggle" data-toggle="dropdown"> + <div><span class="glyphicon glyphicon-user"></span> <b class="caret"></b></div> + </a> <ul class="dropdown-menu"> - <li><a accesskey="m" href="{{ url_for("management") }}"><span class="glyphicon glyphicon-cog"></span> {{ _('Management') }}</a></li> + <li><a href="{{ url_for("profile") }}"><span class="glyphicon glyphicon-user"></span> {{ _('Profile') }}</a></li> + <li><a href="{{ url_for("management") }}"><span class="glyphicon glyphicon-cog"></span> {{ _('Your data') }}</a></li> {% if g.user.is_admin() %} + <li role="presentation" class="divider"></li> <li><a href="{{ url_for("dashboard") }}"><span class="glyphicon glyphicon-dashboard"></span> {{ _('Dashboard') }}</a></li> + <li role="presentation" class="divider"></li> {% endif %} - <li><a href="{{ url_for("about") }}"><span class="glyphicon glyphicon-question-sign"></span> {{ _('About') }}</a></li> + <li><a href="{{ url_for("logout") }}"><span class="glyphicon glyphicon-log-out"></span> {{ _('Logout') }}</a></li> </ul> </li> - <li><a href="{{ url_for("logout") }}"><span class="glyphicon glyphicon-log-out"></span> {{ _('Logout') }}</a></li> + {% if not on_heroku %} <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> diff --git a/pyaggr3g470r/templates/management.html b/pyaggr3g470r/templates/management.html index 1f8b096f..998334a3 100644 --- a/pyaggr3g470r/templates/management.html +++ b/pyaggr3g470r/templates/management.html @@ -11,21 +11,6 @@ <a href="/expire_articles?weeks=10" class="btn btn-default" onclick="return confirm('{{ _('You are going to delete old articles.') }}');">{{ _('Delete articles older than 10 weeks') }}</a> </div> <div class="well"> - <h1>{{ _('Your Profile') }}</h1> - <div class="row"> - <div class="col-md-6"> - <p>{{ _('Update your') }} <a href="/profile">{{ _('profile') }}</a>.</p> - <p>{{ _('Member since') }} {{ user.date_created | datetime }}.</p> - <p>{{ _('Last seen:') }} {{ user.last_seen | datetime }}.</p> - </div> - </div> - <div class="row"> - <div class="col-md-12"> - <a href="/delete_account" class="btn btn-default" onclick="return confirm('{{ _('You are going to delete your account.') }}');">{{ _('Delete your account') }}</a> - </div> - </div> - </div> - <div class="well"> <h1 id="import">{{ _('OPML import/export') }}</h1> <form action="" method="post" id="formImportOPML" enctype="multipart/form-data"> <span class="btn btn-default btn-file">{{ _('Batch import feeds from OPML') }} (<span class="text-info">*.xml {{ _('or') }} *.opml</span>)<input type="file" name="opmlfile" /></span> diff --git a/pyaggr3g470r/templates/profile.html b/pyaggr3g470r/templates/profile.html index 971c4e64..acd593b2 100644 --- a/pyaggr3g470r/templates/profile.html +++ b/pyaggr3g470r/templates/profile.html @@ -2,6 +2,20 @@ {% block content %} <div class="container"> <div class="well"> + <h1>{{ _('Your Profile') }}</h1> + <div class="row"> + <div class="col-md-6"> + <p>{{ _('Member since') }} {{ user.date_created | datetime }}.</p> + <p>{{ _('Last seen:') }} {{ user.last_seen | datetime }}.</p> + </div> + </div> + <div class="row"> + <div class="col-md-12"> + <a href="/delete_account" class="btn btn-default" onclick="return confirm('{{ _('You are going to delete your account.') }}');">{{ _('Delete your account') }}</a> + </div> + </div> + </div> + <div class="well"> <h2>Edit your profile</h2> <form action="" method="post" name="save"> {{ form.hidden_tag() }} @@ -14,8 +28,10 @@ {{ form.password.label }} {{ form.password(class_="form-control") }} {% for error in form.password.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.password_conf.label }} {{ form.password_conf(class_="form-control") }} {% for error in form.password_conf.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.refresh_rate.label }} {{ form.refresh_rate(class_="form-control") }} {% for error in form.refresh_rate.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} <br /> diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index b71fcbcc..577ae59d 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -49,8 +49,9 @@ import conf from pyaggr3g470r import utils, notifications, export from pyaggr3g470r.models import User, Feed, Article, Role from pyaggr3g470r.decorators import feed_access_required -from pyaggr3g470r.forms import SignupForm, SigninForm, AddFeedForm, \ - ProfileForm, InformationMessageForm, RecoverPasswordForm +from pyaggr3g470r.forms import SignupForm, SigninForm, \ + ProfileForm, UserForm, RecoverPasswordForm, \ + AddFeedForm, InformationMessageForm from pyaggr3g470r.controllers import UserController, FeedController, \ ArticleController if not conf.ON_HEROKU: @@ -685,10 +686,11 @@ def create_user(user_id=None): """ Create or edit a user. """ - form = ProfileForm() + form = UserForm() if request.method == 'POST': if form.validate(): + print("Form validated...") role_user = Role.query.filter(Role.name == "user").first() if user_id is not None: # Edit a user @@ -700,6 +702,7 @@ def create_user(user_id=None): flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully updated.'), 'success') else: # Create a new user + print("A new user...") user = User(nickname=form.nickname.data, email=form.email.data, pwdhash=generate_password_hash(form.password.data)) @@ -710,15 +713,16 @@ def create_user(user_id=None): flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully created.'), 'success') return redirect("/admin/edit_user/"+str(user.id)) else: + print("Problem with the form") return redirect(url_for('create_user')) if request.method == 'GET': if user_id is not None: user = User.query.filter(User.id == user_id).first() - form = ProfileForm(obj=user) + form = UserForm(obj=user) message = gettext('Edit the user') + ' <i>' + user.nickname + '</i>' else: - form = ProfileForm() + form = UserForm() message = gettext('Add a new user') return render_template('/admin/create_user.html', form=form, message=message) |