Exemplo n.º 1
0
def sendmail(email, mail_ctx, title, useage):
    logger.debug(useage + ': Prepare to send mail.')

    from shopcart.utils import my_send_mail, url_with_out_slash, MailThread
    from shopcart.models import Email
    email_definition = Email.objects.get(useage=useage)
    if email_definition.is_send:
        logger.info('Mail [%s] has been sended to [%s].' % (useage, email))
        template = 'default'
        if email_definition.template != '' and email_definition.template != None:
            logger.debug('email.template is not none')
            template = url_with_out_slash(email_definition.template)

        template_file = useage + '.html'
        if email_definition.template_file != '' and email_definition.template_file != None:
            logger.debug('email.template_file is not none')
            template_file = template_file

        template_path = 'email/%s/%s' % (template, template_file)

        if title == None or title == '':
            from django.template import Context, loader, base
            title_template = base.Template(template_string=email_definition.title)
            title = title_template.render(Context(mail_ctx))
        logger.debug('Start to send mail.')
        mail_thread = MailThread(ctx=mail_ctx, send_to=email, title=title, template_path=template_path,
                                 username=email_definition.username, password=email_definition.password,
                                 smtp_host=email_definition.smtp_host, sender=email_definition.email_address,
                                 is_ssl=email_definition.need_ssl)
        mail_thread.start()
        # my_send_mail(ctx=mail_ctx,send_to=email,title=title,template_path=template_path,username=email_definition.username,password=email_definition.password,smtp_host=email_definition.smtp_host,sender=email_definition.email_address)
        # my_send_mail(ctx=mail_ctx,send_to=email,title=title,template_path=template_path,username=email_definition.username,password=email_definition.password,smtp_host=email_definition.smtp_host,sender=email_definition.email_address)
        logger.debug('Send mail thread started.')
    else:
        logger.info('Mail function is closed.')
Exemplo n.º 2
0
def sendmail(email,mail_ctx,title,useage):
	logger.debug(useage + ': Prepare to send mail.')

	from shopcart.utils import my_send_mail,url_with_out_slash,MailThread
	from shopcart.models import Email
	email_definition = Email.objects.get(useage=useage)
	if email_definition.is_send:
		logger.info('Mail [%s] has been sended to [%s].' % (useage,email))
		template = 'default'
		if email_definition.template != '' and email_definition.template != None:
			logger.debug('email.template is not none')
			template = url_with_out_slash(email_definition.template)
		
		template_file = useage + '.html'
		if email_definition.template_file != '' and email_definition.template_file != None:
			logger.debug('email.template_file is not none')
			template_file = template_file
		
		template_path =  'email/%s/%s' % (template,template_file)
		
		
		if title == None or title == '':
			from django.template import Context,loader,base
			title_template = base.Template(template_string = email_definition.title)
			title = title_template.render(Context(mail_ctx))
		logger.debug('Start to send mail.')
		mail_thread = MailThread(ctx=mail_ctx,send_to=email,title=title,template_path=template_path,username=email_definition.username,password=email_definition.password,smtp_host=email_definition.smtp_host,sender=email_definition.email_address,is_ssl=email_definition.need_ssl)
		mail_thread.start()
		#my_send_mail(ctx=mail_ctx,send_to=email,title=title,template_path=template_path,username=email_definition.username,password=email_definition.password,smtp_host=email_definition.smtp_host,sender=email_definition.email_address)
		#my_send_mail(ctx=mail_ctx,send_to=email,title=title,template_path=template_path,username=email_definition.username,password=email_definition.password,smtp_host=email_definition.smtp_host,sender=email_definition.email_address)
		logger.debug('Send mail thread started.')
	else:
		logger.info('Mail function is closed.')	
		
Exemplo n.º 3
0
def send_notice_email(notice_type, mail_ctx):
    logger.info('Start to send notice mails,notice_type:%s ...' % notice_type)
    from shopcart.models import NoticeEmailType, NoticeEmailList
    from shopcart.utils import url_with_out_slash, MailThread
    try:
        type = NoticeEmailType.objects.get(type=notice_type)
    except Exception as err:
        logger.info('There is no config for %s. \n Error Message: %s ' % (notice_type, err))
        type = None

    if type and type.is_send == True:
        audit_list = NoticeEmailList.objects.filter(type=type)
    else:
        audit_list = None

    if audit_list:
        template = 'default'
        if type.template != '' and type.template != None:
            logger.debug('email.template is not none')
            template = url_with_out_slash(type.template)

        template_file = 'default' + '.html'
        if type.template_file != '' and type.template_file != None:
            logger.debug('email.template_file is not none')
            template_file = type.template_file

        template_path = 'email/%s/%s' % (template, template_file)

        for audit in audit_list:
            logger.debug('Start to send mail to %s....' % audit.email_address)
            mail_thread = MailThread(ctx=mail_ctx, send_to=audit.email_address, title=type.title,
                                     template_path=template_path, username=type.username, password=type.password,
                                     smtp_host=type.smtp_host, sender=type.sender, is_ssl=type.need_ssl)
            mail_thread.start()
Exemplo n.º 4
0
def get_url(object):
    from shopcart.models import System_Config, CustomizeURL
    url = url_with_out_slash(System_Config.objects.get(name='base_url').val)

    if isinstance(object, CustomizeURL):
        return ('%s/%s' % (url, object.url))
    else:
        return '#'
Exemplo n.º 5
0
def get_url(object):
    from shopcart.models import System_Config, Recruit
    url = url_with_out_slash(System_Config.objects.get(name='base_url').val)
    logger.info('进入get_url %s' % url)
    if isinstance(object, Recruit):
        if object.static_file_name == None or object.static_file_name == '':
            return ('%s/recruit/%s' % (url, object.id))
        else:
            return ('%s/%s' % (url, object.static_file_name))
    else:
        return '#'
Exemplo n.º 6
0
def get_url(object):
    from shopcart.models import System_Config, Recruit
    url = url_with_out_slash(System_Config.objects.get(name='base_url').val)
    logger.info('进入get_url %s' %url)
    if isinstance(object, Recruit):
        if object.static_file_name == None or object.static_file_name == '':
            return ('%s/recruit/%s' % (url, object.id))
        else:
            return ('%s/%s' % (url, object.static_file_name))
    else:
        return '#'
Exemplo n.º 7
0
def get_url(object):
    from shopcart.models import System_Config, Article
    url = url_with_out_slash(System_Config.objects.get(name='base_url').val)

    if isinstance(object, Article):
        if object.static_file_name == None or object.static_file_name == '':
            return ('%s/article/%s' % (url, object.id))
        else:
            return ('%s/%s' % (url, object.static_file_name))
    else:
        return '#'
Exemplo n.º 8
0
def get_url(object):
	from shopcart.models import System_Config,Product
	url = url_with_out_slash(System_Config.objects.get(name='base_url').val)
	
	
	if isinstance(object,Product):
		if object.static_file_name == None or object.static_file_name == '':
			#return  url + '/product/' + object.id
			return ('%s/product/%s' % (url,object.id))
		else:
			return ('%s/%s' % (url,object.static_file_name))
			#return url + '/' + object.static_file_name
	else:
		return '#'
Exemplo n.º 9
0
def user_password_modify_applied_send_mail(sender,	**kwargs):
	try:
		logger.info('Enter user_password_modify_applied_send_mail hanlder!')
		email = kwargs['reset_password'].email
		validate_code = kwargs['reset_password'].validate_code
		mail_ctx = {}
		from shopcart.utils import get_system_parameters
		from shopcart.utils import url_with_out_slash
		mail_ctx['system_para'] = get_system_parameters()
		reset_url =  '%s/user/reset-password?email=%s&validate_code=%s' % (url_with_out_slash(mail_ctx['system_para']['base_url']),email,validate_code)
		logger.debug('reset_url:' + reset_url)
		mail_ctx['email'] = email
		mail_ctx['reset_password_link'] = reset_url
		#sendmail('user_password_modify_applied_send_mail',email,mail_ctx,title=None,useage='user_password_modify_applied')
		sendmail(email,mail_ctx,title=None,useage='user_password_modify_applied')
	except Exception as err:
		logger.error('There is an error ocuuerd in user_password_modify_applied_send_mail . \n Error Message:%s' % err)
Exemplo n.º 10
0
def user_password_modify_applied_send_mail(sender, **kwargs):
    try:
        logger.info('Enter user_password_modify_applied_send_mail hanlder!')
        email = kwargs['reset_password'].email
        validate_code = kwargs['reset_password'].validate_code
        mail_ctx = {}
        from shopcart.utils import get_system_parameters
        from shopcart.utils import url_with_out_slash
        mail_ctx['system_para'] = get_system_parameters()
        reset_url = '%s/user/reset-password?email=%s&validate_code=%s' % (
        url_with_out_slash(mail_ctx['system_para']['base_url']), email, validate_code)
        logger.debug('reset_url:' + reset_url)
        mail_ctx['email'] = email
        mail_ctx['reset_password_link'] = reset_url
        # sendmail('user_password_modify_applied_send_mail',email,mail_ctx,title=None,useage='user_password_modify_applied')
        sendmail(email, mail_ctx, title=None, useage='user_password_modify_applied')
    except Exception as err:
        logger.error('There is an error ocuuerd in user_password_modify_applied_send_mail . \n Error Message:%s' % err)
Exemplo n.º 11
0
def get_url(object):
    from shopcart.models import System_Config, Product, Category
    url = url_with_out_slash(System_Config.objects.get(name='base_url').val)

    if isinstance(object, Product):
        if object.static_file_name == None or object.static_file_name == '':
            # return  url + '/product/' + object.id
            return ('%s/product/%s' % (url, object.id))
        else:
            return ('%s/%s' % (url, object.static_file_name))
        # return url + '/' + object.static_file_name
    elif isinstance(object, Category):
        if object.static_file_name == None or object.static_file_name == '':
            return ('%s/category/%s' % (url, object.id))
        else:
            return ('%s/%s' % (url, object.static_file_name))
    else:
        return '#'
Exemplo n.º 12
0
def product_export(request):
    ctx = {}
    ctx['page_name'] = '商品导出'

    result = {}
    result['success'] = True
    result['message'] = '商品导出成功'
    result['file_url'] = ''

    if request.method == 'POST':
        from shopcart.functions.excel_util import export_products

        method = request.POST.get('method', '')
        logger.debug('Export method is : %s' % method)

        if method == 'selection':
            product_id_list = request.POST.getlist('is_oper')
            if not product_id_list:
                result['success'] = False
                result['message'] = '请选择至少一件商品进行导出'
                result['file_url'] = ''
                return JsonResponse(result)
            product_list = Product.objects.filter(id__in=product_id_list)
        elif method == 'all':
            product_list = Product.objects.all()
        else:
            raise Http404

        try:
            file_name = 'media\export\product_export.xls'
            export_products(product_list, file_name)

            from shopcart.utils import url_with_out_slash
            url = url_with_out_slash(System_Config.objects.get(name='base_url').val)
            result['file_url'] = '%s/media/export/product_export.xls' % url
        except Exception as err:
            logger.error('Product export error : %s' % err)
            result['success'] = False
            result['message'] = '商品导出失败'
            result['file_url'] = ''
        return JsonResponse(result)
    else:
        raise Http404
Exemplo n.º 13
0
def send_notice_email(notice_type, mail_ctx):
    logger.info('Start to send notice mails,notice_type:%s ...' % notice_type)
    from shopcart.models import NoticeEmailType, NoticeEmailList
    from shopcart.utils import url_with_out_slash, MailThread
    try:
        type = NoticeEmailType.objects.get(type=notice_type)
    except Exception as err:
        logger.info('There is no config for %s. \n Error Message: %s ' %
                    (notice_type, err))
        type = None

    if type and type.is_send == True:
        audit_list = NoticeEmailList.objects.filter(type=type)
    else:
        audit_list = None

    if audit_list:
        template = 'default'
        if type.template != '' and type.template != None:
            logger.debug('email.template is not none')
            template = url_with_out_slash(type.template)

        template_file = 'default' + '.html'
        if type.template_file != '' and type.template_file != None:
            logger.debug('email.template_file is not none')
            template_file = type.template_file

        template_path = 'email/%s/%s' % (template, template_file)

        for audit in audit_list:
            logger.debug('Start to send mail to %s....' % audit.email_address)
            mail_thread = MailThread(ctx=mail_ctx,
                                     send_to=audit.email_address,
                                     title=type.title,
                                     template_path=template_path,
                                     username=type.username,
                                     password=type.password,
                                     smtp_host=type.smtp_host,
                                     sender=type.sender,
                                     is_ssl=type.need_ssl)
            mail_thread.start()