Ejemplo n.º 1
0
def ajax_domain_content(request, list_id):
    is_subscribe = request.GET.get('is_subscribe', '')
    cr = connections['mm-pool'].cursor()
    user_id = model_addresses.get_address_userid(request, list_id)
    tablename = 'ml_subscriber_' + str(user_id)
    vals, count, html = {}, 0, ''
    sql = u"SELECT address FROM {0} WHERE list_id={1}".format(
        tablename, list_id)
    if is_subscribe == '1':
        sql += u" and is_subscribe=0 "
    elif is_subscribe == '2':
        sql += u" and is_subscribe=1 "
    cr.execute(sql)
    data = cr.fetchall()
    for address in data:
        count += 1
        domain = address[0].split("@")[-1]
        if domain in vals:
            vals[domain] += 1
        else:
            vals.update({domain: 1})
    sortVals = sorted(vals.iteritems(), key=lambda d: d[1], reverse=True)
    i = 0
    for key, value in sortVals:
        occupy = u"{}".format(round(value * 100.00 / count, 2))
        html += u"<span>" + key + u":<span style='color:green;'>" + occupy + u"%</span></span>&nbsp;&nbsp;"
        i += 1
        if i == 5:
            break
    if not html:
        html = u"<span>{}</span>".format(_(u'无'))
    return HttpResponse(html, content_type='text/html')
Ejemplo n.º 2
0
def ajax_maillist_count(request, list_id):
    status = request.GET.get('status', '')
    cr = connections['mm-pool'].cursor()
    user_id = model_addresses.get_address_userid(request, list_id)
    if status == '1':
        count = address_sqls.get_addr_count(cr, user_id, list_id, status)
        html = '<a type="button" href="/address/subscribe/{}/" target="_blank" title="{}">{}</a>'.format(
            list_id, _(u'查看联系人分类邮箱列表'), count)
        return HttpResponse(json.dumps({'info': html}),
                            content_type="application/json")
    elif status == '2':
        count = address_sqls.get_addr_count(cr, user_id, list_id, status)
        html = '<a type="button" href="/address/subscribe/{}/?is_subscribe=2" target="_blank" title="{}">{}</a>'.format(
            list_id, _(u'查看订阅用户列表'), count)
        return HttpResponse(json.dumps({'info': html}),
                            content_type="application/json")
    elif status == '3':
        count = address_sqls.get_addr_count(cr, user_id, list_id, status)
        html = '<a type="button" href="/address/unsubscribe/{}/?is_subscribe=2" target="_blank" title="{}">{}</a>'.format(
            list_id, _(u'查看退订用户列表'), count)
        return HttpResponse(json.dumps({'info': html}),
                            content_type="application/json")
    else:
        raise Http404
Ejemplo n.º 3
0
def post_task_add(request, is_service_disabled):
    if is_service_disabled:
        messages.add_message(request, messages.ERROR,
                             _(u'修改任务失败;该账户已禁止发送任务,请联系您的客服!'))
        return HttpResponseRedirect('/task/?isvalid=1')

    data = request.POST
    user = request.user
    send_name = data.get('send_name', '')
    redis = get_redis_connection()
    send_name_lock_key = ":edmweb:sendtask:sendname:lock:{}".format(send_name)
    if simple_acquire_lock(redis, send_name_lock_key, 120):
        messages.add_message(
            request, messages.SUCCESS,
            _(u'任务%(send_name)s添加成功') % {'send_name': send_name})
        return HttpResponseRedirect('/task/?isvalid=1')

    track_status = data.get('track_status', '')
    track_domain = data.get('track_domain', '')
    send_domain = data.get('send_domain', '')
    send_account = data.get('send_account', '')
    send_qty_remark = data.get('send_addr_count', '')
    is_need_receipt = int(data.get('is_need_receipt', '0'))

    hour_speed = data.get('hour_speed', '')
    try:
        hour_speed = hour_speed and int(hour_speed) or 0
    except:
        hour_speed = 0

    # AB
    is_ab = data.get('is_ab', 'off')
    ab_appraise_qty = data.get('ab_appraise_qty', '0')
    ab_content_limit = data.get('ab_content_limit', '0')
    is_ab = True if is_ab == 'on' else False

    if send_domain == 'all':
        send_acct_type = 'all'
    elif send_domain != 'all' and send_account == 'all':
        send_acct_type = 'domain'
    else:
        send_acct_type = 'address'
    send_acct_domain = send_domain
    send_acct_address = send_account

    send_replyto = data.get('send_replyto', '')
    send_fullname = data.get('send_fullname', '')
    # send_maillist_id = int(data.get('send_maillist', ''))
    send_maillist_ids = data.getlist('send_maillist', '')
    # 兼容历史
    send_maillist_id = 0
    send_maillist = ""

    template_ids = data.getlist('template', '')
    send_qty_type = data.get('send_qty_type', '')
    send_qty = data.get('send_qty', 0)
    send_qty_start = data.get('send_qty_start', 0)
    if send_qty_type == 'limit' and send_qty:
        send_qty, send_qty_start = send_qty, send_qty_start
    else:
        send_qty, send_qty_start = 0, 0
    if send_maillist_ids and len(send_maillist_ids) >= 2:
        send_qty, send_qty_start = 0, 0

    send_date = data.get('send_date', '')
    send_time = send_date if send_date else None
    send_status = int(data.get('send_status', ''))

    # verify_status = 0 if request.user.service().is_verify == '1' else 1
    # 更新跟踪域名
    _existed = CustomerTrackDomain.objects.filter(
        customer=request.user, domain=track_domain).exists()
    if not _existed and track_domain:
        CustomerTrackDomain.objects.create(customer=request.user,
                                           domain=track_domain)

    # 保存指定回复地址
    replyto_obj, _c = SendTaskReplyto.objects.get_or_create(user=request.user)
    replyto_obj.send_replyto = send_replyto
    replyto_obj.save()
    # 保存任务
    obj = SendTask(user=user,
                   send_name=send_name,
                   send_acct_type=send_acct_type,
                   send_acct_domain=send_acct_domain,
                   send_acct_address=send_acct_address,
                   send_replyto=send_replyto,
                   send_fullname=send_fullname,
                   send_maillist=send_maillist,
                   send_maillist_id=send_maillist_id,
                   send_qty=send_qty,
                   send_qty_remark=send_qty_remark,
                   send_qty_start=send_qty_start,
                   send_time=send_time,
                   send_status=send_status,
                   track_status=track_status,
                   track_domain=track_domain,
                   is_need_receipt=is_need_receipt,
                   hour_speed=hour_speed,
                   is_ab=is_ab,
                   ab_appraise_qty=ab_appraise_qty,
                   ab_content_limit=ab_content_limit)

    verify_status = get_verify_status(request.user, obj.get_real_send_qty())
    if verify_status == '0' and send_status == 2:
        obj.send_status = 1
    # elif maillist_obj.is_importing:
    #     obj.send_status = -5
    obj.verify_status = verify_status
    obj.save()
    task_id = obj.id
    SendContent.objects.filter(send_id=task_id).update(isvalid=False)
    for template_id in template_ids:
        if not templates.check_temlates_exists_pc(request, template_id):
            continue
        SendTaskTpl.objects.get_or_create(task_id=task_id,
                                          template_id=template_id)
        content_id = task_tools.organize_msg(task_id, template_id, user,
                                             send_replyto, None,
                                             is_need_receipt, track_domain)
        redis.lpush(
            'edm_web_mail_content_point_queue',
            json.dumps({
                "user_id": user.id,
                'content_id': content_id,
                'track_status': int(track_status),
                'is_need_receipt': is_need_receipt,
                'track_domain': track_domain,
                'task_ident': send_name,
                'send_maillist_id': None,
            }))

    # 关联地址池
    TaskMailList.objects.filter(send_id=task_id).delete()
    for list_id in send_maillist_ids:
        list_customer_id = model_addresses.get_address_userid(request, list_id)
        if not list_customer_id: continue
        # mailistobj = MailList.objects.filter(id=list_id, customer=request.user).first()
        # if not mailistobj: continue
        TaskMailList.objects.get_or_create(send_id=task_id,
                                           maillist_id=list_id)
        # 地址池推送检测
        redis.lpush("zhimeng:qq:check:queue",
                    "{}_{}".format(list_customer_id, list_id))
    # 关联触发器保存
    triggerList = data.getlist("trigger[]", "")
    TriggerSendtaskShip.objects.filter(task_id=task_id).delete()
    bulkTrig = []
    for trigger_id in triggerList:
        bulkTrig.append(
            TriggerSendtaskShip(task_id=task_id, trigger_id=trigger_id))
    if bulkTrig:
        TriggerSendtaskShip.objects.bulk_create(bulkTrig)
    if send_status == 2 and verify_status == '1':
        obj.start()

    # messages.add_message(request, messages.SUCCESS, _(u'任务添加成功'))
    messages.add_message(request, messages.SUCCESS,
                         _(u'任务%(send_name)s添加成功') % {'send_name': send_name})
    return HttpResponseRedirect('/task/?isvalid=1')