Subversion Repositories SmartDukaan

Rev

Rev 6389 | Rev 6821 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
130 ashish 1
'''
2
Created on 28-Apr-2010
3
 
4
@author: ashish
5
'''
5623 anupam.sin 6
from shop2020.utils.Utils import log_entry, to_py_date
1491 vikas 7
from shop2020.model.v1.user.impl.UserDataAccessors import create_user, update_user, get_user_by_id, get_user_by_email, update_password,\
557 chandransh 8
    set_user_as_logged_out, set_user_as_logged_in, remove_address_for_user,\
5326 rajveer 9
    add_address_for_user, authenticate_user, user_exists, initialize, set_default_address,\
1894 vikas 10
    create_anonymous_user, forgot_password, get_all_addresses_for_user, get_address, get_default_address_id, get_default_pincode,\
1845 vikas 11
    create_user_communication, get_user_communication_by_id, get_user_communication_by_user, get_all_user_communications,\
1996 vikas 12
    create_affiliate, get_affiliate_by_id, get_affiliate_by_name, get_tracker_by_id, add_track_log, get_track_log_by_id, get_track_logs_by_affiliate,\
13
    get_track_logs_by_user, get_track_logs, create_master_affiliate,\
2641 varun.gupt 14
    get_master_affiliate_by_id, get_master_affiliate_by_name, get_affiliates_by_master_affiliate, get_all_master_affiliates,\
6394 amit.gupta 15
    get_my_research_items,\
2981 rajveer 16
    get_browse_history_items, update_my_research, delete_item_from_my_research,\
5326 rajveer 17
    update_browse_history, get_user_by_mobile_number, is_alive, increase_trust_level,\
5623 anupam.sin 18
    get_user_by_cart_id, get_trust_level, remove_user_communication,\
19
    get_user_emails
3032 mandeep.dh 20
 
557 chandransh 21
from shop2020.model.v1.user.impl.CartDataAccessors import create_cart, get_cart,\
5326 rajveer 22
    get_cart_by_id, get_carts_between, add_item_to_cart,\
23
    add_address_to_cart, commit_cart,\
1976 varun.gupt 24
    validate_cart, merge_cart, delete_item_from_cart, check_out, reset_cart,\
3554 varun.gupt 25
    apply_coupon_to_cart, remove_coupon, get_carts_with_coupon_count,\
5555 rajveer 26
    delete_discounts_from_cart, save_discounts, show_cod_option,\
27
    add_store_to_cart
5326 rajveer 28
from shop2020.model.v1.user.impl.Converters import to_t_user, to_t_cart, to_t_address, to_t_user_communication,\
6394 amit.gupta 29
     to_t_master_affiliate, to_t_affiliate, to_t_tracker, to_t_track_log
576 chandransh 30
 
557 chandransh 31
from shop2020.thriftpy.model.v1.user.ttypes import ShoppingCartException
130 ashish 32
 
2981 rajveer 33
from shop2020.model.v1.user.impl import UserDataAccessors, CartDataAccessors
5623 anupam.sin 34
#from apport.hookutils import ret
557 chandransh 35
 
130 ashish 36
class UserContextServiceHandler:
37
 
404 rajveer 38
 
3187 rajveer 39
    def __init__(self, dbname='user', db_hostname='localhost'):
40
        initialize(dbname, db_hostname)
557 chandransh 41
 
130 ashish 42
    """
557 chandransh 43
    service
130 ashish 44
    """
557 chandransh 45
    def createAnonymousUser(self, jsessionId):
766 rajveer 46
        try:
5326 rajveer 47
            return to_t_user(create_anonymous_user(jsessionId))
766 rajveer 48
        finally:
4323 mandeep.dh 49
            self.closeSession()
4211 mandeep.dh 50
 
557 chandransh 51
    def getUserById(self, userId):
130 ashish 52
        """
53
        Parameters:
557 chandransh 54
        - userId
130 ashish 55
        """
766 rajveer 56
        try:
57
            return to_t_user(get_user_by_id(userId))
58
        finally:
4323 mandeep.dh 59
            self.closeSession()
1491 vikas 60
 
5326 rajveer 61
    def getUserByCartId(self, cartId):
62
        """
63
        Parameters:
64
        - cartId
65
        """
66
        try:
67
            return to_t_user(get_user_by_cart_id(cartId))
68
        finally:
69
            self.closeSession()
70
 
3032 mandeep.dh 71
    def getUserByMobileNumber(self, mobileNumber):
72
        """
73
        Parameters:
74
        - mobileNumber
75
        """
76
        try:
77
            return to_t_user(get_user_by_mobile_number(mobileNumber))
78
        finally:
4323 mandeep.dh 79
            self.closeSession()
3032 mandeep.dh 80
 
1491 vikas 81
    def getUserByEmail(self, email):
82
        """
83
        Parameters:
84
         - email
85
        """
86
        try:
87
            return to_t_user(get_user_by_email(email))
88
        finally:
4323 mandeep.dh 89
            self.closeSession()
1491 vikas 90
 
557 chandransh 91
    def createUser(self, user):
130 ashish 92
        """
93
        Parameters:
557 chandransh 94
        - user
130 ashish 95
        """
766 rajveer 96
        try:
5326 rajveer 97
            return to_t_user(create_user(user))
766 rajveer 98
        finally:
4323 mandeep.dh 99
            self.closeSession()
100
 
557 chandransh 101
    def updateUser(self, user):
130 ashish 102
        """
103
        Parameters:
557 chandransh 104
        - user
130 ashish 105
        """
766 rajveer 106
        try:
107
            return to_t_user(update_user(user))
108
        finally:
4323 mandeep.dh 109
            self.closeSession()
766 rajveer 110
 
557 chandransh 111
    def authenticateUser(self, email, password):
130 ashish 112
        """
113
        Parameters:
557 chandransh 114
        - email
115
        - password
116
        """
117
        log_entry(self, "authenticate user")
766 rajveer 118
        try:
119
            return to_t_user(authenticate_user(email, password))
120
        finally:
4323 mandeep.dh 121
            self.closeSession()
766 rajveer 122
 
557 chandransh 123
    def userExists(self, email):
124
        """
125
        Parameters:
126
        - email
127
        """
128
        log_entry(self, "user exists")
766 rajveer 129
        try:
130
            return user_exists(email)
131
        finally:
4323 mandeep.dh 132
            self.closeSession()
766 rajveer 133
 
567 rajveer 134
    def addAddressForUser(self, userId, address, setDefault):
557 chandransh 135
        """
136
        Parameters:
137
        - userId
138
        - address
139
        - setDefault
140
        """
141
        log_entry(self, "add address for user")
766 rajveer 142
        try:
143
            return add_address_for_user(address, userId, setDefault)
144
        finally:
4323 mandeep.dh 145
            self.closeSession()
766 rajveer 146
 
557 chandransh 147
    def removeAddressForUser(self, userid, addressId):
148
        """
149
        Parameters:
150
        - userid
151
        - addressId
152
        """
153
        log_entry(self, "removing address")
766 rajveer 154
        try:
155
            return remove_address_for_user(userid, addressId)
156
        finally:
4323 mandeep.dh 157
            self.closeSession()
766 rajveer 158
 
557 chandransh 159
    def setUserAsLoggedIn(self, userId, timestamp):
160
        """
161
        Parameters:
162
        - userId
163
        - timestamp
164
        """
165
        log_entry(self, "set_user_as_logged_in")
766 rajveer 166
        try:
167
            return set_user_as_logged_in(userId, timestamp)
168
        finally:
4323 mandeep.dh 169
            self.closeSession()
766 rajveer 170
 
557 chandransh 171
    def setUserAsLoggedOut(self, userId, timestamp):
172
        """
173
        Parameters:
174
        - userId
175
        - timestamp
176
        """
177
        log_entry(self, "set user as logged out")
766 rajveer 178
        try:
179
            return set_user_as_logged_out(userId, timestamp)
180
        finally:
4323 mandeep.dh 181
            self.closeSession()
766 rajveer 182
 
557 chandransh 183
    def setDefaultAddress(self, userId, addressId):
184
        """
185
        Parameters:
186
        - userId
187
        - addressId
188
        """
766 rajveer 189
        try:
190
            return set_default_address(userId, addressId)
191
        finally:
4323 mandeep.dh 192
            self.closeSession()
766 rajveer 193
 
594 rajveer 194
    def updatePassword(self, userid, oldPassword, newPassword):
557 chandransh 195
        """
196
        Parameters:
594 rajveer 197
         - userid
198
         - oldPassword
199
         - newPassword
557 chandransh 200
        """
201
        log_entry(self, "updating password")
766 rajveer 202
        try:
203
            return update_password(userid, oldPassword, newPassword)
204
        finally:
4323 mandeep.dh 205
            self.closeSession()
766 rajveer 206
 
884 rajveer 207
    def forgotPassword(self, email, password):
581 rajveer 208
        """
209
        Parameters:
210
         - email
211
        """
212
        log_entry(self, "forgot password")
766 rajveer 213
        try:
884 rajveer 214
            return forgot_password(email, password)
766 rajveer 215
        finally:
4323 mandeep.dh 216
            self.closeSession()
217
 
594 rajveer 218
    def getAllAddressesForUser(self, userId):
219
        """
220
        Parameters:
221
         - userId
222
        """
766 rajveer 223
        try:
224
            addresses = get_all_addresses_for_user(userId)
225
 
226
            t_addresses = list()
227
            for address in addresses:
228
                t_addresses.append(to_t_address(address))
229
            return t_addresses
230
        finally:
4323 mandeep.dh 231
            self.closeSession()
594 rajveer 232
 
1894 vikas 233
    def getAddressById(self, addressId):
234
        """
235
        Parameters:
236
         - addressId
237
        """
238
        try:
239
            return to_t_address(get_address(addressId))
240
        finally:
4323 mandeep.dh 241
            self.closeSession()
1894 vikas 242
 
594 rajveer 243
    def getDefaultAddressId(self, userId):
244
        """
245
        Parameters:
246
         - userId
247
        """
766 rajveer 248
        try:
785 rajveer 249
            return get_default_address_id(userId)
766 rajveer 250
        finally:
4323 mandeep.dh 251
            self.closeSession()
785 rajveer 252
 
253
    def getDefaultPincode(self, userId):
254
        """
255
        Parameters:
256
         - userId
257
        """
258
        try:
259
            return get_default_pincode(userId)
260
        finally:
4323 mandeep.dh 261
            self.closeSession()
785 rajveer 262
 
557 chandransh 263
    def getCurrentCart(self, userId):
264
        """
265
        Parameters:
130 ashish 266
         - userId
267
        """
766 rajveer 268
        try:
269
            cart = get_cart(userId)
270
            if cart:
271
                return to_t_cart(cart)
272
            else:
273
                raise ShoppingCartException(101, "not cart attached to this user")
274
        finally:
4323 mandeep.dh 275
            self.closeSession()
766 rajveer 276
 
557 chandransh 277
    def getCart(self, cartId):
278
        """
279
        Parameters:
280
         - cartId
281
        """
766 rajveer 282
        try:
283
            cart = get_cart_by_id(cartId)
284
            if cart:
285
                return to_t_cart(cart)
286
            else:
287
                raise ShoppingCartException(101, "not cart attached to this id")
288
        finally:
4323 mandeep.dh 289
            self.closeSession()
766 rajveer 290
 
557 chandransh 291
    def getCartsByTime(self, from_time, to_time, status):
130 ashish 292
        """
293
        Parameters:
557 chandransh 294
         - from_time
295
         - to_time
296
         - status
130 ashish 297
        """
766 rajveer 298
        try:
299
            carts = get_carts_between(from_time, to_time, status)
300
            t_carts = []
301
            if carts:
302
                for cart in carts:
303
                    t_carts.append(to_t_cart(cart))
304
            return t_carts
305
        finally:
4323 mandeep.dh 306
            self.closeSession()
766 rajveer 307
 
3557 rajveer 308
    def addItemToCart(self, cartId, itemId, quantity, sourceId):
130 ashish 309
        """
310
        Parameters:
557 chandransh 311
         - cartId
312
         - itemId
313
         - quantity
130 ashish 314
        """
766 rajveer 315
        try:
3557 rajveer 316
            return add_item_to_cart(cartId, itemId, quantity, sourceId)
766 rajveer 317
        finally:
4323 mandeep.dh 318
            self.closeSession()
766 rajveer 319
 
557 chandransh 320
    def deleteItemFromCart(self, cartId, itemId):
130 ashish 321
        """
322
        Parameters:
557 chandransh 323
         - cartId
324
         - itemId
130 ashish 325
        """
766 rajveer 326
        try:
327
            delete_item_from_cart(cartId, itemId)
328
        finally:
4323 mandeep.dh 329
            self.closeSession()
766 rajveer 330
 
557 chandransh 331
    def addAddressToCart(self, cartId, addressId):
332
        """
333
        Parameters:
334
         - cartId
130 ashish 335
         - addressId
336
        """
766 rajveer 337
        try:
338
            return add_address_to_cart(cartId, addressId)
339
        finally:
4323 mandeep.dh 340
            self.closeSession()
1976 varun.gupt 341
 
342
    def applyCouponToCart(self, cartId, couponCode, totalPrice, discountedPrice):
343
        '''
344
        Parameters:
345
        - cartId
346
        - couponCode
347
        - totalPrice
348
        - discountedPrice
349
        '''
350
        try:
351
            apply_coupon_to_cart(cartId, couponCode, totalPrice, discountedPrice)
352
        finally:
4323 mandeep.dh 353
            self.closeSession()
1976 varun.gupt 354
 
355
    def removeCoupon(self, cartId):
356
        '''
357
        Parameters:
358
        - cartId
359
        '''
360
        try:
361
            remove_coupon(cartId)
362
        finally:
4323 mandeep.dh 363
            self.closeSession()
1976 varun.gupt 364
 
6389 rajveer 365
    def createOrders(self, cartId, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId):
130 ashish 366
        """
367
        Parameters:
557 chandransh 368
         - cartId
2815 vikas 369
         - sessionSource
130 ashish 370
        """
766 rajveer 371
        try:
6389 rajveer 372
            return commit_cart(cartId, sessionSource, sessionTime, firstSource, firstSourceTime, userId, schemeId)
766 rajveer 373
        finally:
4323 mandeep.dh 374
            self.closeSession()
1466 ankur.sing 375
 
3557 rajveer 376
    def validateCart(self, cartId, sourceId):
130 ashish 377
        """
1466 ankur.sing 378
        Validates that:
379
        1. The checkout timestamp is greater than the updatedOn timestamp.
380
        2. All of the lines in the cart are active items.
381
        3. The estimate for any of the lines in cart doesn't change.
1976 varun.gupt 382
        4. If a Coupon Code is attached, it gets applied and discounted price is computed
383
        If first three are true, returns empty string; else returns appropriate message.
1466 ankur.sing 384
 
130 ashish 385
        Parameters:
557 chandransh 386
         - cartId
130 ashish 387
        """
766 rajveer 388
        try:
3557 rajveer 389
            return validate_cart(cartId, sourceId)
766 rajveer 390
        finally:
4323 mandeep.dh 391
            self.closeSession()
766 rajveer 392
 
557 chandransh 393
    def mergeCart(self, fromCartId, toCartId):
513 rajveer 394
        """
395
        Parameters:
557 chandransh 396
         - fromCartId
397
         - toCartId
513 rajveer 398
        """
766 rajveer 399
        try:
400
            merge_cart(fromCartId, toCartId)
401
        finally:
4323 mandeep.dh 402
            self.closeSession()
766 rajveer 403
 
691 chandransh 404
    def checkOut(self, cartId):
405
        """
406
        Sets the checkedOutOn timestamp of the cart. Raises an exception if the specified cart can't be found.
407
 
408
        Parameters:
409
         - cartId
410
        """
766 rajveer 411
        try:
412
            return check_out(cartId)
413
        finally:
4323 mandeep.dh 414
            self.closeSession()
766 rajveer 415
 
691 chandransh 416
    def resetCart(self, cartId, items):
417
        """
418
        The second parameter is a map of item ids and their quantities which have been successfully processed.
419
        This methods removes the specified quantiry of the specified item from the cart.
420
 
421
        Parameters:
422
         - cartId
423
         - items
424
        """
766 rajveer 425
        try:
426
            return reset_cart(cartId, items)
427
        finally:
4323 mandeep.dh 428
            self.closeSession()
772 rajveer 429
 
430
    #Widget related methods
431
    def updateMyResearch(self, userId, itemId):
432
        """
433
        Parameters:
434
         - user_id
435
         - item_id
436
        """
437
        try:
438
            return update_my_research(userId, itemId)
439
        finally:
4323 mandeep.dh 440
            self.closeSession()
772 rajveer 441
 
442
    def deleteItemFromMyResearch(self, userId, itemId):
443
        """
444
        Parameters:
445
         - user_id
446
         - item_id
447
        """
448
        try:
449
            return delete_item_from_my_research(userId, itemId)
450
        finally:
4323 mandeep.dh 451
            self.closeSession()
766 rajveer 452
 
772 rajveer 453
    def updateBrowseHistory(self, userId, itemId):
454
        """
455
        Parameters: 
456
        - user_id
457
        - item_id
458
        """
459
        try:
460
            update_browse_history(userId, itemId)
461
        finally:
4323 mandeep.dh 462
            self.closeSession()
772 rajveer 463
 
464
    def mergeBrowseHistory(self, fromUserId, toUserId):
465
        """
466
        Parameters:
467
         - user_id
468
        """
2981 rajveer 469
        pass
772 rajveer 470
 
1273 varun.gupt 471
    def saveUserCommunication(self, userId, email, communicationType, orderId, awb, product, subject, message):
472
        """
473
        Parameters:
474
         - userId
475
         - email
476
         - communicationType
477
         - orderId
478
         - awb
479
         - product
480
         - subject
481
         - message
482
        """
483
        try:
484
            return create_user_communication(userId, email, communicationType, orderId, awb, product, subject, message)
485
        finally:
4323 mandeep.dh 486
            self.closeSession()
1273 varun.gupt 487
 
1583 varun.gupt 488
    def getUserCommunicationById(self, id):
489
        """
490
        Parameters:
491
         - id
492
        """
493
        try:
494
            return to_t_user_communication(get_user_communication_by_id(id))
495
        finally:
4323 mandeep.dh 496
            self.closeSession()
1583 varun.gupt 497
 
498
    def getUserCommunicationByUser(self, userId):
499
        """
500
        Parameters:
501
         - userId
502
        """
503
        try:
504
            return [to_t_user_communication(user_communication) for user_communication in get_user_communication_by_user(userId)]
505
        finally:
4323 mandeep.dh 506
            self.closeSession()
1583 varun.gupt 507
 
508
    def getAllUserCommunications(self):
509
        try:
510
            return [to_t_user_communication(user_communication) for user_communication in get_all_user_communications()]
511
        finally:
4323 mandeep.dh 512
            self.closeSession()
5407 amar.kumar 513
 
514
    def removeUserCommunication(self, id):
515
        try:
516
            remove_user_communication(id)
517
        finally:
518
            self.closeSession()
1596 ankur.sing 519
 
1859 vikas 520
    def createMasterAffiliate(self, name, addedOn):
1845 vikas 521
        """
522
        Parameters
523
         - name
1859 vikas 524
         - addedOn
1845 vikas 525
        """
526
        try:
1859 vikas 527
            return to_t_master_affiliate(create_master_affiliate(name, addedOn))
1845 vikas 528
        finally:
4323 mandeep.dh 529
            self.closeSession()
1845 vikas 530
 
1899 vikas 531
    def getAllMasterAffiliates(self):
532
        try:
533
            return [to_t_master_affiliate(masterAffiliate) for masterAffiliate in get_all_master_affiliates()]
534
        finally:
4323 mandeep.dh 535
            self.closeSession()
1899 vikas 536
 
1845 vikas 537
    def getMasterAffiliateById(self, id):
538
        """
539
        Parameters
540
         - id
541
        """
542
        try:
543
            return to_t_master_affiliate(get_master_affiliate_by_id(id))
544
        finally:
4323 mandeep.dh 545
            self.closeSession()
1845 vikas 546
 
547
    def getMasterAffiliateByName(self, name):
548
        """
549
        Parameters
550
         - id
551
        """
552
        try:
553
            return to_t_master_affiliate(get_master_affiliate_by_name(name))
554
        finally:
4323 mandeep.dh 555
            self.closeSession()
1845 vikas 556
 
1859 vikas 557
    def createAffiliate(self, name, url, masterAffiliateId, addedOn):
1845 vikas 558
        """
559
        Parameters
560
         - name
561
         - url
1859 vikas 562
         - masterAffiliateId
563
         - addedOn
1845 vikas 564
        """
565
        try:
1859 vikas 566
            return to_t_affiliate(create_affiliate(name, url, masterAffiliateId, addedOn))
1845 vikas 567
        finally:
4323 mandeep.dh 568
            self.closeSession()
1845 vikas 569
 
570
    def getAffiliateById(self, id):
571
        """
572
        Parameters
573
         - id
574
        """
575
        try:
576
            return to_t_affiliate(get_affiliate_by_id(id))
577
        finally:
4323 mandeep.dh 578
            self.closeSession()
1845 vikas 579
 
580
    def getAffiliateByName(self, name):
581
        """
582
        Parameters
583
         - name
584
        """
585
        try:
586
            return to_t_affiliate(get_affiliate_by_name(name))
587
        finally:
4323 mandeep.dh 588
            self.closeSession()
1845 vikas 589
 
1996 vikas 590
    def getAffiliatesByMasterAffiliate(self, masterAffiliateId):
1845 vikas 591
        """
592
        Parameters
593
         - master_id
594
        """
595
        try:
1996 vikas 596
            return [to_t_affiliate(affiliate) for affiliate in get_affiliates_by_master_affiliate(masterAffiliateId)]
1845 vikas 597
        finally:
4323 mandeep.dh 598
            self.closeSession()
1845 vikas 599
 
1996 vikas 600
    def getTrackerById(self, trackerId):
1845 vikas 601
        """
602
        Parameters
1996 vikas 603
         - trackerId
1845 vikas 604
        """
605
        try:
1996 vikas 606
            return to_t_tracker(get_tracker_by_id(trackerId))
1845 vikas 607
        finally:
4323 mandeep.dh 608
            self.closeSession()
1996 vikas 609
 
610
    def addTrackLog(self, affiliateId, userId, event, url, data, addedOn):
1845 vikas 611
        """
1996 vikas 612
        Parameter
1845 vikas 613
         - affiliateId
614
         - userId
615
         - event
616
         - url
617
         - data
1859 vikas 618
         - addedOn
1845 vikas 619
        """
620
        try:
1996 vikas 621
            return add_track_log(affiliateId, userId, event, url, data, addedOn)
1845 vikas 622
        finally:
4323 mandeep.dh 623
            self.closeSession()
1845 vikas 624
 
625
    def getTrackLogById(self, id):
626
        """
627
        Parameter
628
         - id
629
        """
630
        try:
631
            return to_t_track_log(get_track_log_by_id(id))
632
        finally:
4323 mandeep.dh 633
            self.closeSession()
1845 vikas 634
 
3293 vikas 635
    def getTrackLogsByAffiliate(self, affiliateId, startDate, endDate):
1845 vikas 636
        """
637
        Parameter
1996 vikas 638
         - affiliate_id
1845 vikas 639
        """
640
        try:
3293 vikas 641
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_affiliate(affiliateId, startDate, endDate)]
1845 vikas 642
        finally:
4323 mandeep.dh 643
            self.closeSession()
1845 vikas 644
 
645
    def getTrackLogsByUser(self, user_id):
646
        """
647
        Parameter
648
         - user_id
649
        """
650
        try:
651
            return [to_t_track_log(track_log) for track_log in get_track_logs_by_user(user_id)]
652
        finally:
4323 mandeep.dh 653
            self.closeSession()
1845 vikas 654
 
1996 vikas 655
    def getTrackLogs(self, affiliateId, userId, event, url):
1845 vikas 656
        """
657
        Parameter
1996 vikas 658
         - affiliateId
659
         - userId
660
         - event
661
         - url
1845 vikas 662
        """
663
        try:
1996 vikas 664
            return [to_t_track_log(track_log) for track_log in get_track_logs(affiliateId, userId, event, url)]
1845 vikas 665
        finally:
4323 mandeep.dh 666
            self.closeSession()
1845 vikas 667
 
1596 ankur.sing 668
    def getUserCount(self, userType):
669
        """
670
        Returns number of registered users.
1612 ankur.sing 671
        If userType = null, then it returns count of all users, including anonymous
672
        If userType = UserType.ANONYMOUS, then it returns count of anonymous users only
673
        If userType = UserType.USER, then it returns count of non-anonymous users only
1596 ankur.sing 674
 
675
        Parameters:
1612 ankur.sing 676
         - userType
1596 ankur.sing 677
        """
1673 ankur.sing 678
        try:
679
            return UserDataAccessors.get_user_count(userType)
680
        finally:
4323 mandeep.dh 681
            self.closeSession()
1673 ankur.sing 682
 
1891 ankur.sing 683
    def getAllUsers(self, userType, startDate, endDate):
1673 ankur.sing 684
        """
685
        Returns list of users of type userType. If userType is null, then returns all the users.
686
 
687
        Parameters:
688
         - userType
689
        """
690
        try:
1891 ankur.sing 691
            users = UserDataAccessors.get_users(userType, startDate, endDate)
1673 ankur.sing 692
            t_users = list()
693
            for user in users:
694
                t_users.append(to_t_user(user))
695
            return t_users
696
        finally:
4323 mandeep.dh 697
            self.closeSession()
1583 varun.gupt 698
 
2981 rajveer 699
    def getMyResearchItems(self, userId):
130 ashish 700
        """
701
        Parameters:
2981 rajveer 702
         - userId
130 ashish 703
        """
766 rajveer 704
        try:
2981 rajveer 705
            return get_my_research_items(userId)
766 rajveer 706
        finally:
4323 mandeep.dh 707
            self.closeSession()
2981 rajveer 708
 
709
    def getBrowseHistoryItems(self, userId):
130 ashish 710
        """
711
        Parameters:
557 chandransh 712
         - userId
130 ashish 713
        """
766 rajveer 714
        try:
2981 rajveer 715
            return get_browse_history_items(userId)
766 rajveer 716
        finally:
4323 mandeep.dh 717
            self.closeSession()
2981 rajveer 718
 
3386 varun.gupt 719
    def getCartsWithCouponCount(self, couponCode):
720
        '''
721
        Parameters:
722
         - couponCode
723
        '''
724
        try:
725
            return get_carts_with_coupon_count(couponCode)
726
        finally:
4323 mandeep.dh 727
            self.closeSession()
3499 mandeep.dh 728
 
729
    def increaseTrustLevel(self, userId, trustLevelDelta):
730
        """
731
        Parameters:
732
         - userId
733
         - trustLevelDelta
734
        """
735
        try:
736
            return increase_trust_level(userId, trustLevelDelta)
737
        finally:
4323 mandeep.dh 738
            self.closeSession()
3554 varun.gupt 739
 
5407 amar.kumar 740
    def getTrustLevel(self, userId):
741
        try:
742
            return get_trust_level(userId)
743
        finally:
744
            self.closeSession()
745
 
3554 varun.gupt 746
    def deleteDiscountsFromCart(self, cartId):
747
        '''
748
        Parameters:
749
         - cartId
750
        '''
751
        try:
752
            return delete_discounts_from_cart(cart_id = cartId)
753
        finally:
4323 mandeep.dh 754
            self.closeSession()
3554 varun.gupt 755
 
756
    def saveDiscounts(self, discounts):
757
        '''
758
        Parameters:
759
         - discounts
760
        '''
761
        try:
762
            return save_discounts(discounts)
763
        finally:
4323 mandeep.dh 764
            self.closeSession()
3499 mandeep.dh 765
 
4668 varun.gupt 766
    def showCODOption(self, cartId, sourceId, pincode):
767
        '''
768
        Parameters:
769
         - cartId
770
         - pincode
771
        '''
772
        try:
773
            return show_cod_option(cartId, sourceId, pincode)
774
        finally:
775
            self.closeSession()
5555 rajveer 776
 
777
 
778
    def addStoreToCart(self, cartId, storeId):
779
        """
780
        Parameters:
781
         - cartId
782
         - storeId
783
        """
784
        try:
785
            return add_store_to_cart(cartId, storeId)
786
        finally:
787
            self.closeSession()
788
 
5623 anupam.sin 789
    def getUserEmails(self, startDate, endDate):
790
        '''
791
        Get email addresses for users activated within a given date range
792
 
793
        Parameters:
794
         - startDate
795
         - endDate
796
        '''
797
        try:
798
            return get_user_emails(to_py_date(startDate), to_py_date(endDate))
799
        finally:
800
            self.closeSession()
801
 
2981 rajveer 802
    def closeSession(self, ):
803
        CartDataAccessors.close_session()
804
        UserDataAccessors.close_session()
3376 rajveer 805
 
806
    def isAlive(self, ):
807
        """
808
        For checking weather service is active alive or not. It also checks connectivity with database
809
        """
810
        try:
811
            return is_alive()
812
        finally:
4323 mandeep.dh 813
            self.closeSession()
772 rajveer 814