diff options
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r-- | pyaggr3g470r/forms.py | 20 | ||||
-rw-r--r-- | pyaggr3g470r/models.py | 5 | ||||
-rw-r--r-- | pyaggr3g470r/templates/admin/create_user.html | 7 | ||||
-rw-r--r-- | pyaggr3g470r/templates/admin/dashboard.html | 8 | ||||
-rw-r--r-- | pyaggr3g470r/templates/opml.xml | 4 | ||||
-rw-r--r-- | pyaggr3g470r/templates/profile.html | 7 | ||||
-rw-r--r-- | pyaggr3g470r/templates/signup.html | 7 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 16 |
8 files changed, 26 insertions, 48 deletions
diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py index d89c3062..fe2dd0d8 100644 --- a/pyaggr3g470r/forms.py +++ b/pyaggr3g470r/forms.py @@ -36,8 +36,7 @@ from flask_wtf import RecaptchaField from pyaggr3g470r.models import User class SignupForm(Form): - firstname = TextField(lazy_gettext("First name"), [validators.Required(lazy_gettext("Please enter your first name."))]) - lastname = TextField(lazy_gettext("Last name"), [validators.Required(lazy_gettext("Please enter your last name."))]) + 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"), [validators.Required(lazy_gettext("Please enter a password.")), validators.Length(min=6, max=100)]) recaptcha = RecaptchaField() @@ -49,11 +48,8 @@ class SignupForm(Form): def validate(self): if not Form.validate(self): return False - if self.firstname.data != User.make_valid_nickname(self.firstname.data): - self.firstname.errors.append(lazy_gettext('This firstname has invalid characters. Please use letters, numbers, dots and underscores only.')) - return False - if self.lastname.data != User.make_valid_nickname(self.lastname.data): - self.lastname.errors.append(lazy_gettext('This lastname has invalid characters. Please use letters, numbers, dots and underscores only.')) + 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.')) return False return True @@ -97,8 +93,7 @@ class AddFeedForm(Form): return True class ProfileForm(Form): - firstname = TextField(lazy_gettext("First name"), [validators.Required(lazy_gettext("Please enter your first name."))]) - lastname = TextField(lazy_gettext("Last name"), [validators.Required(lazy_gettext("Please enter your last name."))]) + 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")) submit = SubmitField(lazy_gettext("Save")) @@ -109,10 +104,7 @@ class ProfileForm(Form): def validate(self): if not Form.validate(self): return False - if self.firstname.data != User.make_valid_nickname(self.firstname.data): - self.firstname.errors.append(lazy_gettext('This firstname has invalid characters. Please use letters, numbers, dots and underscores only.')) - return False - if self.lastname.data != User.make_valid_nickname(self.lastname.data): - self.lastname.errors.append(lazy_gettext('This lastname has invalid characters. Please use letters, numbers, dots and underscores only.')) + 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.')) return False return True diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py index f21ee3ec..15973d80 100644 --- a/pyaggr3g470r/models.py +++ b/pyaggr3g470r/models.py @@ -40,8 +40,7 @@ class User(db.Model, UserMixin): Represent a user. """ id = db.Column(db.Integer, primary_key = True) - firstname = db.Column(db.String()) - lastname = db.Column(db.String()) + nickname = db.Column(db.String(), unique = True) email = db.Column(db.String(254), index = True, unique = True) pwdhash = db.Column(db.String()) roles = db.relationship('Role', backref = 'user', lazy = 'dynamic') @@ -81,7 +80,7 @@ class User(db.Model, UserMixin): return self.id == other.id def __repr__(self): - return '<User %r>' % (self.firstname) + return '<User %r>' % (self.nickname) class Role(db.Model): """ diff --git a/pyaggr3g470r/templates/admin/create_user.html b/pyaggr3g470r/templates/admin/create_user.html index fcb59cd7..4e6c629f 100644 --- a/pyaggr3g470r/templates/admin/create_user.html +++ b/pyaggr3g470r/templates/admin/create_user.html @@ -9,11 +9,8 @@ <form action="" method="post" name="saveprofileform" id="profileform"> {{ form.hidden_tag() }} - {{ form.firstname.label }} - {{ form.firstname(class_="form-control") }} {% for error in form.firstname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} - - {{ form.lastname.label }} - {{ form.lastname(class_="form-control") }} {% for error in form.lastname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.nickname.label }} + {{ form.nickname(class_="form-control") }} {% for error in form.nickname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} {{ form.email.label }} {{ form.email(class_="form-control") }} {% for error in form.email.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} diff --git a/pyaggr3g470r/templates/admin/dashboard.html b/pyaggr3g470r/templates/admin/dashboard.html index 5c7fa5c1..4e60ad1d 100644 --- a/pyaggr3g470r/templates/admin/dashboard.html +++ b/pyaggr3g470r/templates/admin/dashboard.html @@ -9,18 +9,16 @@ <thead> <tr> <th>#</th> - <th>{{ _('Firstname') }}</th> - <th>{{ _('Lastname') }}</th> + <th>{{ _('Nickname') }}</th> <th>{{ _('Email') }}</th> <th>{{ _('Actions') }}</th> </tr> </thead> <tbody> - {% for user in users|sort(attribute="firstname") %} + {% for user in users|sort(attribute="nickname") %} <tr> <td>{{ loop.index }}</td> - <td><a href="/admin/user/{{ user.id }}/">{{ user.firstname }}</a></td> - <td>{{ user.lastname }}</td> + <td><a href="/admin/user/{{ user.id }}/">{{ user.nickname }}</a></td> <td>{{ user.email }}</td> <td> <a href="/admin/user/{{ user.id }}/"><i class="glyphicon glyphicon-user" title="{{ _('View this user') }}<"></i></a> diff --git a/pyaggr3g470r/templates/opml.xml b/pyaggr3g470r/templates/opml.xml index 07d2b3d9..96fe66f5 100644 --- a/pyaggr3g470r/templates/opml.xml +++ b/pyaggr3g470r/templates/opml.xml @@ -2,10 +2,10 @@ <!-- OPML generated by pyAggr3g470r on {{ now | datetime }} --> <opml version="1.1"> <head> - <title>Feeds of {{ user.firstname }}</title> + <title>Feeds of {{ user.nickname }}</title> <dateCreated>{{ now | datetime }}</dateCreated> <dateModified>{{ now | datetime }}</dateModified> - <ownerName>{{ user.firstname }} {{ user.lastname }}</ownerName> + <ownerName>{{ user.nickname }}</ownerName> <ownerEmail>{{ user.email }}</ownerEmail> </head> <body> diff --git a/pyaggr3g470r/templates/profile.html b/pyaggr3g470r/templates/profile.html index 0bad12ee..b7467329 100644 --- a/pyaggr3g470r/templates/profile.html +++ b/pyaggr3g470r/templates/profile.html @@ -5,11 +5,8 @@ <form action="" method="post" name="save"> {{ form.hidden_tag() }} - {{ form.firstname.label }} - {{ form.firstname(class_="form-control") }} {% for error in form.firstname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} - - {{ form.lastname.label }} - {{ form.lastname(class_="form-control") }} {% for error in form.lastname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.nickname.label }} + {{ form.nickname(class_="form-control") }} {% for error in form.nickname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} {{ form.email.label }} {{ form.email(class_="form-control") }} {% for error in form.email.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} diff --git a/pyaggr3g470r/templates/signup.html b/pyaggr3g470r/templates/signup.html index 9c2ad32c..6644d4f1 100644 --- a/pyaggr3g470r/templates/signup.html +++ b/pyaggr3g470r/templates/signup.html @@ -5,11 +5,8 @@ <form action="" method="post" name="save"> {{ form.hidden_tag() }} - {{ form.firstname.label }} - {{ form.firstname(class_="form-control") }} {% for error in form.firstname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} - - {{ form.lastname.label }} - {{ form.lastname(class_="form-control") }} {% for error in form.lastname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.nickname.label }} + {{ form.nickname(class_="form-control") }} {% for error in form.nickname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} {{ form.email.label }} {{ form.email(class_="form-control") }} {% for error in form.email.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 3a6cd9ad..2efa5bf2 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -173,8 +173,7 @@ def signup(): if form.validate_on_submit(): role_user = Role.query.filter(Role.name == "user").first() - user = User(firstname=form.firstname.data, - lastname=form.lastname.data, + user = User(nickname=form.nickname.data, email=form.email.data, pwdhash=generate_password_hash(form.password.data)) user.roles = [role_user] @@ -633,7 +632,7 @@ def profile(): if form.password.data != "": user.set_password(form.password.data) db.session.commit() - flash(gettext('User') + ' ' + user.firstname + ' ' + gettext('successfully updated.'), 'success') + flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully updated.'), 'success') return redirect(url_for('profile')) else: return render_template('profile.html', form=form) @@ -693,17 +692,16 @@ def create_user(user_id=None): user.set_password(form.password.data) user.roles = [role_user] db.session.commit() - flash(gettext('User') + ' ' + user.firstname + ' ' + gettext('successfully updated.'), 'success') + flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully updated.'), 'success') else: # Create a new user - user = User(firstname=form.firstname.data, - lastname=form.lastname.data, + user = User(nickname=form.nickname.data, email=form.email.data, pwdhash=generate_password_hash(form.password.data)) user.roles.extend([role_user]) db.session.add(user) db.session.commit() - flash(gettext('User') + ' ' + user.firstname + ' ' + gettext('successfully created.'), 'success') + flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully created.'), 'success') return redirect("/admin/edit_user/"+str(user.id)+"/") else: return render_template('profile.html', form=form) @@ -712,7 +710,7 @@ def create_user(user_id=None): if user_id is not None: user = User.query.filter(User.id == user_id).first() form = ProfileForm(obj=user) - message = gettext('Edit the user') + ' <i>' + user.firstname + '</i>' + message = gettext('Edit the user') + ' <i>' + user.nickname + '</i>' else: form = ProfileForm() message = gettext('Add a new user') @@ -743,7 +741,7 @@ def delete_user(user_id=None): if user is not None: db.session.delete(user) db.session.commit() - flash(gettext('User') + ' ' + user.firstname + ' ' + gettext('successfully deleted.'), 'success') + flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully deleted.'), 'success') else: flash(gettext('This user does not exist.'), 'danger') return redirect(redirect_url()) |