Subversion Repositories SmartDukaan

Rev

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

Rev 3079 Rev 3086
Line 17... Line 17...
17
import sys
17
import sys
18
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
18
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
19
from sqlalchemy import desc, asc
19
from sqlalchemy import desc, asc
20
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
20
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
21
from sqlalchemy.sql.expression import and_, distinct, func
21
from sqlalchemy.sql.expression import and_, distinct, func
-
 
22
from string import Template
-
 
23
from shop2020.clients.HelperClient import HelperClient
22
 
24
 
23
def initialize():
25
def initialize():
24
    DataService.initialize()
26
    DataService.initialize()
25
    
27
    
26
 
28
 
Line 934... Line 936...
934
        product_notification.addedOn = datetime.datetime.now()
936
        product_notification.addedOn = datetime.datetime.now()
935
        session.commit()
937
        session.commit()
936
        return True
938
        return True
937
    except:
939
    except:
938
        return False
940
        return False
-
 
941
 
-
 
942
 
-
 
943
def send_product_notifications():
-
 
944
    product_notifications = ProductNotification.query.all()
-
 
945
    for product_notification in product_notifications:
-
 
946
        item = product_notification.item
-
 
947
        availability = __get_item_availability(item)
-
 
948
        if availability > 0:
-
 
949
            __enque_product_notification_email(product_notification.email, __get_product_name(item) , product_notification.addedOn, __get_product_url(item), item.id)
-
 
950
            product_notification.delete()
-
 
951
    session.commit()
-
 
952
    return True
-
 
953
   
-
 
954
def __get_product_name(item):
-
 
955
    product_name = item.brand + " " + item.model_name + " " + item.model_number
-
 
956
    color = item.color
-
 
957
    if color is not None and color != 'NA':
-
 
958
        product_name = product_name + " (" + color + ")"
-
 
959
    product_url = product_url.replace("  "," ")
-
 
960
    return product_name
-
 
961
 
-
 
962
 
-
 
963
def __get_product_url(item):
-
 
964
    product_url = "http://www.saholic.com/mobile-phones/" + item.brand + "-" + item.model_name + "-" + item.model_number + "-" + str(item.catalog_item_id)
-
 
965
    product_url = product_url.replace("--","-")
-
 
966
    product_url = product_url.replace(" ","")
-
 
967
    return product_url
-
 
968
 
-
 
969
 
-
 
970
 
-
 
971
def __enque_product_notification_email(email, product, date, url, itemId):
-
 
972
                
-
 
973
    html = """
-
 
974
        <html>
-
 
975
        <body>
-
 
976
        <div>
-
 
977
        <p>
-
 
978
            Hi,<br /><br />
-
 
979
            The product requested by you on $date is now available on saholic.com.
-
 
980
        </p>
-
 
981
            
-
 
982
        <p>    
-
 
983
        <strong>Product: $product </strong>
-
 
984
        </p>
-
 
985
        
-
 
986
        <p>
-
 
987
        Click the link below to visit the product: 
-
 
988
        <br/>
-
 
989
        $url
-
 
990
        </p>
-
 
991
        <p>
-
 
992
        Regards,<br/>
-
 
993
        Saholic Customer Support Team<br/>
-
 
994
        www.saholic.com<br/>
-
 
995
        Email: help@saholic.com<br/>
-
 
996
        </p>
-
 
997
        </div>
-
 
998
        </body>
-
 
999
        </html>
-
 
1000
        """
-
 
1001
 
-
 
1002
    html = Template(html).substitute(dict(product=product,date=date,url=url))
939
    
1003
    
-
 
1004
    try:
-
 
1005
        helper_client = HelperClient().get_client()
-
 
1006
        helper_client.saveUserEmailForSending(email, "", "Product requested by you is available now.", html, str(itemId), "ProductNotification")
-
 
1007
    except Exception as e:
-
 
1008
        print e
-
 
1009
 
-
 
1010
 
940
def close_session():
1011
def close_session():
941
    if session.is_active:
1012
    if session.is_active:
942
        print "session is active. closing it."
1013
        print "session is active. closing it."
943
        session.close()
1014
        session.close()