Commit 2deff05a authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

astakos: Correct realname splitting

If a realname splits in more than two parts, store the whole value
as last_name. Also use the util function rather than initializing
a temporary AstakosUser, where needed.
parent 7bf3bd9e
...@@ -35,7 +35,7 @@ from django.utils.importlib import import_module ...@@ -35,7 +35,7 @@ from django.utils.importlib import import_module
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from astakos.im.models import AstakosUser from astakos.im import models
from astakos.im import functions from astakos.im import functions
from astakos.im import settings from astakos.im import settings
from astakos.im import forms from astakos.im import forms
...@@ -444,13 +444,11 @@ class InvitationsBackend(ActivationBackend): ...@@ -444,13 +444,11 @@ class InvitationsBackend(ActivationBackend):
initial_data = None initial_data = None
if request.method == 'GET': if request.method == 'GET':
if invitation: if invitation:
# create a tmp user with the invitation realname first, last = models.split_realname(invitation.realname)
# to extract first and last name
u = AstakosUser(realname=invitation.realname)
initial_data = {'email': invitation.username, initial_data = {'email': invitation.username,
'inviter': invitation.inviter.realname, 'inviter': invitation.inviter.realname,
'first_name': u.first_name, 'first_name': first,
'last_name': u.last_name, 'last_name': last,
'provider': provider} 'provider': provider}
else: else:
if provider == request.POST.get('provider', ''): if provider == request.POST.get('provider', ''):
......
...@@ -303,6 +303,14 @@ def get_resource_names(): ...@@ -303,6 +303,14 @@ def get_resource_names():
return _RESOURCE_NAMES return _RESOURCE_NAMES
def split_realname(value):
parts = value.split(' ')
if len(parts) == 2:
return parts
else:
return ('', value)
class AstakosUserManager(UserManager): class AstakosUserManager(UserManager):
def get_auth_provider_user(self, provider, **kwargs): def get_auth_provider_user(self, provider, **kwargs):
...@@ -476,12 +484,9 @@ class AstakosUser(User): ...@@ -476,12 +484,9 @@ class AstakosUser(User):
@realname.setter @realname.setter
def realname(self, value): def realname(self, value):
parts = value.split(' ') first, last = split_realname(value)
if len(parts) == 2: self.first_name = first
self.first_name = parts[0] self.last_name = last
self.last_name = parts[1]
else:
self.last_name = parts[0]
def add_permission(self, pname): def add_permission(self, pname):
if self.has_perm(pname): if self.has_perm(pname):
...@@ -1199,12 +1204,9 @@ class PendingThirdPartyUser(models.Model): ...@@ -1199,12 +1204,9 @@ class PendingThirdPartyUser(models.Model):
@realname.setter @realname.setter
def realname(self, value): def realname(self, value):
parts = value.split(' ') first, last = split_realname(value)
if len(parts) == 2: self.first_name = first
self.first_name = parts[0] self.last_name = last
self.last_name = parts[1]
else:
self.last_name = parts[0]
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.id: if not self.id:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment