| 130 |
ashish |
1 |
from shop2020.thriftpy.model.v1.user.ttypes import Address as TAddress,\
|
| 557 |
chandransh |
2 |
Phone as TPhone, SocialHandles as TSocialHandles,\
|
| 565 |
rajveer |
3 |
UserState as TUserState, User as TUser, Cart as TCart, Line as TLine, Sex as TSex
|
| 130 |
ashish |
4 |
from shop2020.utils.Utils import to_java_date
|
|
|
5 |
|
|
|
6 |
def to_t_address(address):
|
|
|
7 |
t_address = TAddress()
|
|
|
8 |
t_address.id = address.id
|
|
|
9 |
t_address.line1 = address.line_1
|
|
|
10 |
t_address.line2 = address.line_2
|
|
|
11 |
t_address.landmark = address.landmark
|
|
|
12 |
t_address.city = address.city
|
|
|
13 |
t_address.state = address.state
|
|
|
14 |
t_address.pin = address.pin
|
|
|
15 |
t_address.country = address.country
|
|
|
16 |
t_address.enabled = address.enabled
|
|
|
17 |
t_address.type = address.type
|
|
|
18 |
t_address.addedOn = to_java_date(address.added_on)
|
| 414 |
ashish |
19 |
t_address.name = address.name
|
|
|
20 |
t_address.phone = address.phone
|
| 557 |
chandransh |
21 |
return t_address
|
| 130 |
ashish |
22 |
|
| 557 |
chandransh |
23 |
def to_t_user(user):
|
|
|
24 |
t_user = TUser()
|
| 576 |
chandransh |
25 |
if user is None:
|
|
|
26 |
t_user.userId = -1
|
|
|
27 |
return t_user
|
|
|
28 |
|
| 557 |
chandransh |
29 |
t_user.userId = user.id
|
|
|
30 |
t_user.name = user.name
|
|
|
31 |
t_user.email = user.email
|
|
|
32 |
t_user.sex = user.sex
|
|
|
33 |
|
|
|
34 |
t_user.socialHandles = to_t_social_handle(user.social_handles)
|
|
|
35 |
t_user.communicationEmail = user.communication_email
|
|
|
36 |
t_user.defaultAddressId = user.default_address_id
|
|
|
37 |
t_user.isAnonymous = user.is_anonymous
|
|
|
38 |
t_user.activeCartId = user.active_cart_id
|
| 567 |
rajveer |
39 |
t_user.dateOfBirth = user.date_of_birth
|
|
|
40 |
t_user.mobileNumber = user.mobile_number
|
| 130 |
ashish |
41 |
#put all addresses
|
| 557 |
chandransh |
42 |
if user.addresses:
|
|
|
43 |
t_user.addresses = list()
|
|
|
44 |
for address in user.addresses:
|
|
|
45 |
t_user.addresses.append(to_t_address(address))
|
|
|
46 |
return t_user
|
| 513 |
rajveer |
47 |
|
| 130 |
ashish |
48 |
def to_t_internal_info(internal_info):
|
|
|
49 |
pass
|
|
|
50 |
|
|
|
51 |
def to_t_user_state(user_state):
|
|
|
52 |
t_user_state = TUserState()
|
|
|
53 |
t_user_state.userId = user_state.user.id
|
| 557 |
chandransh |
54 |
t_user_state.lastLogin = to_java_date(user_state.last_login)
|
| 130 |
ashish |
55 |
t_user_state.lastLogout = to_java_date(user_state.last_logout)
|
|
|
56 |
t_user_state.emailVerificationSentOn = to_java_date(user_state.email_verification_sent_on)
|
|
|
57 |
t_user_state.smsVerificationSentOn = to_java_date(user_state.sms_verification_sent_on)
|
| 557 |
chandransh |
58 |
t_user_state.isEmailVerified = user_state.is_email_verified
|
| 130 |
ashish |
59 |
t_user_state.isSMSVerified = user_state.is_sms_verified
|
|
|
60 |
t_user_state.activeSince = to_java_date(user_state.active_since)
|
|
|
61 |
t_user_state.status = user_state.account_status
|
|
|
62 |
return t_user_state
|
|
|
63 |
|
|
|
64 |
def to_t_phone(phone):
|
|
|
65 |
t_phone = TPhone()
|
|
|
66 |
t_phone.areaCode = phone.area_code
|
|
|
67 |
t_phone.countryCode = phone.country_code
|
|
|
68 |
t_phone.extension = phone.extension
|
|
|
69 |
t_phone.number = phone.number
|
|
|
70 |
t_phone.type = phone.type
|
|
|
71 |
return t_phone
|
|
|
72 |
|
|
|
73 |
def to_t_social_handle(social_handles):
|
|
|
74 |
t_socialHandle = TSocialHandles()
|
|
|
75 |
for social_handle in social_handles:
|
|
|
76 |
if social_handle.service.name == "Facebook":
|
|
|
77 |
t_socialHandle.facebook = social_handle.handle
|
|
|
78 |
if social_handle.service.name == "OpenSocial":
|
|
|
79 |
t_socialHandle.opensocial = social_handle.handle
|
|
|
80 |
if social_handle.service.name == "Twitter":
|
|
|
81 |
t_socialHandle.twitter = social_handle.handle
|
| 557 |
chandransh |
82 |
return t_socialHandle
|
|
|
83 |
|
|
|
84 |
def to_t_cart(cart):
|
|
|
85 |
t_cart = TCart()
|
|
|
86 |
if cart:
|
|
|
87 |
t_cart.id = cart.id
|
|
|
88 |
t_cart.status = cart.cart_status
|
|
|
89 |
lines = []
|
|
|
90 |
if cart.lines:
|
|
|
91 |
for line in cart.lines:
|
|
|
92 |
lines.append(to_t_line(line))
|
|
|
93 |
t_cart.lines = lines
|
|
|
94 |
t_cart.createdOn = to_java_date(cart.created_on)
|
|
|
95 |
t_cart.updatedOn = to_java_date(cart.updated_on)
|
|
|
96 |
t_cart.userId = cart.user_id
|
|
|
97 |
t_cart.addressId = cart.address_id
|
|
|
98 |
t_cart.committedOn = to_java_date(cart.committed_on)
|
|
|
99 |
return t_cart
|
|
|
100 |
|
|
|
101 |
def to_t_line(line_item):
|
| 565 |
rajveer |
102 |
t_line_item = TLine()
|
| 557 |
chandransh |
103 |
if line_item:
|
|
|
104 |
t_line_item.id = line_item.id
|
|
|
105 |
t_line_item.itemId = line_item.item_id
|
|
|
106 |
t_line_item.quantity = line_item.quantity
|
|
|
107 |
t_line_item.createdOn = to_java_date(line_item.created_on)
|
|
|
108 |
t_line_item.updatedOn = to_java_date(line_item.updated_on)
|
|
|
109 |
t_line_item.lineStatus = line_item.line_status
|
|
|
110 |
return t_line_item
|
|
|
111 |
|