Subversion Repositories SmartDukaan

Rev

Rev 414 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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)
20
    return t_address
21
 
22
 
23
def to_t_user_context(user_context):
24
    t_user_context = TUserContext()
25
    t_user_context.id = user_context.id
26
    t_user_context.sessionid = user_context.session_id
27
    t_user_context.primaryInfo = to_t_primary_info(user_context.primary_info)
28
    t_user_context.internalInfo = to_t_internal_info(user_context.internal_info)
29
    t_user_context.userState = to_t_user_state(user_context.state)
30
    return t_user_context
31
 
32
 
33
def to_t_primary_info(primary_info):
34
    t_primary_info = TUserPrimaryInfo()
35
    t_primary_info.userId = primary_info.user.id
36
    t_primary_info.title = primary_info.title
37
    t_primary_info.firstName = primary_info.first_name
38
    t_primary_info.middleName = primary_info.middle_name
39
    t_primary_info.lastName = primary_info.last_name
40
    t_primary_info.pictureUrl = primary_info.picture_id
41
    t_primary_info.email = primary_info.email
42
    t_primary_info.userHandle = primary_info.user_handle
43
    t_primary_info.socialHandles = to_t_social_handle(primary_info.social_handles)
44
    t_primary_info.shipmentOption = primary_info.shipment_option 
45
    t_primary_info.occupation = primary_info.occupation
46
    t_primary_info.hintQuestion = primary_info.hint_question
47
    t_primary_info.hintAnswer = primary_info.hint_answer
48
 
49
    #put all addresses
50
    if primary_info.addresses:
51
        t_primary_info.addresses = set()
52
        for address in primary_info.addresses:
53
            t_primary_info.addresses.add(to_t_address(address))
54
    return t_primary_info  
55
 
56
    pass
57
 
58
def to_t_internal_info(internal_info):
59
    pass
60
 
61
def to_t_user_state(user_state):
62
    t_user_state = TUserState()
63
    t_user_state.userId = user_state.user.id
64
    t_user_state.isEmailVerified = user_state.is_email_verified
65
    t_user_state.lastLogin = to_java_date(user_state.last_login_timestamp)
66
    t_user_state.lastLogout = to_java_date(user_state.last_logout)
67
    t_user_state.emailVerificationSentOn = to_java_date(user_state.email_verification_sent_on)
68
    t_user_state.smsVerificationSentOn = to_java_date(user_state.sms_verification_sent_on)
69
    t_user_state.isSMSVerified = user_state.is_sms_verified
70
    t_user_state.activeSince = to_java_date(user_state.active_since)
71
    t_user_state.isLoggedIn = user_state.is_logged_in
72
    t_user_state.shoppingCartHandle = user_state.current_shopping_cart
73
    t_user_state.status = user_state.account_status
74
    return t_user_state    
75
 
76
def to_t_phone(phone):
77
    t_phone = TPhone()
78
    t_phone.areaCode = phone.area_code
79
    t_phone.countryCode = phone.country_code
80
    t_phone.extension = phone.extension
81
    t_phone.number = phone.number
82
    t_phone.type = phone.type
83
    return t_phone
84
 
85
def to_t_social_handle(social_handles):
86
    t_socialHandle = TSocialHandles()
87
    for social_handle in social_handles:
88
        if social_handle.service.name == "Facebook":
89
            t_socialHandle.facebook = social_handle.handle
90
        if social_handle.service.name == "OpenSocial":
91
            t_socialHandle.opensocial = social_handle.handle
92
        if social_handle.service.name == "Twitter":
93
            t_socialHandle.twitter = social_handle.handle
94
    return t_socialHandle