| 130 |
ashish |
1 |
from shop2020.thriftpy.model.v1.user.ttypes import Address as TAddress,\
|
|
|
2 |
UserContext as TUserContext, Phone as TPhone, SocialHandles as TSocialHandles,\
|
|
|
3 |
UserState as TUserState, UserPrimaryInfo as TUserPrimaryInfo
|
|
|
4 |
from shop2020.model.v1.user.impl.Dataservice import Address
|
|
|
5 |
from shop2020.utils.Utils import to_java_date
|
|
|
6 |
|
|
|
7 |
def to_t_address(address):
|
|
|
8 |
t_address = TAddress()
|
|
|
9 |
t_address.id = address.id
|
|
|
10 |
t_address.line1 = address.line_1
|
|
|
11 |
t_address.line2 = address.line_2
|
|
|
12 |
t_address.landmark = address.landmark
|
|
|
13 |
t_address.city = address.city
|
|
|
14 |
t_address.state = address.state
|
|
|
15 |
t_address.pin = address.pin
|
|
|
16 |
t_address.country = address.country
|
|
|
17 |
t_address.enabled = address.enabled
|
|
|
18 |
t_address.type = address.type
|
|
|
19 |
t_address.addedOn = to_java_date(address.added_on)
|
| 414 |
ashish |
20 |
t_address.name = address.name
|
|
|
21 |
t_address.phone = address.phone
|
| 130 |
ashish |
22 |
return t_address
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
def to_t_user_context(user_context):
|
|
|
26 |
t_user_context = TUserContext()
|
|
|
27 |
t_user_context.id = user_context.id
|
|
|
28 |
t_user_context.sessionid = user_context.session_id
|
|
|
29 |
t_user_context.primaryInfo = to_t_primary_info(user_context.primary_info)
|
|
|
30 |
t_user_context.internalInfo = to_t_internal_info(user_context.internal_info)
|
|
|
31 |
t_user_context.userState = to_t_user_state(user_context.state)
|
|
|
32 |
return t_user_context
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
def to_t_primary_info(primary_info):
|
|
|
36 |
t_primary_info = TUserPrimaryInfo()
|
|
|
37 |
t_primary_info.userId = primary_info.user.id
|
|
|
38 |
t_primary_info.title = primary_info.title
|
|
|
39 |
t_primary_info.firstName = primary_info.first_name
|
|
|
40 |
t_primary_info.middleName = primary_info.middle_name
|
|
|
41 |
t_primary_info.lastName = primary_info.last_name
|
|
|
42 |
t_primary_info.pictureUrl = primary_info.picture_id
|
|
|
43 |
t_primary_info.email = primary_info.email
|
|
|
44 |
t_primary_info.userHandle = primary_info.user_handle
|
|
|
45 |
t_primary_info.socialHandles = to_t_social_handle(primary_info.social_handles)
|
|
|
46 |
t_primary_info.shipmentOption = primary_info.shipment_option
|
|
|
47 |
t_primary_info.occupation = primary_info.occupation
|
|
|
48 |
t_primary_info.hintQuestion = primary_info.hint_question
|
|
|
49 |
t_primary_info.hintAnswer = primary_info.hint_answer
|
| 504 |
rajveer |
50 |
t_primary_info.communicationEmail = primary_info.communication_email
|
|
|
51 |
t_primary_info.defaultAddressId = primary_info.default_address_id
|
| 130 |
ashish |
52 |
|
|
|
53 |
#put all addresses
|
|
|
54 |
if primary_info.addresses:
|
|
|
55 |
t_primary_info.addresses = set()
|
|
|
56 |
for address in primary_info.addresses:
|
|
|
57 |
t_primary_info.addresses.add(to_t_address(address))
|
|
|
58 |
return t_primary_info
|
|
|
59 |
|
|
|
60 |
pass
|
|
|
61 |
|
|
|
62 |
def to_t_internal_info(internal_info):
|
|
|
63 |
pass
|
|
|
64 |
|
|
|
65 |
def to_t_user_state(user_state):
|
|
|
66 |
t_user_state = TUserState()
|
|
|
67 |
t_user_state.userId = user_state.user.id
|
|
|
68 |
t_user_state.isEmailVerified = user_state.is_email_verified
|
|
|
69 |
t_user_state.lastLogin = to_java_date(user_state.last_login_timestamp)
|
|
|
70 |
t_user_state.lastLogout = to_java_date(user_state.last_logout)
|
|
|
71 |
t_user_state.emailVerificationSentOn = to_java_date(user_state.email_verification_sent_on)
|
|
|
72 |
t_user_state.smsVerificationSentOn = to_java_date(user_state.sms_verification_sent_on)
|
|
|
73 |
t_user_state.isSMSVerified = user_state.is_sms_verified
|
|
|
74 |
t_user_state.activeSince = to_java_date(user_state.active_since)
|
|
|
75 |
t_user_state.isLoggedIn = user_state.is_logged_in
|
|
|
76 |
t_user_state.shoppingCartHandle = user_state.current_shopping_cart
|
|
|
77 |
t_user_state.status = user_state.account_status
|
|
|
78 |
return t_user_state
|
|
|
79 |
|
|
|
80 |
def to_t_phone(phone):
|
|
|
81 |
t_phone = TPhone()
|
|
|
82 |
t_phone.areaCode = phone.area_code
|
|
|
83 |
t_phone.countryCode = phone.country_code
|
|
|
84 |
t_phone.extension = phone.extension
|
|
|
85 |
t_phone.number = phone.number
|
|
|
86 |
t_phone.type = phone.type
|
|
|
87 |
return t_phone
|
|
|
88 |
|
|
|
89 |
def to_t_social_handle(social_handles):
|
|
|
90 |
t_socialHandle = TSocialHandles()
|
|
|
91 |
for social_handle in social_handles:
|
|
|
92 |
if social_handle.service.name == "Facebook":
|
|
|
93 |
t_socialHandle.facebook = social_handle.handle
|
|
|
94 |
if social_handle.service.name == "OpenSocial":
|
|
|
95 |
t_socialHandle.opensocial = social_handle.handle
|
|
|
96 |
if social_handle.service.name == "Twitter":
|
|
|
97 |
t_socialHandle.twitter = social_handle.handle
|
|
|
98 |
return t_socialHandle
|