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