| 130 |
ashish |
1 |
'''
|
|
|
2 |
Created on 28-Apr-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
| 12696 |
amit.gupta |
6 |
from elixir import session
|
| 130 |
ashish |
7 |
from shop2020.model.v1.user.impl import Dataservice
|
| 12696 |
amit.gupta |
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, \
|
| 18764 |
kshitij.so |
11 |
FacebookUser, UserSource, PrivateDealUser, Counter, AccessTokenizer, PrivateDealUserAddressMapping, \
|
|
|
12 |
Line
|
| 12696 |
amit.gupta |
13 |
from shop2020.thriftpy.model.v1.user.ttypes import UserContextException, \
|
|
|
14 |
AuthenticationException, Sex, WidgetType as WType
|
| 2981 |
rajveer |
15 |
from shop2020.utils.Utils import log_entry, to_py_date
|
| 12696 |
amit.gupta |
16 |
from sqlalchemy import desc, select
|
|
|
17 |
from sqlalchemy.sql import and_
|
| 12722 |
amit.gupta |
18 |
from sqlalchemy.sql.expression import or_
|
| 2981 |
rajveer |
19 |
import datetime
|
| 15251 |
manish.sha |
20 |
import os, binascii
|
| 18764 |
kshitij.so |
21 |
from shop2020.model.v1.user.impl.Converters import to_t_line
|
| 18973 |
amit.gupta |
22 |
tinStates = ['Delhi']
|
| 18960 |
amit.gupta |
23 |
CounterStateMap = {"Andhra Pradesh":"AP",
|
|
|
24 |
"Arunachal Pradesh":"AR",
|
|
|
25 |
"Assam":"AS",
|
|
|
26 |
"Bihar":"BR",
|
|
|
27 |
"Chhattisgarh":"CT",
|
|
|
28 |
"Goa":"GA",
|
|
|
29 |
"Gujarat":"GJ",
|
|
|
30 |
"Haryana":"HR",
|
|
|
31 |
"Himachal Pradesh":"HP",
|
|
|
32 |
"Jammu and Kashmir":"JK",
|
|
|
33 |
"Jharkhand":"JH",
|
|
|
34 |
"Karnataka":"KA",
|
|
|
35 |
"Kerala":"KL",
|
|
|
36 |
"Madhya Pradesh":"MP",
|
|
|
37 |
"Maharashtra":"MH",
|
|
|
38 |
"Manipur":"MN",
|
|
|
39 |
"Meghalaya":"ML",
|
|
|
40 |
"Mizoram":"MZ",
|
|
|
41 |
"Nagaland":"NL",
|
|
|
42 |
"Odisha":"OR",
|
|
|
43 |
"Punjab":"PB",
|
|
|
44 |
"Rajasthan":"RJ",
|
|
|
45 |
"Sikkim":"SK",
|
|
|
46 |
"Tamil Nadu":"TN",
|
|
|
47 |
"Telangana":"TS",
|
|
|
48 |
"Tripura":"TR",
|
|
|
49 |
"Uttarakhand":"UT",
|
|
|
50 |
"Uttar Pradesh":"UP",
|
|
|
51 |
"West Bengal":"WB",
|
|
|
52 |
"Andaman and Nicobar Islands":"AN",
|
|
|
53 |
"Chandigarh":"CH",
|
|
|
54 |
"Dadra and Nagar Haveli":"DN",
|
|
|
55 |
"Daman and Diu":"DD",
|
|
|
56 |
"Delhi":"DL",
|
|
|
57 |
"Lakshadweep":"LD",
|
|
|
58 |
"Puducherry":"PY",
|
|
|
59 |
"Pondicherry":"PY"
|
|
|
60 |
}
|
| 12696 |
amit.gupta |
61 |
|
| 3187 |
rajveer |
62 |
def initialize(dbname='user', db_hostname="localhost"):
|
| 130 |
ashish |
63 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
| 3187 |
rajveer |
64 |
Dataservice.initialize(dbname, db_hostname)
|
| 557 |
chandransh |
65 |
|
| 5326 |
rajveer |
66 |
def create_anonymous_user(jsession_id):
|
| 576 |
chandransh |
67 |
user=User.get_by(jsession_id=jsession_id)
|
| 5036 |
rajveer |
68 |
#user=User.query.with_lockmode("update").filter_by(jsession_id=jsession_id)
|
| 576 |
chandransh |
69 |
if not user is None:
|
|
|
70 |
return user
|
| 5326 |
rajveer |
71 |
cart = create_cart()
|
| 557 |
chandransh |
72 |
user = User()
|
|
|
73 |
anonymous_str = "anonymous"
|
| 576 |
chandransh |
74 |
user.email = jsession_id + "@anonymous.com"
|
| 557 |
chandransh |
75 |
user.password = anonymous_str
|
|
|
76 |
user.name = anonymous_str
|
|
|
77 |
user.communication_email = jsession_id + "@anonymous.com"
|
|
|
78 |
user.jsession_id = jsession_id
|
|
|
79 |
user.is_anonymous = True
|
|
|
80 |
user.sex = Sex.WONT_SAY
|
| 5326 |
rajveer |
81 |
user.active_cart = cart
|
| 3499 |
mandeep.dh |
82 |
user.trust_level = 0
|
| 5326 |
rajveer |
83 |
user.active_since = datetime.datetime.now()
|
| 2747 |
chandransh |
84 |
session.commit()
|
| 557 |
chandransh |
85 |
|
|
|
86 |
return user
|
|
|
87 |
|
|
|
88 |
def get_user_by_id(user_id):
|
|
|
89 |
return User.get_by(id=user_id)
|
|
|
90 |
|
| 5326 |
rajveer |
91 |
def get_user_by_cart_id(cart_id):
|
|
|
92 |
return User.get_by(active_cart_id=cart_id)
|
|
|
93 |
|
| 3032 |
mandeep.dh |
94 |
def get_user_by_mobile_number(mobile_number):
|
|
|
95 |
return User.get_by(mobile_number=mobile_number)
|
|
|
96 |
|
| 1491 |
vikas |
97 |
def get_user_by_email(email):
|
|
|
98 |
return User.get_by(email=email)
|
|
|
99 |
|
| 5326 |
rajveer |
100 |
def create_user(user_to_add):
|
| 7825 |
amar.kumar |
101 |
user = User.get_by(email=user_to_add.email)
|
|
|
102 |
if user:
|
| 13661 |
amit.gupta |
103 |
if user.password == user_to_add.password or user_to_add.password == "":
|
|
|
104 |
if user_to_add.password == "":
|
|
|
105 |
add_private_deal_user(user.id)
|
| 7825 |
amar.kumar |
106 |
return user
|
|
|
107 |
else:
|
|
|
108 |
raise UserContextException(109, "User already exists with this email id.")
|
| 5326 |
rajveer |
109 |
|
|
|
110 |
cart = create_cart()
|
|
|
111 |
|
| 557 |
chandransh |
112 |
user = User()
|
|
|
113 |
user.email = user_to_add.email
|
|
|
114 |
user.password = user_to_add.password
|
|
|
115 |
user.name = user_to_add.name
|
|
|
116 |
user.communication_email = user_to_add.communicationEmail
|
|
|
117 |
user.jsession_id = user_to_add.jsessionId
|
|
|
118 |
user.is_anonymous = False
|
|
|
119 |
user.sex = user_to_add.sex
|
| 567 |
rajveer |
120 |
user.date_of_birth = user_to_add.dateOfBirth
|
| 5326 |
rajveer |
121 |
user.active_cart = cart
|
| 567 |
rajveer |
122 |
user.mobile_number = user_to_add.mobileNumber
|
| 2020 |
vikas |
123 |
user.source = user_to_add.source
|
| 2815 |
vikas |
124 |
user.source_start_time = to_py_date(user_to_add.sourceStartTime)
|
| 3499 |
mandeep.dh |
125 |
user.trust_level = 0
|
| 5326 |
rajveer |
126 |
user.active_since = datetime.datetime.now()
|
| 12696 |
amit.gupta |
127 |
addresses = []
|
|
|
128 |
if user_to_add.addresses:
|
|
|
129 |
address = user_to_add.addresses[0]
|
|
|
130 |
address_to_add = Address()
|
|
|
131 |
address_to_add.line_1 = address.line1
|
|
|
132 |
address_to_add.line_2 = address.line2
|
|
|
133 |
address_to_add.landmark = address.landmark
|
|
|
134 |
address_to_add.city = address.city
|
|
|
135 |
address_to_add.country = address.country
|
|
|
136 |
address_to_add.state = address.state
|
|
|
137 |
address_to_add.pin = address.pin
|
|
|
138 |
address_to_add.type = address.type
|
|
|
139 |
address_to_add.name = address.name
|
|
|
140 |
address_to_add.phone = address.phone
|
|
|
141 |
address_to_add.added_on = to_py_date(address.addedOn)
|
|
|
142 |
address_to_add.enabled = True
|
|
|
143 |
address_to_add.user = user
|
|
|
144 |
address_to_add.type = 1
|
|
|
145 |
address_to_add.added_on = datetime.datetime.now()
|
|
|
146 |
addresses.append(address_to_add)
|
|
|
147 |
user.addresses = addresses
|
| 8201 |
rajveer |
148 |
us = UserSource()
|
|
|
149 |
us.user = user
|
|
|
150 |
us.source_id = 1
|
|
|
151 |
if user_to_add.sourceId:
|
|
|
152 |
us.source_id = user_to_add.sourceId
|
| 7883 |
rajveer |
153 |
|
|
|
154 |
if user_to_add.isFacebookUser:
|
|
|
155 |
fuser = FacebookUser()
|
|
|
156 |
fuser.facebook_access_token = user_to_add.facebookAccessToken
|
|
|
157 |
fuser.facebook_id = user_to_add.facebookId
|
|
|
158 |
fuser.user = user
|
| 130 |
ashish |
159 |
session.commit()
|
| 12696 |
amit.gupta |
160 |
if user_to_add.addresses:
|
|
|
161 |
user.default_address_id = user.addresses[0].id
|
|
|
162 |
session.commit()
|
| 14819 |
amit.gupta |
163 |
|
|
|
164 |
if user_to_add.password == "":
|
|
|
165 |
add_private_deal_user(user.id)
|
| 557 |
chandransh |
166 |
return user
|
| 130 |
ashish |
167 |
|
|
|
168 |
#===============================================================================
|
|
|
169 |
# Need to provide the update apis here for relevant fields in PrimaryInfo.
|
|
|
170 |
#===============================================================================
|
| 557 |
chandransh |
171 |
def update_user(user_to_update):
|
| 594 |
rajveer |
172 |
if not user_to_update.userId:
|
| 415 |
ashish |
173 |
raise UserContextException(110, "user does not exist")
|
| 594 |
rajveer |
174 |
user = get_user_by_id(user_to_update.userId)
|
|
|
175 |
user.email = user_to_update.email
|
|
|
176 |
user.password = user_to_update.password
|
|
|
177 |
user.name = user_to_update.name
|
|
|
178 |
user.communication_email = user_to_update.communicationEmail
|
|
|
179 |
user.jsession_id = user_to_update.jsessionId
|
|
|
180 |
user.is_anonymous = user_to_update.isAnonymous
|
|
|
181 |
user.sex = user_to_update.sex
|
|
|
182 |
user.date_of_birth = user_to_update.dateOfBirth
|
|
|
183 |
user.mobile_number = user_to_update.mobileNumber
|
| 7883 |
rajveer |
184 |
if user_to_update.isFacebookUser:
|
| 7884 |
rajveer |
185 |
if user.fbusers and user.fbusers[0]:
|
|
|
186 |
fuser = user.fbusers[0]
|
|
|
187 |
else:
|
|
|
188 |
fuser = FacebookUser()
|
| 7883 |
rajveer |
189 |
if user_to_update.facebookAccessToken is not None:
|
|
|
190 |
fuser.facebook_access_token = user_to_update.facebookAccessToken
|
|
|
191 |
if user_to_update.facebookId is not None:
|
|
|
192 |
fuser.facebook_id = user_to_update.facebookId
|
|
|
193 |
fuser.user = user
|
| 415 |
ashish |
194 |
session.commit()
|
| 594 |
rajveer |
195 |
return user
|
| 415 |
ashish |
196 |
|
| 557 |
chandransh |
197 |
def authenticate_user(user_handle, password):
|
|
|
198 |
user = User.get_by(email=user_handle)
|
| 130 |
ashish |
199 |
if not user:
|
| 557 |
chandransh |
200 |
raise AuthenticationException("This email address is not registered.", 102)
|
| 130 |
ashish |
201 |
|
| 557 |
chandransh |
202 |
if user.password == get_db_password(password):
|
|
|
203 |
return user
|
| 130 |
ashish |
204 |
else:
|
|
|
205 |
raise AuthenticationException("Wrong username or password", 102)
|
|
|
206 |
|
|
|
207 |
def user_exists(email):
|
| 413 |
rajveer |
208 |
try:
|
| 557 |
chandransh |
209 |
user = User.get_by(email=email)
|
|
|
210 |
if user:
|
|
|
211 |
return True
|
|
|
212 |
else:
|
|
|
213 |
return False
|
| 413 |
rajveer |
214 |
except:
|
| 130 |
ashish |
215 |
return False
|
|
|
216 |
|
| 567 |
rajveer |
217 |
def add_address_for_user(address, user_id, set_default):
|
| 557 |
chandransh |
218 |
user = get_user_by_id(user_id)
|
| 766 |
rajveer |
219 |
|
| 130 |
ashish |
220 |
if not user:
|
|
|
221 |
raise_user_exception(user_id)
|
|
|
222 |
if not address:
|
|
|
223 |
raise UserContextException(103,"Address cannot be null")
|
|
|
224 |
|
|
|
225 |
address_to_add = Address()
|
|
|
226 |
address_to_add.line_1 = address.line1
|
|
|
227 |
address_to_add.line_2 = address.line2
|
|
|
228 |
address_to_add.landmark = address.landmark
|
|
|
229 |
address_to_add.city = address.city
|
|
|
230 |
address_to_add.country = address.country
|
|
|
231 |
address_to_add.state = address.state
|
|
|
232 |
address_to_add.pin = address.pin
|
|
|
233 |
address_to_add.type = address.type
|
| 414 |
ashish |
234 |
address_to_add.name = address.name
|
|
|
235 |
address_to_add.phone = address.phone
|
| 18966 |
amit.gupta |
236 |
address_to_add.added_on = datetime.datetime.now()
|
| 130 |
ashish |
237 |
address_to_add.enabled = True
|
| 557 |
chandransh |
238 |
address_to_add.user = user
|
| 130 |
ashish |
239 |
session.commit()
|
| 509 |
rajveer |
240 |
|
| 557 |
chandransh |
241 |
if set_default is True:
|
|
|
242 |
user.default_address_id = address_to_add.id
|
| 567 |
rajveer |
243 |
#set default address if nothing is default
|
|
|
244 |
if user.default_address_id is None:
|
|
|
245 |
user.default_address_id = address_to_add.id
|
|
|
246 |
|
| 557 |
chandransh |
247 |
session.commit()
|
| 513 |
rajveer |
248 |
|
| 567 |
rajveer |
249 |
return address_to_add.id
|
| 513 |
rajveer |
250 |
|
| 130 |
ashish |
251 |
def remove_address_for_user(user_id, address_id):
|
|
|
252 |
address = get_address(address_id)
|
|
|
253 |
|
|
|
254 |
if not address:
|
| 557 |
chandransh |
255 |
raise UserContextException(103, "Address not found")
|
|
|
256 |
if address.user.id != user_id:
|
|
|
257 |
raise UserContextException(104, "This address belongs to some other user")
|
| 130 |
ashish |
258 |
address.enabled = False
|
| 10714 |
amit.gupta |
259 |
user = User.get_by(id=user_id)
|
|
|
260 |
if user.default_address_id == address_id:
|
|
|
261 |
firstValidAddress = Address.query.filter_by(user_id = user_id, enabled=True).first()
|
|
|
262 |
if firstValidAddress is None:
|
|
|
263 |
user.default_address_id = None
|
|
|
264 |
else:
|
|
|
265 |
user.default_address_id = firstValidAddress.id
|
| 130 |
ashish |
266 |
session.commit()
|
|
|
267 |
return True
|
|
|
268 |
|
|
|
269 |
def set_user_as_logged_in(user_id, time_stamp):
|
| 5326 |
rajveer |
270 |
user = User.get_by(id=user_id)
|
| 130 |
ashish |
271 |
|
| 5326 |
rajveer |
272 |
if not user:
|
| 557 |
chandransh |
273 |
raise_user_exception(user_id)
|
| 130 |
ashish |
274 |
|
|
|
275 |
if not time_stamp:
|
| 5326 |
rajveer |
276 |
user.last_login = datetime.datetime.now()
|
| 557 |
chandransh |
277 |
else:
|
| 5326 |
rajveer |
278 |
user.last_login = to_py_date(time_stamp)
|
| 130 |
ashish |
279 |
session.commit()
|
|
|
280 |
return True
|
|
|
281 |
|
| 557 |
chandransh |
282 |
def set_user_as_logged_out(user_id, time_stamp):
|
| 5326 |
rajveer |
283 |
user = User.get_by(id=user_id)
|
| 130 |
ashish |
284 |
|
| 5326 |
rajveer |
285 |
if not user:
|
| 130 |
ashish |
286 |
raise_user_exception(user_id)
|
|
|
287 |
|
|
|
288 |
if not time_stamp:
|
| 5326 |
rajveer |
289 |
user.last_logout = datetime.datetime.now()
|
| 557 |
chandransh |
290 |
else:
|
| 5326 |
rajveer |
291 |
user.last_logout = to_py_date(time_stamp)
|
| 130 |
ashish |
292 |
session.commit()
|
|
|
293 |
return True
|
|
|
294 |
|
| 557 |
chandransh |
295 |
def set_default_address(user_id, address_id):
|
|
|
296 |
user = get_user_by_id(user_id)
|
|
|
297 |
address = Address.get_by(id=address_id)
|
|
|
298 |
if not user:
|
|
|
299 |
raise_user_exception(user_id)
|
|
|
300 |
if not address:
|
|
|
301 |
raise UserContextException(103, "Address not found")
|
|
|
302 |
if address.user.id != user.id:
|
|
|
303 |
raise UserContextException(104, "This address belongs to some other user")
|
|
|
304 |
|
|
|
305 |
user.default_address_id = address_id
|
|
|
306 |
session.commit()
|
|
|
307 |
|
| 594 |
rajveer |
308 |
def update_password(user_id, old_password, new_password):
|
| 557 |
chandransh |
309 |
user = get_user_by_id(user_id)
|
| 130 |
ashish |
310 |
|
|
|
311 |
if not user:
|
|
|
312 |
raise_user_exception(user_id)
|
|
|
313 |
|
| 594 |
rajveer |
314 |
if user.password != old_password:
|
|
|
315 |
return False
|
|
|
316 |
|
|
|
317 |
if check_for_valid_password(new_password):
|
|
|
318 |
user.password = get_db_password(new_password)
|
| 130 |
ashish |
319 |
session.commit()
|
|
|
320 |
return True
|
|
|
321 |
else:
|
|
|
322 |
return False
|
| 1273 |
varun.gupt |
323 |
|
|
|
324 |
|
|
|
325 |
def create_user_communication(user_id, email, communication_type, order_id, awb, product, subject, message):
|
|
|
326 |
|
|
|
327 |
user_communication = UserCommunication()
|
|
|
328 |
user_communication.user_id = user_id
|
|
|
329 |
user_communication.communication_type = communication_type
|
| 1743 |
varun.gupt |
330 |
|
|
|
331 |
if order_id > 0:
|
|
|
332 |
user_communication.order_id = order_id
|
| 1273 |
varun.gupt |
333 |
user_communication.airwaybill_no = awb
|
|
|
334 |
user_communication.reply_to = email
|
|
|
335 |
user_communication.product_name = product
|
|
|
336 |
user_communication.subject = subject
|
|
|
337 |
user_communication.message = message
|
| 1301 |
varun.gupt |
338 |
user_communication.communication_timestamp = datetime.datetime.now()
|
| 1273 |
varun.gupt |
339 |
session.commit()
|
| 3206 |
mandeep.dh |
340 |
return True
|
|
|
341 |
|
| 1583 |
varun.gupt |
342 |
def get_user_communication_by_id(user_communication_id):
|
|
|
343 |
return UserCommunication.get_by(id = user_communication_id)
|
|
|
344 |
|
|
|
345 |
def get_user_communication_by_user(user_communication_user_id):
|
| 1607 |
vikas |
346 |
return UserCommunication.query.filter_by(user_id = user_communication_user_id).order_by(-UserCommunication.id).all()
|
| 1583 |
varun.gupt |
347 |
|
|
|
348 |
def get_all_user_communications():
|
| 1863 |
vikas |
349 |
return UserCommunication.query.order_by(-UserCommunication.id).all()
|
| 1583 |
varun.gupt |
350 |
|
| 5407 |
amar.kumar |
351 |
def remove_user_communication(commId):
|
|
|
352 |
UserCommunication.query.filter_by(id=commId).delete()
|
|
|
353 |
session.commit()
|
|
|
354 |
|
| 1859 |
vikas |
355 |
def create_master_affiliate(name, added_on):
|
| 1845 |
vikas |
356 |
master_affiliate = MasterAffiliate()
|
|
|
357 |
master_affiliate.name = name
|
| 1859 |
vikas |
358 |
master_affiliate.added_on = to_py_date(added_on)
|
| 1845 |
vikas |
359 |
session.commit()
|
|
|
360 |
return master_affiliate
|
|
|
361 |
|
| 1899 |
vikas |
362 |
def get_all_master_affiliates():
|
|
|
363 |
return MasterAffiliate.query.all()
|
|
|
364 |
|
| 1845 |
vikas |
365 |
def get_master_affiliate_by_id(id):
|
|
|
366 |
return MasterAffiliate.get_by(id = id)
|
|
|
367 |
|
|
|
368 |
def get_master_affiliate_by_name(name):
|
|
|
369 |
return MasterAffiliate.get_by(name = name)
|
|
|
370 |
|
| 1859 |
vikas |
371 |
def create_affiliate(name, url, master_affiliate_id, added_on):
|
| 1845 |
vikas |
372 |
affiliate = Affiliate()
|
|
|
373 |
affiliate.name = name
|
|
|
374 |
if url is not None:
|
|
|
375 |
affiliate.url = url
|
|
|
376 |
affiliate.master_affiliate_id = master_affiliate_id
|
| 1859 |
vikas |
377 |
affiliate.added_on = to_py_date(added_on)
|
| 1845 |
vikas |
378 |
session.commit()
|
|
|
379 |
return affiliate
|
|
|
380 |
|
|
|
381 |
def get_affiliate_by_id(id):
|
|
|
382 |
return Affiliate.get_by(id = id)
|
|
|
383 |
|
|
|
384 |
def get_affiliate_by_name(name):
|
|
|
385 |
return Affiliate.get_by(name = name)
|
|
|
386 |
|
|
|
387 |
def get_affiliates_by_master_affiliate(master_affiliate_id):
|
|
|
388 |
return MasterAffiliate.get_by(id = master_affiliate_id).affiliates
|
|
|
389 |
|
|
|
390 |
def get_tracker_by_id(id):
|
|
|
391 |
return Tracker.get_by(id = id)
|
|
|
392 |
|
| 1996 |
vikas |
393 |
def add_track_log(affiliate_id, user_id, event, url, data, added_on):
|
| 1845 |
vikas |
394 |
track_log = TrackLog()
|
| 1996 |
vikas |
395 |
track_log.affiliate_id = affiliate_id
|
| 1845 |
vikas |
396 |
if user_id:
|
|
|
397 |
track_log.user_id = user_id
|
| 3378 |
vikas |
398 |
track_log.event_id = event
|
| 1845 |
vikas |
399 |
if url:
|
|
|
400 |
track_log.url = url
|
|
|
401 |
if data:
|
| 1859 |
vikas |
402 |
track_log.data = data
|
|
|
403 |
track_log.added_on = to_py_date(added_on)
|
| 1845 |
vikas |
404 |
session.commit()
|
|
|
405 |
return track_log.id
|
|
|
406 |
|
|
|
407 |
def get_track_log_by_id(id):
|
|
|
408 |
return TrackLog.get_by(id = id)
|
|
|
409 |
|
| 3293 |
vikas |
410 |
def get_track_logs_by_affiliate(affiliate_id, start_date, end_date):
|
|
|
411 |
query = TrackLog.query
|
|
|
412 |
|
|
|
413 |
if affiliate_id:
|
|
|
414 |
query = query.filter(TrackLog.affiliate_id == affiliate_id)
|
|
|
415 |
if start_date:
|
|
|
416 |
query = query.filter(TrackLog.added_on >= to_py_date(start_date))
|
|
|
417 |
if end_date:
|
|
|
418 |
query = query.filter(TrackLog.added_on <= to_py_date(end_date))
|
|
|
419 |
return query.all()
|
| 1845 |
vikas |
420 |
|
|
|
421 |
def get_track_logs_by_user(user_id):
|
|
|
422 |
return TrackLog.query.filter(TrackLog.user_id == user_id).all()
|
|
|
423 |
|
| 1996 |
vikas |
424 |
def get_track_logs(affiliate_id, user_id, event, url):
|
| 1845 |
vikas |
425 |
query = TrackLog.query
|
|
|
426 |
|
| 1996 |
vikas |
427 |
if affiliate_id:
|
|
|
428 |
query = query.filter(TrackLog.affiliate_id == affiliate_id)
|
|
|
429 |
if user_id:
|
|
|
430 |
query = query.filter(TrackLog.user_id == user_id)
|
| 1845 |
vikas |
431 |
if event:
|
|
|
432 |
query = query.filter(TrackLog.event == event)
|
|
|
433 |
if url:
|
|
|
434 |
query = query.filter(TrackLog.url == url)
|
|
|
435 |
return query.all()
|
|
|
436 |
|
|
|
437 |
|
| 557 |
chandransh |
438 |
def get_address(address_id):
|
|
|
439 |
address = Address.get_by(id=address_id)
|
| 18735 |
manish.sha |
440 |
addressMapping = PrivateDealUserAddressMapping.query.filter_by(user_id = address.user_id,address_id=address_id).first()
|
|
|
441 |
if addressMapping is None:
|
|
|
442 |
return address, {}, {}
|
|
|
443 |
else:
|
|
|
444 |
return address, {address_id:addressMapping.taxInvoiceAvailable}, {address_id:addressMapping.creditOptionAvailable}
|
| 557 |
chandransh |
445 |
|
| 19889 |
manas |
446 |
def get_counter_name(user_ids):
|
|
|
447 |
result = session.query(PrivateDealUserAddressMapping,Address).join((Address,PrivateDealUserAddressMapping.address_id==Address.id)).filter(PrivateDealUserAddressMapping.user_id.in_(user_ids)).filter(PrivateDealUserAddressMapping.creditOptionAvailable==1).all()
|
|
|
448 |
userCounterMap = {}
|
|
|
449 |
if result is not None:
|
|
|
450 |
for r in result:
|
|
|
451 |
if userCounterMap.has_key(r.PrivateDealUserAddressMapping.user_id):
|
|
|
452 |
pass
|
|
|
453 |
else:
|
|
|
454 |
userCounterMap[r.PrivateDealUserAddressMapping.user_id] = r.Address.name
|
|
|
455 |
return userCounterMap
|
|
|
456 |
|
| 884 |
rajveer |
457 |
def forgot_password(email, password):
|
|
|
458 |
try:
|
|
|
459 |
user = User.get_by(email=email)
|
|
|
460 |
if user:
|
|
|
461 |
user.password = password
|
| 900 |
rajveer |
462 |
session.commit()
|
| 884 |
rajveer |
463 |
return True
|
|
|
464 |
else:
|
|
|
465 |
return False
|
|
|
466 |
except:
|
|
|
467 |
return False
|
|
|
468 |
|
| 594 |
rajveer |
469 |
def get_all_addresses_for_user(userId):
|
| 18735 |
manish.sha |
470 |
addresses = Address.query.filter_by(user_id = userId, enabled=True).all()
|
| 18530 |
manish.sha |
471 |
privateDealUser = get_private_deal_user(userId)
|
| 18735 |
manish.sha |
472 |
taxInvoiceMap = {}
|
|
|
473 |
creditOptionMap = {}
|
| 18530 |
manish.sha |
474 |
if privateDealUser is None:
|
| 18735 |
manish.sha |
475 |
return addresses, taxInvoiceMap, creditOptionMap
|
|
|
476 |
else:
|
|
|
477 |
addressMappings = PrivateDealUserAddressMapping.query.filter_by(user_id = userId).all()
|
|
|
478 |
for mapping in addressMappings:
|
|
|
479 |
taxInvoiceMap[mapping.address_id] = mapping.taxInvoiceAvailable
|
|
|
480 |
creditOptionMap[mapping.address_id] = mapping.creditOptionAvailable
|
|
|
481 |
for address in addresses:
|
|
|
482 |
if not taxInvoiceMap.has_key(address.id):
|
|
|
483 |
taxInvoiceMap[address.id] = False
|
|
|
484 |
if not creditOptionMap.has_key(address.id):
|
|
|
485 |
creditOptionMap[address.id] = False
|
|
|
486 |
return addresses, taxInvoiceMap, creditOptionMap
|
|
|
487 |
'''
|
|
|
488 |
privateDealUser = get_private_deal_user(userId)
|
|
|
489 |
if privateDealUser is None:
|
| 18530 |
manish.sha |
490 |
return Address.query.filter_by(user_id = userId, enabled=True).all()
|
|
|
491 |
else:
|
| 18634 |
manish.sha |
492 |
if privateDealUser.counter:
|
|
|
493 |
if privateDealUser.counter.documentVerified:
|
|
|
494 |
return Address.query.filter_by(user_id = userId, enabled=True).all()
|
|
|
495 |
else:
|
|
|
496 |
return Address.query.filter_by(id=privateDealUser.counter.addressId).all()
|
|
|
497 |
return Address.query.filter_by(user_id = userId, enabled=True).all()
|
| 18735 |
manish.sha |
498 |
'''
|
| 581 |
rajveer |
499 |
|
| 785 |
rajveer |
500 |
def get_default_address_id(userId):
|
| 18603 |
manish.sha |
501 |
user = get_user_by_id(userId)
|
| 18735 |
manish.sha |
502 |
if user is None:
|
|
|
503 |
return 0
|
|
|
504 |
if user.default_address_id is None:
|
|
|
505 |
return 0
|
|
|
506 |
return user.default_address_id
|
|
|
507 |
'''
|
| 18530 |
manish.sha |
508 |
privateDealUser = get_private_deal_user(userId)
|
|
|
509 |
if privateDealUser is None:
|
|
|
510 |
if user.default_address_id is None:
|
|
|
511 |
return 0
|
|
|
512 |
else:
|
| 18603 |
manish.sha |
513 |
if privateDealUser.counter:
|
| 18634 |
manish.sha |
514 |
return privateDealUser.counter.addressId
|
|
|
515 |
else:
|
|
|
516 |
if user.default_address_id is None:
|
|
|
517 |
return 0
|
|
|
518 |
return user.default_address_id
|
| 18735 |
manish.sha |
519 |
'''
|
| 581 |
rajveer |
520 |
|
| 785 |
rajveer |
521 |
def get_default_pincode(user_id):
|
| 18740 |
manish.sha |
522 |
user = get_user_by_id(user_id)
|
|
|
523 |
if not user:
|
|
|
524 |
raise_user_exception(user_id)
|
|
|
525 |
default_address_id = user.default_address_id
|
|
|
526 |
if default_address_id:
|
|
|
527 |
address = Address.get_by(id=default_address_id)
|
|
|
528 |
default_pincode = address.pin
|
|
|
529 |
else:
|
|
|
530 |
default_pincode = '110001'
|
|
|
531 |
return default_pincode
|
|
|
532 |
'''
|
| 18646 |
manish.sha |
533 |
default_address_id = get_default_address_id(user_id)
|
| 785 |
rajveer |
534 |
if default_address_id:
|
|
|
535 |
address = Address.get_by(id=default_address_id)
|
|
|
536 |
default_pincode = address.pin
|
|
|
537 |
else:
|
| 18646 |
manish.sha |
538 |
default_pincode = '110001'
|
| 18740 |
manish.sha |
539 |
return default_pincode
|
|
|
540 |
'''
|
| 1596 |
ankur.sing |
541 |
|
|
|
542 |
def get_user_count(user_type):
|
|
|
543 |
if user_type is None:
|
|
|
544 |
return User.query.count()
|
|
|
545 |
else:
|
|
|
546 |
return User.query.filter_by(is_anonymous = user_type).count()
|
| 785 |
rajveer |
547 |
|
| 1891 |
ankur.sing |
548 |
def get_users(user_type, start_date, end_date):
|
| 5326 |
rajveer |
549 |
query = session.query(User)
|
| 1891 |
ankur.sing |
550 |
if start_date != -1:
|
| 5326 |
rajveer |
551 |
query = query.filter(User.active_since >= to_py_date(start_date))
|
| 1891 |
ankur.sing |
552 |
if end_date != -1:
|
| 5326 |
rajveer |
553 |
query = query.filter(User.active_since <= to_py_date(end_date))
|
| 1891 |
ankur.sing |
554 |
if user_type is not None:
|
|
|
555 |
query = query.filter(User.is_anonymous == user_type)
|
|
|
556 |
return query.all()
|
| 1673 |
ankur.sing |
557 |
|
| 130 |
ashish |
558 |
#=============================================================================
|
|
|
559 |
# Helper functions
|
|
|
560 |
#=============================================================================
|
|
|
561 |
|
|
|
562 |
'''
|
|
|
563 |
This function returns the password as stored in the db
|
|
|
564 |
'''
|
|
|
565 |
def get_db_password(password):
|
|
|
566 |
return password
|
|
|
567 |
|
|
|
568 |
def check_for_valid_password(password):
|
|
|
569 |
if not password:
|
|
|
570 |
raise UserContextException(105,"password cannot be null")
|
|
|
571 |
return True
|
|
|
572 |
#------------------------------------------------------------------------------
|
|
|
573 |
|
|
|
574 |
#===============================================================================
|
|
|
575 |
# raises the UserContextException
|
|
|
576 |
#===============================================================================
|
|
|
577 |
def raise_user_exception(user_id):
|
| 766 |
rajveer |
578 |
raise UserContextException(101, "no such user in system %d" %(user_id))
|
|
|
579 |
|
| 2981 |
rajveer |
580 |
def get_my_research_items(userId):
|
|
|
581 |
query = UserWidgetItem.query.filter_by(userId=userId)
|
|
|
582 |
query = query.filter_by(widgetId=WType.MY_RESEARCH)
|
|
|
583 |
query = query.order_by(desc(UserWidgetItem.addedOn))
|
|
|
584 |
widgetItems = query.all()
|
|
|
585 |
return [widgetItem.itemId for widgetItem in widgetItems]
|
|
|
586 |
|
|
|
587 |
def get_browse_history_items(userId):
|
|
|
588 |
query = UserWidgetItem.query.filter_by(userId=userId)
|
|
|
589 |
query = query.filter_by(widgetId=WType.BROWSE_HISTORY)
|
|
|
590 |
query = query.order_by(desc(UserWidgetItem.addedOn)).limit(10)
|
|
|
591 |
widgetItems = query.all()
|
|
|
592 |
return [widgetItem.itemId for widgetItem in widgetItems]
|
|
|
593 |
|
|
|
594 |
def update_my_research(userId, itemId):
|
|
|
595 |
isNew = False
|
|
|
596 |
query = UserWidgetItem.query.filter_by(userId=userId)
|
|
|
597 |
query = query.filter_by(widgetId=WType.MY_RESEARCH)
|
|
|
598 |
query = query.filter_by(itemId=itemId)
|
|
|
599 |
widgetItem = query.first()
|
|
|
600 |
if not widgetItem:
|
|
|
601 |
isNew = True
|
|
|
602 |
widgetItem = UserWidgetItem()
|
|
|
603 |
widgetItem.userId = userId
|
|
|
604 |
widgetItem.widgetId = WType.MY_RESEARCH
|
|
|
605 |
widgetItem.itemId = itemId
|
|
|
606 |
widgetItem.addedOn = datetime.datetime.now()
|
|
|
607 |
session.commit()
|
|
|
608 |
return isNew
|
|
|
609 |
|
|
|
610 |
def update_browse_history(userId, itemId):
|
|
|
611 |
query = UserWidgetItem.query.filter_by(userId=userId)
|
|
|
612 |
query = query.filter_by(widgetId=WType.BROWSE_HISTORY)
|
|
|
613 |
query = query.filter_by(itemId=itemId)
|
|
|
614 |
widgetItem = query.first()
|
|
|
615 |
if not widgetItem:
|
|
|
616 |
widgetItem = UserWidgetItem()
|
|
|
617 |
widgetItem.userId = userId
|
|
|
618 |
widgetItem.widgetId = WType.BROWSE_HISTORY
|
|
|
619 |
widgetItem.itemId = itemId
|
|
|
620 |
widgetItem.addedOn = datetime.datetime.now()
|
|
|
621 |
session.commit()
|
|
|
622 |
|
|
|
623 |
def delete_item_from_my_research(userId, itemId):
|
|
|
624 |
query = UserWidgetItem.query.filter_by(userId=userId)
|
|
|
625 |
query = query.filter_by(widgetId=WType.MY_RESEARCH)
|
|
|
626 |
query = query.filter_by(itemId=itemId)
|
|
|
627 |
widgetItem = query.first()
|
|
|
628 |
if widgetItem:
|
|
|
629 |
widgetItem.delete()
|
|
|
630 |
session.commit()
|
|
|
631 |
else:
|
| 11499 |
amit.gupta |
632 |
print "Not item in my research to delete with itemId " + str(itemId)
|
| 2981 |
rajveer |
633 |
|
| 3499 |
mandeep.dh |
634 |
def increase_trust_level(userId, trustLevelDelta):
|
|
|
635 |
user = User.query.filter_by(id = userId).with_lockmode('update').first()
|
|
|
636 |
user.trust_level += trustLevelDelta
|
|
|
637 |
session.commit()
|
|
|
638 |
|
| 5407 |
amar.kumar |
639 |
def get_trust_level(userId):
|
|
|
640 |
user = User.query.filter_by(id = userId).first()
|
|
|
641 |
return user.trust_level
|
| 5623 |
anupam.sin |
642 |
|
|
|
643 |
def get_user_emails(start_date, end_date):
|
|
|
644 |
emails = select([User.table.c.communication_email], and_(User.table.c.active_since >= start_date, User.table.c.active_since <= end_date, User.table.c.is_anonymous==0)).execute()
|
|
|
645 |
email_addresses = []
|
| 5407 |
amar.kumar |
646 |
|
| 5623 |
anupam.sin |
647 |
for email in emails:
|
|
|
648 |
email_addresses.append(str(email[0]))
|
|
|
649 |
|
|
|
650 |
return email_addresses
|
| 7825 |
amar.kumar |
651 |
|
| 11679 |
vikram.rag |
652 |
def is_private_deal_user(userId):
|
|
|
653 |
try:
|
| 18608 |
amit.gupta |
654 |
user = PrivateDealUser.get_by(id=userId)
|
| 11679 |
vikram.rag |
655 |
if user is None:
|
|
|
656 |
return False
|
|
|
657 |
elif not user.isActive:
|
|
|
658 |
return False
|
|
|
659 |
else:
|
|
|
660 |
return True
|
|
|
661 |
except:
|
|
|
662 |
print("Error : Unable to get details for User Id : " + str(userId))
|
|
|
663 |
return False
|
|
|
664 |
finally:
|
|
|
665 |
close_session()
|
|
|
666 |
|
| 11890 |
kshitij.so |
667 |
def add_private_deal_user(userId):
|
| 18608 |
amit.gupta |
668 |
user = PrivateDealUser.get_by(id=userId)
|
| 11890 |
kshitij.so |
669 |
if user is None:
|
|
|
670 |
try:
|
|
|
671 |
pd = PrivateDealUser()
|
|
|
672 |
pd.id = userId
|
|
|
673 |
pd.created_on = datetime.datetime.now()
|
|
|
674 |
pd.isActive = True
|
| 13401 |
manish.sha |
675 |
pd.bulkShipmentAmountLimit=50000
|
| 18590 |
manish.sha |
676 |
pd.creditorAssigned = False
|
| 18735 |
manish.sha |
677 |
pd.tinVerified = False
|
| 11890 |
kshitij.so |
678 |
session.commit()
|
|
|
679 |
return True
|
|
|
680 |
except Exception as e:
|
|
|
681 |
print "Unable to add user to private deals",e
|
|
|
682 |
return False
|
|
|
683 |
else:
|
| 13661 |
amit.gupta |
684 |
return True
|
| 11679 |
vikram.rag |
685 |
|
| 11890 |
kshitij.so |
686 |
def change_private_deal_user_status(userId,isActive):
|
| 18608 |
amit.gupta |
687 |
user = PrivateDealUser.get_by(id=userId)
|
| 11890 |
kshitij.so |
688 |
if user is None:
|
|
|
689 |
return False
|
|
|
690 |
else:
|
|
|
691 |
user.isActive = isActive
|
|
|
692 |
session.commit()
|
|
|
693 |
return True
|
|
|
694 |
|
|
|
695 |
def get_private_deal_user(userId):
|
| 18608 |
amit.gupta |
696 |
return PrivateDealUser.get_by(id=userId)
|
| 11890 |
kshitij.so |
697 |
|
| 12696 |
amit.gupta |
698 |
def register_counter(tCounter, userId):
|
| 18951 |
amit.gupta |
699 |
try:
|
|
|
700 |
firstValidAddress = Address.query.filter_by(id=tCounter.address).first()
|
|
|
701 |
except:
|
|
|
702 |
pass
|
|
|
703 |
if not firstValidAddress:
|
|
|
704 |
firstValidAddress = Address.query.filter_by(user_id = userId, enabled=True).first()
|
| 12696 |
amit.gupta |
705 |
counter = Counter()
|
|
|
706 |
_setCounter(counter, tCounter, firstValidAddress)
|
| 18951 |
amit.gupta |
707 |
pDealUser = PrivateDealUser.query.filter_by(id=userId).first()
|
|
|
708 |
if not pDealUser:
|
|
|
709 |
pDealUser = PrivateDealUser()
|
|
|
710 |
pDealUser.created_on = datetime.datetime.now()
|
|
|
711 |
pDealUser.bulkShipmentAmountLimit=50000
|
| 12696 |
amit.gupta |
712 |
pDealUser.counter = counter
|
| 18951 |
amit.gupta |
713 |
pDealUser.tinVerified = True if tCounter.documentVerified else False
|
| 12696 |
amit.gupta |
714 |
pDealUser.tin = tCounter.tin
|
|
|
715 |
pDealUser.isActive = True
|
|
|
716 |
session.commit()
|
|
|
717 |
m = {}
|
|
|
718 |
m['counter_code'] = counter.code
|
|
|
719 |
return m
|
|
|
720 |
|
|
|
721 |
def _setCounter(counter,tCounter,address):
|
|
|
722 |
counter.name = tCounter.name
|
|
|
723 |
counter.ownerName = tCounter.ownerName
|
|
|
724 |
counter.createdOn = datetime.datetime.now()
|
|
|
725 |
counter.email = tCounter.email
|
|
|
726 |
counter.mobile = tCounter.mobile
|
|
|
727 |
counter.addressId = address.id
|
| 12790 |
amit.gupta |
728 |
counter.dob = tCounter.dob
|
| 21908 |
amit.gupta |
729 |
counter.gstin = tCounter.gstin
|
| 18951 |
amit.gupta |
730 |
counter.documentVerified = tCounter.documentVerified
|
| 21967 |
amit.gupta |
731 |
# if counter.documentVerified:
|
|
|
732 |
# pduaddress = PrivateDealUserAddressMapping()
|
|
|
733 |
# pduaddress.address_id = address.id
|
|
|
734 |
# pduaddress.creditOptionAvailable = False
|
|
|
735 |
# pduaddress.user_id = address.user_id
|
|
|
736 |
# if address.state in tinStates:
|
|
|
737 |
# pduaddress.taxInvoiceAvailable = True
|
|
|
738 |
# else:
|
|
|
739 |
# pduaddress.taxInvoiceAvailable = False
|
| 18951 |
amit.gupta |
740 |
counter.verificationType = tCounter.verificationType
|
|
|
741 |
counter.verifiedOn = datetime.datetime.now()
|
| 12696 |
amit.gupta |
742 |
query = Counter.query.filter(Counter.code.like(CounterStateMap[address.state] + '%')).order_by(Counter.id.desc())
|
|
|
743 |
lastStateCounter = query.first()
|
|
|
744 |
if lastStateCounter:
|
| 12698 |
amit.gupta |
745 |
counter.code = CounterStateMap[address.state] + str(int(lastStateCounter.code[2:])+1).zfill(6)
|
| 12696 |
amit.gupta |
746 |
else:
|
| 12698 |
amit.gupta |
747 |
counter.code = CounterStateMap[address.state] + "000001"
|
| 12696 |
amit.gupta |
748 |
counter.striker = tCounter.striker
|
|
|
749 |
if tCounter.alternateMobile:
|
|
|
750 |
counter.alternateMobile = tCounter.alternateMobile
|
|
|
751 |
if tCounter.spCounterSize:
|
|
|
752 |
counter.spCounterSize = tCounter.spCounterSize
|
|
|
753 |
if tCounter.fpCounterSize:
|
|
|
754 |
counter.fpCounterSize = tCounter.fpCounterSize
|
| 12722 |
amit.gupta |
755 |
|
|
|
756 |
def search_counter(type1, searchString):
|
|
|
757 |
if type1=="counter_code":
|
|
|
758 |
return Counter.query.filter(Counter.code==searchString).all()
|
|
|
759 |
elif type1=="mobile":
|
|
|
760 |
return Counter.query.filter(or_(Counter.alternateMobile==searchString, Counter.mobile==searchString)).all()
|
|
|
761 |
elif type1=="email":
|
|
|
762 |
return Counter.query.filter(Counter.email==searchString).all()
|
|
|
763 |
elif type1=="counter_name":
|
|
|
764 |
return Counter.query.filter(Counter.name.like("%" + searchString + "%")).all()
|
| 18982 |
amit.gupta |
765 |
elif type1=="tin":
|
|
|
766 |
return Counter.query.filter(Counter.tin==searchString).all()
|
| 12722 |
amit.gupta |
767 |
else:
|
|
|
768 |
return []
|
| 18977 |
amit.gupta |
769 |
def get_counter_by_user_id(user_id):
|
|
|
770 |
pdu = PrivateDealUser.query.filter(PrivateDealUser.id==user_id).first()
|
|
|
771 |
if pdu is None:
|
|
|
772 |
return None
|
|
|
773 |
else:
|
|
|
774 |
return pdu.counter
|
| 12722 |
amit.gupta |
775 |
|
|
|
776 |
def get_all_users_by_counter(counterid):
|
|
|
777 |
dealers = PrivateDealUser.query.filter(PrivateDealUser.counter_id == counterid).all()
|
|
|
778 |
dealerids = [dealer.id for dealer in dealers]
|
|
|
779 |
print dealerids
|
|
|
780 |
if len(dealerids) > 0:
|
|
|
781 |
return User.query.filter(User.id.in_(dealerids)).all()
|
|
|
782 |
return []
|
|
|
783 |
|
| 15251 |
manish.sha |
784 |
def get_active_access_token_for_user(userId, source):
|
|
|
785 |
user = get_private_deal_user(userId)
|
|
|
786 |
if user is not None:
|
|
|
787 |
accessTokenObj = AccessTokenizer.query.filter(AccessTokenizer.userId==userId).filter(AccessTokenizer.source==source).filter(AccessTokenizer.expired==False).filter(AccessTokenizer.expiredTime>datetime.datetime.now()).first()
|
|
|
788 |
if accessTokenObj is not None:
|
|
|
789 |
return accessTokenObj.tokenString
|
|
|
790 |
else:
|
|
|
791 |
accessTokenObj = AccessTokenizer()
|
|
|
792 |
accessTokenObj.userId = userId
|
|
|
793 |
accessTokenObj.source = source
|
|
|
794 |
accessTokenObj.tokenString = binascii.b2a_hex(os.urandom(15))
|
|
|
795 |
accessTokenObj.expiredTime = datetime.datetime.now()+datetime.timedelta(minutes=10)
|
|
|
796 |
accessTokenObj.expired = False
|
|
|
797 |
session.commit()
|
|
|
798 |
return accessTokenObj.tokenString
|
|
|
799 |
else:
|
|
|
800 |
return 'Invalid User'
|
|
|
801 |
|
|
|
802 |
def validate_access_token(accessToken):
|
|
|
803 |
accessTokenObj = AccessTokenizer.query.filter(AccessTokenizer.tokenString==accessToken).filter(AccessTokenizer.expired==False).filter(AccessTokenizer.expiredTime>datetime.datetime.now()).first()
|
|
|
804 |
if accessTokenObj is not None:
|
|
|
805 |
accessTokenObj.expired = True
|
|
|
806 |
session.commit()
|
|
|
807 |
return True
|
|
|
808 |
else:
|
|
|
809 |
return False
|
| 12722 |
amit.gupta |
810 |
|
| 18634 |
manish.sha |
811 |
def is_address_editable_for_counter(userId):
|
| 18530 |
manish.sha |
812 |
privateDealUser = get_private_deal_user(userId)
|
|
|
813 |
if privateDealUser is None:
|
| 18634 |
manish.sha |
814 |
return True
|
| 18530 |
manish.sha |
815 |
else:
|
| 18634 |
manish.sha |
816 |
if privateDealUser.counter:
|
|
|
817 |
if privateDealUser.counter.documentVerified:
|
|
|
818 |
return True
|
|
|
819 |
else:
|
|
|
820 |
return False
|
|
|
821 |
return True
|
| 18530 |
manish.sha |
822 |
|
|
|
823 |
def get_billing_address_for_user(userId):
|
|
|
824 |
privateDealUser = get_private_deal_user(userId)
|
| 18656 |
amit.gupta |
825 |
if privateDealUser is None:
|
| 18743 |
manish.sha |
826 |
return None, {}, {}
|
| 18656 |
amit.gupta |
827 |
if privateDealUser.counter:
|
|
|
828 |
return get_address(privateDealUser.counter.addressId)
|
| 18530 |
manish.sha |
829 |
else:
|
| 18743 |
manish.sha |
830 |
return None, {}, {}
|
| 12696 |
amit.gupta |
831 |
|
| 18590 |
manish.sha |
832 |
def is_creditor_assigned(userId):
|
|
|
833 |
try:
|
|
|
834 |
privateDealUser = get_private_deal_user(userId)
|
|
|
835 |
if privateDealUser.creditorAssigned:
|
|
|
836 |
return True
|
|
|
837 |
else:
|
|
|
838 |
return False
|
|
|
839 |
except:
|
|
|
840 |
return False
|
|
|
841 |
|
| 18735 |
manish.sha |
842 |
def is_tax_invoice_enabled_user(userId):
|
|
|
843 |
try:
|
|
|
844 |
privateDealUser = get_private_deal_user(userId)
|
|
|
845 |
if privateDealUser.tin and privateDealUser.tinVerified:
|
|
|
846 |
return True
|
|
|
847 |
else:
|
|
|
848 |
return False
|
|
|
849 |
except:
|
|
|
850 |
return False
|
| 18764 |
kshitij.so |
851 |
|
| 19182 |
amit.gupta |
852 |
def tax_invoice_available(address_id):
|
|
|
853 |
addressMapping = PrivateDealUserAddressMapping.query.filter_by(address_id=address_id).first()
|
|
|
854 |
return True if addressMapping and addressMapping.taxInvoiceAvailable else False
|
|
|
855 |
|
| 18764 |
kshitij.so |
856 |
def get_cart_by_value(cartIds):
|
|
|
857 |
returnMap = {}
|
|
|
858 |
lines = Line.query.filter(Line.cart_id.in_(cartIds)).all()
|
|
|
859 |
for line in lines:
|
|
|
860 |
if returnMap.has_key(line.cart_id):
|
|
|
861 |
returnMap.get(line.cart_id).append(to_t_line(line))
|
|
|
862 |
else:
|
|
|
863 |
returnMap[line.cart_id] = [to_t_line(line)]
|
|
|
864 |
return returnMap
|
| 18735 |
manish.sha |
865 |
|
| 766 |
rajveer |
866 |
def close_session():
|
|
|
867 |
if session.is_active:
|
|
|
868 |
print "session is active. closing it."
|
| 3376 |
rajveer |
869 |
session.close()
|
|
|
870 |
|
|
|
871 |
def is_alive():
|
|
|
872 |
try:
|
|
|
873 |
session.query(User.id).limit(1).one()
|
|
|
874 |
return True
|
|
|
875 |
except:
|
| 18764 |
kshitij.so |
876 |
return False
|
|
|
877 |
|
|
|
878 |
if __name__ == '__main__':
|
|
|
879 |
Dataservice.initialize()
|
| 19889 |
manas |
880 |
print (get_cart_by_value([1005394]))
|