[chronojump-server] Added table Language User now is the one to be used to decided the language of the server The server
- From: Marcos Venteo Garcia <mventeo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Added table Language User now is the one to be used to decided the language of the server The server
- Date: Wed, 21 Mar 2018 18:59:27 +0000 (UTC)
commit ae74c0047125e2c2d8104baca0f48aefa851f175
Author: Marcos Venteo <mventeo gmail com>
Date: Wed Mar 21 19:59:14 2018 +0100
Added table Language
User now is the one to be used to decided the language of the server
The server reads the value from User table when requesting language code
chronojumpserver/__init__.py | 6 +++---
chronojumpserver/models.py | 13 +++++++++----
2 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/chronojumpserver/__init__.py b/chronojumpserver/__init__.py
index c5ec357..7424f46 100755
--- a/chronojumpserver/__init__.py
+++ b/chronojumpserver/__init__.py
@@ -98,7 +98,7 @@ def shutdown_session(exception=None):
from chronojumpserver.database import init_db
init_db()
-from chronojumpserver.models import User, Coach
+from chronojumpserver.models import User, Language
# To retrieve the user from session
@login_manager.user_loader
def load_user(user_id):
@@ -108,8 +108,8 @@ def load_user(user_id):
def get_locale():
if current_user.is_authenticated:
# Get the coach lang
- coach = Coach.query.filter(Coach.user_id == current_user.id).first()
- return coach.lang
+ language = Language.query.filter(Language.id == current_user.language_id).first()
+ return language.code
else:
#return best accepted by browser
return request.accept_languages.best_match(['ca','es','en', 'fr'])
diff --git a/chronojumpserver/models.py b/chronojumpserver/models.py
index e428af4..50b48e8 100755
--- a/chronojumpserver/models.py
+++ b/chronojumpserver/models.py
@@ -23,7 +23,10 @@ class HelperMixin(object):
return o
-
+class Language(HelperMixin, Base):
+ __tablename__ = 'language'
+ code = Column(String(5), unique = True)
+ name = Column(String(25))
class Organization(HelperMixin, Base):
__tablename__ = 'organization'
@@ -57,7 +60,6 @@ class Coach(HelperMixin, Base):
user_id = Column(Integer, nullable=False)
name = Column(String(50), unique=True)
details = Column(String(100), nullable=False)
- lang = Column(String(5), default='ca')
class GroupCoach(HelperMixin, Base):
@@ -527,11 +529,13 @@ class User(UserMixin, Base):
username = Column('username', String(50))
password = Column('password', String(50))
user_type = Column('user_type', String(50))
+ language_id = Column('language_id', ForeignKey('language.id'))
- def __init__(self, username, password, user_type='default'):
+ def __init__(self, username, password, language_id, user_type='default'):
self.username = username
self.password = password
self.user_type = user_type
+ self.language_id = language_id
@property
def serialize(self):
@@ -540,7 +544,8 @@ class User(UserMixin, Base):
'id': self.id,
'username': self.username,
'password': self.password,
- 'user_type': self.user_type
+ 'user_type': self.user_type,
+ 'language_id' : self.language_id
}
@classmethod
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]