#NEWLINE# def from_csv( self , user , row , crypt_password = True ) : #NEWLINE# #INDENT# 'Create a new account from a CSV file entry.\n\n        The expected order is the following::\n\n        "account", loginname, password, first name, last name, enabled, group\n\n        Additional fields can be added using the *AccountImported* event.\n\n        :param user: a ``core.User`` instance\n        :param row: a list containing the expected information\n        :param crypt_password:\n        ' #NEWLINE# from modoboa.lib.permissions import get_account_roles #NEWLINE# if ( len ( row ) < 7 ) : #NEWLINE# #INDENT# raise BadRequest ( _ ( 'Invalid line' ) ) #NEWLINE# #UNINDENT# desired_role = row [ 6 ] . strip ( ) #NEWLINE# if ( not user . is_superuser ) : #NEWLINE# #INDENT# allowed_roles = get_account_roles ( user ) #NEWLINE# allowed_roles = [ role [ 0 ] for role in allowed_roles ] #NEWLINE# if ( desired_role not in allowed_roles ) : #NEWLINE# #INDENT# raise PermDeniedException ( _ ( "You can't import an account with a role greater than yours" ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . username = row [ 1 ] . strip ( ) #NEWLINE# try : #NEWLINE# #INDENT# User . objects . get ( username = self . username ) #NEWLINE# #UNINDENT# except User . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Conflict #NEWLINE# #UNINDENT# if ( desired_role == 'SimpleUsers' ) : #NEWLINE# #INDENT# if ( ( len ( row ) < 8 ) or ( not row [ 7 ] . strip ( ) ) ) : #NEWLINE# #INDENT# raise BadRequest ( _ ( ( "The simple user '%s' must have a valid email address" % self . username ) ) ) #NEWLINE# #UNINDENT# if ( self . username != row [ 7 ] . strip ( ) ) : #NEWLINE# #INDENT# raise BadRequest ( _ ( ( "username and email fields must not differ for '%s'" % self . username ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if crypt_password : #NEWLINE# #INDENT# self . set_password ( row [ 2 ] . strip ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . password = row [ 2 ] . strip ( ) #NEWLINE# #UNINDENT# self . first_name = row [ 3 ] . strip ( ) #NEWLINE# self . last_name = row [ 4 ] . strip ( ) #NEWLINE# self . is_active = ( row [ 5 ] . strip ( ) in [ 'True' , '1' , 'yes' , 'y' ] ) #NEWLINE# self . save ( ) #NEWLINE# self . role = desired_role #NEWLINE# self . post_create ( user ) #NEWLINE# if ( len ( row ) < 8 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# events . raiseEvent ( 'AccountImported' , user , self , row [ 7 : ] )