| Line 1... |
Line 1... |
| 1 |
'''
|
1 |
'''
|
| 2 |
Created on 28-Apr-2010
|
2 |
Created on 28-Apr-2010
|
| 3 |
|
3 |
|
| 4 |
@author: ashish
|
4 |
@author: ashish
|
| 5 |
'''
|
5 |
'''
|
| 6 |
from shop2020.model.v1.user.impl import Dataservice
|
- |
|
| 7 |
from shop2020.utils.Utils import log_entry, to_py_date
|
- |
|
| 8 |
from shop2020.thriftpy.model.v1.user.ttypes import WidgetType as WType
|
- |
|
| 9 |
from shop2020.model.v1.user.impl.Dataservice import User, UserCommunication, \
|
- |
|
| 10 |
Address, Affiliate, Tracker, TrackLog,\
|
- |
|
| 11 |
MasterAffiliate, UserWidgetItem, FacebookUser, UserSource, PrivateDealUser
|
- |
|
| 12 |
from shop2020.thriftpy.model.v1.user.ttypes import UserContextException,\
|
- |
|
| 13 |
AuthenticationException, Sex
|
- |
|
| 14 |
from elixir import session
|
6 |
from elixir import session
|
| 15 |
import datetime
|
- |
|
| 16 |
from sqlalchemy import desc
|
- |
|
| 17 |
from sqlalchemy import select
|
7 |
from shop2020.model.v1.user.impl import Dataservice
|
| 18 |
from shop2020.model.v1.user.impl.CartDataAccessors import create_cart
|
8 |
from shop2020.model.v1.user.impl.CartDataAccessors import create_cart
|
| - |
|
9 |
from shop2020.model.v1.user.impl.Dataservice import User, UserCommunication, \
|
| - |
|
10 |
Address, Affiliate, Tracker, TrackLog, MasterAffiliate, UserWidgetItem, \
|
| - |
|
11 |
FacebookUser, UserSource, PrivateDealUser, Counter
|
| - |
|
12 |
from shop2020.thriftpy.model.v1.user.ttypes import UserContextException, \
|
| - |
|
13 |
AuthenticationException, Sex, WidgetType as WType
|
| - |
|
14 |
from shop2020.utils.Utils import log_entry, to_py_date
|
| - |
|
15 |
from sqlalchemy import desc, select
|
| 19 |
from sqlalchemy.sql import and_
|
16 |
from sqlalchemy.sql import and_
|
| - |
|
17 |
import datetime
|
| - |
|
18 |
|
| - |
|
19 |
CounterStateMap = {"Telangana" : "TS", "Andhra Pradesh" : "AP"}
|
| 20 |
|
20 |
|
| 21 |
def initialize(dbname='user', db_hostname="localhost"):
|
21 |
def initialize(dbname='user', db_hostname="localhost"):
|
| 22 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
22 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
| 23 |
Dataservice.initialize(dbname, db_hostname)
|
23 |
Dataservice.initialize(dbname, db_hostname)
|
| 24 |
|
24 |
|
| Line 79... |
Line 79... |
| 79 |
user.mobile_number = user_to_add.mobileNumber
|
79 |
user.mobile_number = user_to_add.mobileNumber
|
| 80 |
user.source = user_to_add.source
|
80 |
user.source = user_to_add.source
|
| 81 |
user.source_start_time = to_py_date(user_to_add.sourceStartTime)
|
81 |
user.source_start_time = to_py_date(user_to_add.sourceStartTime)
|
| 82 |
user.trust_level = 0
|
82 |
user.trust_level = 0
|
| 83 |
user.active_since = datetime.datetime.now()
|
83 |
user.active_since = datetime.datetime.now()
|
| - |
|
84 |
addresses = []
|
| - |
|
85 |
if user_to_add.addresses:
|
| - |
|
86 |
address = user_to_add.addresses[0]
|
| - |
|
87 |
address_to_add = Address()
|
| - |
|
88 |
address_to_add.line_1 = address.line1
|
| - |
|
89 |
address_to_add.line_2 = address.line2
|
| 84 |
|
- |
|
| - |
|
90 |
address_to_add.landmark = address.landmark
|
| - |
|
91 |
address_to_add.city = address.city
|
| - |
|
92 |
address_to_add.country = address.country
|
| - |
|
93 |
address_to_add.state = address.state
|
| - |
|
94 |
address_to_add.pin = address.pin
|
| - |
|
95 |
address_to_add.type = address.type
|
| - |
|
96 |
address_to_add.name = address.name
|
| - |
|
97 |
address_to_add.phone = address.phone
|
| - |
|
98 |
address_to_add.added_on = to_py_date(address.addedOn)
|
| - |
|
99 |
address_to_add.enabled = True
|
| - |
|
100 |
address_to_add.user = user
|
| - |
|
101 |
address_to_add.type = 1
|
| - |
|
102 |
address_to_add.added_on = datetime.datetime.now()
|
| - |
|
103 |
addresses.append(address_to_add)
|
| - |
|
104 |
user.addresses = addresses
|
| 85 |
us = UserSource()
|
105 |
us = UserSource()
|
| 86 |
us.user = user
|
106 |
us.user = user
|
| 87 |
us.source_id = 1
|
107 |
us.source_id = 1
|
| 88 |
if user_to_add.sourceId:
|
108 |
if user_to_add.sourceId:
|
| 89 |
us.source_id = user_to_add.sourceId
|
109 |
us.source_id = user_to_add.sourceId
|
| Line 92... |
Line 112... |
| 92 |
fuser = FacebookUser()
|
112 |
fuser = FacebookUser()
|
| 93 |
fuser.facebook_access_token = user_to_add.facebookAccessToken
|
113 |
fuser.facebook_access_token = user_to_add.facebookAccessToken
|
| 94 |
fuser.facebook_id = user_to_add.facebookId
|
114 |
fuser.facebook_id = user_to_add.facebookId
|
| 95 |
fuser.user = user
|
115 |
fuser.user = user
|
| 96 |
session.commit()
|
116 |
session.commit()
|
| - |
|
117 |
if user_to_add.addresses:
|
| - |
|
118 |
user.default_address_id = user.addresses[0].id
|
| - |
|
119 |
session.commit()
|
| 97 |
return user
|
120 |
return user
|
| 98 |
|
121 |
|
| 99 |
#===============================================================================
|
122 |
#===============================================================================
|
| 100 |
# Need to provide the update apis here for relevant fields in PrimaryInfo.
|
123 |
# Need to provide the update apis here for relevant fields in PrimaryInfo.
|
| 101 |
#===============================================================================
|
124 |
#===============================================================================
|
| Line 554... |
Line 577... |
| 554 |
return True
|
577 |
return True
|
| 555 |
|
578 |
|
| 556 |
def get_private_deal_user(userId):
|
579 |
def get_private_deal_user(userId):
|
| 557 |
return PrivateDealUser.get_by(id=userId)
|
580 |
return PrivateDealUser.get_by(id=userId)
|
| 558 |
|
581 |
|
| - |
|
582 |
def register_counter(tCounter, userId):
|
| - |
|
583 |
firstValidAddress = Address.query.filter_by(user_id = userId, enabled=True).first()
|
| - |
|
584 |
counter = Counter()
|
| - |
|
585 |
_setCounter(counter, tCounter, firstValidAddress)
|
| - |
|
586 |
pDealUser = PrivateDealUser()
|
| - |
|
587 |
pDealUser.counter = counter
|
| - |
|
588 |
pDealUser.tin = tCounter.tin
|
| - |
|
589 |
pDealUser.id = userId
|
| - |
|
590 |
pDealUser.created_on = datetime.datetime.now()
|
| - |
|
591 |
pDealUser.isActive = True
|
| - |
|
592 |
session.commit()
|
| - |
|
593 |
m = {}
|
| - |
|
594 |
m['counter_code'] = counter.code
|
| - |
|
595 |
return m
|
| - |
|
596 |
|
| - |
|
597 |
def _setCounter(counter,tCounter,address):
|
| - |
|
598 |
#counter = Counter()
|
| - |
|
599 |
counter.name = tCounter.name
|
| - |
|
600 |
counter.ownerName = tCounter.ownerName
|
| - |
|
601 |
counter.createdOn = datetime.datetime.now()
|
| - |
|
602 |
counter.email = tCounter.email
|
| - |
|
603 |
counter.mobile = tCounter.mobile
|
| - |
|
604 |
counter.addressId = address.id
|
| - |
|
605 |
counter.tin = tCounter.tin
|
| - |
|
606 |
query = Counter.query.filter(Counter.code.like(CounterStateMap[address.state] + '%')).order_by(Counter.id.desc())
|
| - |
|
607 |
lastStateCounter = query.first()
|
| - |
|
608 |
if lastStateCounter:
|
| - |
|
609 |
counter.code = CounterStateMap[state] + str(int(lastStateCounter.code[2:])+1).zfill(6)
|
| - |
|
610 |
else:
|
| - |
|
611 |
counter.code = CounterStateMap[state] + "000001"
|
| - |
|
612 |
counter.striker = tCounter.striker
|
| - |
|
613 |
if tCounter.alternateMobile:
|
| - |
|
614 |
counter.alternateMobile = tCounter.alternateMobile
|
| - |
|
615 |
if tCounter.spCounterSize:
|
| - |
|
616 |
counter.spCounterSize = tCounter.spCounterSize
|
| - |
|
617 |
if tCounter.fpCounterSize:
|
| - |
|
618 |
counter.fpCounterSize = tCounter.fpCounterSize
|
| - |
|
619 |
|
| 559 |
def close_session():
|
620 |
def close_session():
|
| 560 |
if session.is_active:
|
621 |
if session.is_active:
|
| 561 |
print "session is active. closing it."
|
622 |
print "session is active. closing it."
|
| 562 |
session.close()
|
623 |
session.close()
|
| 563 |
|
624 |
|