
    P1i'                         d dl mZ d dlmZ d dlmZ ddlmZ d dlm	Z	 d dl
mZ  e       Z eee      d	        Z eee      d
        Z eee      d        Zy)    )	post_save)receiver)get_user_model   )UserProfilePerson)NameFormatter)senderc                     |r!t         j                  j                  |       yt         j                  j                  |       y)zJCreate or update a UserProfile instance when a User is created or updated.)userN)r   objectscreateget_or_create)r   instancecreatedkwargss       2/home/cursorai/projects/iching/accounts/signals.pycreate_or_update_user_profiler   
   s7     """1 	))x)8    c                 R    t        |d      r|j                  j                          yy)z5Save the UserProfile instance when the User is saved.profileN)hasattrr   save)r   r   r   s      r   save_user_profiler      s%     x# $r   c                 J   t        |j                  d      r|j                  j                  ryddl}|j	                         }t        |d      ry|j
                  rHddlm} t        j                  |j                  j                  |j                  j                        }|j                  j                  |j                  d      j                         }|r
|j                         r||_        |j                  j"                  r4|j                  j"                  dk7  r|j                  j"                  |_        |j
                  |_        |j$                  |_        |j&                  |_        |j(                  |_        |j*                  |_        t        |j                  d      xr |j                  j                  |_        |j/                          |j1                          y|j                  j3                  ||j                  j"                  |j
                  |j$                  |j&                  |j(                  |j*                  |j                  t        |j                  d      xr |j                  j                  d	
      }|j/                          |j1                          yy)
zNCreate or update a BaziPerson record when a UserProfile is created or updated.is_temporary_userNr   _bazi_recalc_threadr   T)
created_byownerN)
namegender
birth_date
birth_time	twin_type
father_dob
mother_dobr   created_by_temp_userr    )r   r   r   	threadingcurrent_threadr$   bazi.modelsr	   r
   format_name
first_name	last_namer   filterfirststripr"   r#   r%   r&   r'   r(   r)   calculate_bazir   r   )	r   r   r   r   r*   r+   r	   	full_namebazi_persons	            r   create_or_update_bazi_personr6      s    x}}12x}}7V7V --/N~45& "--hmm.F.FH_H_`	 nn++x}}D+QWWY  #, }}##(<(<(C%-]]%9%9" &.%8%8K"%-%8%8K"$,$6$6K!%-%8%8K"%-%8%8K"/6x}}FY/Z/~_g_l_l_~_~K,&&( !..//}}++#..#..",,#..#..#==%,X]]<O%P%tU]UbUbUtUt 0 K &&(Y r   N)django.db.models.signalsr   django.dispatchr   django.contrib.authr   modelsr   r,   r	   iching.utils.utilsr
   Userr   r   r6    r   r   <module>r>      sn    . $ .   ,	)D!9 "9 
)D!  " 
 
)K(9 )9r   