Subversion Repositories SmartDukaan

Rev

Rev 3376 | Rev 4189 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3376 Rev 3386
Line 2... Line 2...
2
Created on: May 24, 2011
2
Created on: May 24, 2011
3
@author: Varun Gupta
3
@author: Varun Gupta
4
'''
4
'''
5
 
5
 
6
from shop2020.model.v1.user.impl.PromotionDataAccessors import initialize, create_promotion,\
6
from shop2020.model.v1.user.impl.PromotionDataAccessors import initialize, create_promotion,\
7
    generate_coupons_for_promotion, apply_coupon, track_coupon_usage, is_alive
7
    generate_coupons_for_promotion, apply_coupon, track_coupon_usage, is_alive,\
-
 
8
    get_active_coupons, get_successful_payment_count_for_coupon,\
-
 
9
    get_rule_doc_string
8
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
10
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
9
from shop2020.model.v1.user.impl import PromotionDataAccessors
11
from shop2020.model.v1.user.impl import PromotionDataAccessors
-
 
12
from shop2020.model.v1.user.impl.Converters import to_t_coupon
10
 
13
 
11
class PromotionServiceHandler:
14
class PromotionServiceHandler:
12
    
15
    
13
    def __init__(self, dbname='user', db_hostname='localhost'):
16
    def __init__(self, dbname='user', db_hostname='localhost'):
14
        initialize(dbname, db_hostname)
17
        initialize(dbname, db_hostname)
Line 85... Line 88...
85
        '''
88
        '''
86
        try:
89
        try:
87
            return get_coupon_usage_count_by_user(couponCode, userId)
90
            return get_coupon_usage_count_by_user(couponCode, userId)
88
        finally:
91
        finally:
89
            PromotionDataAccessors.close_session()
92
            PromotionDataAccessors.close_session()
90
 
93
    
-
 
94
    def getActiveCoupons(self):
-
 
95
        '''
-
 
96
        Returns a list of active coupons
-
 
97
        '''
-
 
98
        try:
-
 
99
            return [to_t_coupon(coupon) for coupon in get_active_coupons()]
-
 
100
        finally:
-
 
101
            PromotionDataAccessors.close_session()
-
 
102
    
-
 
103
    def getSuccessfulPaymentCountForCoupon(self, couponCode):
-
 
104
        '''
-
 
105
        Returns the count of successful payments done using this coupon
-
 
106
        
-
 
107
        Parameters:
-
 
108
        - couponCode
-
 
109
        '''
-
 
110
        try:
-
 
111
            return get_successful_payment_count_for_coupon(couponCode)
-
 
112
        finally:
-
 
113
            PromotionDataAccessors.close_session()
-
 
114
    
-
 
115
    def getRuleDocString(self, ruleName):
-
 
116
        '''
-
 
117
        Returns the doc string of the rule module
-
 
118
        
-
 
119
        Parameters:
-
 
120
        - ruleName
-
 
121
        '''
-
 
122
        try:
-
 
123
            return get_rule_doc_string(ruleName)
-
 
124
        finally:
-
 
125
            PromotionDataAccessors.close_session()
-
 
126
    
91
    def isAlive(self, ):
127
    def isAlive(self):
92
        """
128
        """
93
        For checking weather service is active alive or not. It also checks connectivity with database
129
        For checking weather service is active alive or not. It also checks connectivity with database
94
        """
130
        """
95
        try:
131
        try:
96
            return is_alive()
132
            return is_alive()
97
        finally:
133
        finally:
98
            PromotionDataAccessors.close_session()
134
            PromotionDataAccessors.close_session()        
99
135