diff --git a/.gitignore b/.gitignore index f8749fe..94c30c9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ app.db search.db flask +*.mo diff --git a/app/__init__.py b/app/__init__.py index 57bb3d2..99ff54e 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -4,6 +4,7 @@ from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.login import LoginManager from flask.ext.openid import OpenID from flask.ext.mail import Mail +from flask.ext.babel import Babel, lazy_gettext from config import basedir, ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD from momentjs import momentjs @@ -13,8 +14,10 @@ db = SQLAlchemy(app) lm = LoginManager() lm.init_app(app) lm.login_view = 'login' +lm.login_message = lazy_gettext('Please log in to access this page.') oid = OpenID(app, os.path.join(basedir, 'tmp')) mail = Mail(app) +babel = Babel(app) if not app.debug: import logging diff --git a/app/forms.py b/app/forms.py index a39fe06..83233a0 100644 --- a/app/forms.py +++ b/app/forms.py @@ -1,5 +1,6 @@ from flask.ext.wtf import Form, TextField, BooleanField, TextAreaField from flask.ext.wtf import Required, Length +from flask.ext.babel import gettext from app.models import User class LoginForm(Form): @@ -19,9 +20,12 @@ class EditForm(Form): return False if self.nickname.data == self.original_nickname: return True + if self.nickname.data != User.make_valid_nickname(self.nickname.data): + self.nickname.errors.append(gettext('This nickname has invalid characters. Please use letters, numbers, dots and underscores only.')) + return False user = User.query.filter_by(nickname = self.nickname.data).first() if user != None: - self.nickname.errors.append('This nickname is already in use. Please choose another one.') + self.nickname.errors.append(gettext('This nickname is already in use. Please choose another one.')) return False return True diff --git a/app/models.py b/app/models.py index 3b1fd48..63c35be 100644 --- a/app/models.py +++ b/app/models.py @@ -2,6 +2,7 @@ from hashlib import md5 from app import db from app import app import flask.ext.whooshalchemy as whooshalchemy +import re ROLE_USER = 0 ROLE_ADMIN = 1 @@ -26,6 +27,10 @@ class User(db.Model): backref = db.backref('followers', lazy = 'dynamic'), lazy = 'dynamic') + @staticmethod + def make_valid_nickname(nickname): + return re.sub('[^a-zA-Z0-9_\.]', '', nickname) + @staticmethod def make_unique_nickname(nickname): if User.query.filter_by(nickname = nickname).first() == None: diff --git a/app/static/js/moment-es.min.js b/app/static/js/moment-es.min.js new file mode 100755 index 0000000..546e172 --- /dev/null +++ b/app/static/js/moment-es.min.js @@ -0,0 +1,4 @@ +// moment.js language configuration +// language : spanish (es) +// author : Julio Napurí : https://github.com/julionc +(function(){function e(e){e.lang("es",{months:"enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre".split("_"),monthsShort:"ene._feb._mar._abr._may._jun._jul._ago._sep._oct._nov._dic.".split("_"),weekdays:"domingo_lunes_martes_mi\u00e9rcoles_jueves_viernes_s\u00e1bado".split("_"),weekdaysShort:"dom._lun._mar._mi\u00e9._jue._vie._s\u00e1b.".split("_"),weekdaysMin:"Do_Lu_Ma_Mi_Ju_Vi_S\u00e1".split("_"),longDateFormat:{LT:"H:mm",L:"DD/MM/YYYY",LL:"D \\de MMMM \\de YYYY",LLL:"D \\de MMMM \\de YYYY LT",LLLL:"dddd, D \\de MMMM \\de YYYY LT"},calendar:{sameDay:function(){return"[hoy a la"+(this.hours()!==1?"s":"")+"] LT"},nextDay:function(){return"[ma\u00f1ana a la"+(this.hours()!==1?"s":"")+"] LT"},nextWeek:function(){return"dddd [a la"+(this.hours()!==1?"s":"")+"] LT"},lastDay:function(){return"[ayer a la"+(this.hours()!==1?"s":"")+"] LT"},lastWeek:function(){return"[el] dddd [pasado a la"+(this.hours()!==1?"s":"")+"] LT"},sameElse:"L"},relativeTime:{future:"en %s",past:"hace %s",s:"unos segundos",m:"un minuto",mm:"%d minutos",h:"una hora",hh:"%d horas",d:"un d\u00eda",dd:"%d d\u00edas",M:"un mes",MM:"%d meses",y:"un a\u00f1o",yy:"%d a\u00f1os"},ordinal:function(e){return"\u00ba"},week:{dow:1,doy:4}})}typeof define=="function"&&define.amd&&define(["moment"],e),typeof window!="undefined"&&window.moment&&e(window.moment)})(); \ No newline at end of file diff --git a/app/templates/404.html b/app/templates/404.html index 203c070..6463c28 100644 --- a/app/templates/404.html +++ b/app/templates/404.html @@ -2,6 +2,6 @@ {% extends "base.html" %} {% block content %} -
The administrator has been notified. Sorry for the inconvenience!
- +{{ _('The administrator has been notified. Sorry for the inconvenience!') }}
+ {% endblock %} \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index a8fd68d..92497a3 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -11,6 +11,9 @@ + {% if g.locale != 'en' %} + + {% endif %} @@ -24,15 +27,15 @@ microblog @@ -45,3 +48,4 @@