Subversion Repositories SmartDukaan

Rev

Rev 504 | Rev 513 | Go to most recent revision | Details | Compare with Previous | 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)
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
509 rajveer 42
    t_primary_info.dateOfBirth = to_java_date(primary_info.date_of_birth)
130 ashish 43
    t_primary_info.pictureUrl = primary_info.picture_id
44
    t_primary_info.email = primary_info.email
45
    t_primary_info.userHandle = primary_info.user_handle
46
    t_primary_info.socialHandles = to_t_social_handle(primary_info.social_handles)
47
    t_primary_info.shipmentOption = primary_info.shipment_option 
48
    t_primary_info.occupation = primary_info.occupation
49
    t_primary_info.hintQuestion = primary_info.hint_question
50
    t_primary_info.hintAnswer = primary_info.hint_answer
504 rajveer 51
    t_primary_info.communicationEmail = primary_info.communication_email
52
    t_primary_info.defaultAddressId = primary_info.default_address_id
130 ashish 53
 
54
    #put all addresses
55
    if primary_info.addresses:
56
        t_primary_info.addresses = set()
57
        for address in primary_info.addresses:
58
            t_primary_info.addresses.add(to_t_address(address))
59
    return t_primary_info  
60
 
61
    pass
62
 
63
def to_t_internal_info(internal_info):
64
    pass
65
 
66
def to_t_user_state(user_state):
67
    t_user_state = TUserState()
68
    t_user_state.userId = user_state.user.id
69
    t_user_state.isEmailVerified = user_state.is_email_verified
70
    t_user_state.lastLogin = to_java_date(user_state.last_login_timestamp)
71
    t_user_state.lastLogout = to_java_date(user_state.last_logout)
72
    t_user_state.emailVerificationSentOn = to_java_date(user_state.email_verification_sent_on)
73
    t_user_state.smsVerificationSentOn = to_java_date(user_state.sms_verification_sent_on)
74
    t_user_state.isSMSVerified = user_state.is_sms_verified
75
    t_user_state.activeSince = to_java_date(user_state.active_since)
76
    t_user_state.isLoggedIn = user_state.is_logged_in
77
    t_user_state.shoppingCartHandle = user_state.current_shopping_cart
78
    t_user_state.status = user_state.account_status
79
    return t_user_state    
80
 
81
def to_t_phone(phone):
82
    t_phone = TPhone()
83
    t_phone.areaCode = phone.area_code
84
    t_phone.countryCode = phone.country_code
85
    t_phone.extension = phone.extension
86
    t_phone.number = phone.number
87
    t_phone.type = phone.type
88
    return t_phone
89
 
90
def to_t_social_handle(social_handles):
91
    t_socialHandle = TSocialHandles()
92
    for social_handle in social_handles:
93
        if social_handle.service.name == "Facebook":
94
            t_socialHandle.facebook = social_handle.handle
95
        if social_handle.service.name == "OpenSocial":
96
            t_socialHandle.opensocial = social_handle.handle
97
        if social_handle.service.name == "Twitter":
98
            t_socialHandle.twitter = social_handle.handle
99
    return t_socialHandle