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
from django.core.exceptions import ImproperlyConfigured
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 settings
from astakos.im import forms
......@@ -444,13 +444,11 @@ class InvitationsBackend(ActivationBackend):
initial_data = None
if request.method == 'GET':
if invitation:
# create a tmp user with the invitation realname
# to extract first and last name
u = AstakosUser(realname=invitation.realname)
first, last = models.split_realname(invitation.realname)
initial_data = {'email': invitation.username,
'inviter': invitation.inviter.realname,
'first_name': u.first_name,
'last_name': u.last_name,
'first_name': first,
'last_name': last,
'provider': provider}
else:
if provider == request.POST.get('provider', ''):
......
......@@ -303,6 +303,14 @@ def get_resource_names():
return _RESOURCE_NAMES
def split_realname(value):
parts = value.split(' ')
if len(parts) == 2:
return parts
else:
return ('', value)
class AstakosUserManager(UserManager):
def get_auth_provider_user(self, provider, **kwargs):
......@@ -476,12 +484,9 @@ class AstakosUser(User):
@realname.setter
def realname(self, value):
parts = value.split(' ')
if len(parts) == 2:
self.first_name = parts[0]
self.last_name = parts[1]
else:
self.last_name = parts[0]
first, last = split_realname(value)
self.first_name = first
self.last_name = last
def add_permission(self, pname):
if self.has_perm(pname):
......@@ -1199,12 +1204,9 @@ class PendingThirdPartyUser(models.Model):
@realname.setter
def realname(self, value):
parts = value.split(' ')
if len(parts) == 2:
self.first_name = parts[0]
self.last_name = parts[1]
else:
self.last_name = parts[0]
first, last = split_realname(value)
self.first_name = first
self.last_name = last
def save(self, *args, **kwargs):
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