def ml_unsubscribe_list(request, list_id): obj = model_addresses.get_address_obj(request, list_id) user_id = obj.customer_id subject = model_addresses.get_subject(request, list_id, obj) cr = connections['mm-pool'].cursor() address_sqls.checkTable(cr, user_id) if request.method == "POST": obj2 = get_object(MailList, request.user, list_id) tablename = 'ml_unsubscribe_' + str(request.user.id) address = request.POST.get('address', '') id = request.POST.get('id', False) status = int(request.POST.get('status', False)) if int(status) == -2: # 删除 sql = u"DELETE FROM {0} WHERE list_id={1} AND address='{2}'".format( tablename, id, address) cr.execute(sql) redis = get_redis_connection() redis.rpush(EDM_WEB_USER_MAIL_IMPORT_COUNT_QUEUE, '{}_{}'.format(request.user.id, list_id)) messages.add_message(request, messages.SUCCESS, _(u'删除成功')) return HttpResponseRedirect("/address/unsubscribe/{}/".format(list_id)) return render(request, 'address/ml_unsubscribe_list.html', context={ 'subject': subject, 'list_id': list_id })
def ml_subscribe_list(request, list_id): obj = model_addresses.get_address_obj(request, list_id) user_id = obj.customer_id if request.user.id == user_id: is_modify_flag = obj.is_allow_export else: is_modify_flag = False # obj = get_object(MailList, request.user, list_id) # is_modify_flag = obj.is_allow_export subject = model_addresses.get_subject(request, list_id, obj) is_subscribe = request.GET.get('is_subscribe', '') cr = connections['mm-pool'].cursor() address_sqls.checkTable(cr, user_id) if request.method == "POST": obj2 = get_object(MailList, request.user, list_id) tablename = 'ml_subscriber_' + str(request.user.id) id = request.POST.get('id', False) ids = request.POST.get('ids', '') status = int(request.POST.get('status', False)) redis = get_redis_connection() if int(status) == -2: # 单个删除 sql = "DELETE FROM {0} WHERE address_id={1}".format(tablename, id) cr.execute(sql) messages.add_message(request, messages.SUCCESS, _(u'成功删除')) redis.rpush(EDM_WEB_USER_MAIL_IMPORT_COUNT_QUEUE, '{}_{}'.format(request.user.id, list_id)) return HttpResponseRedirect( "/address/subscribe/{}/".format(list_id)) if int(status) == -1: # 批量删除 sql = "DELETE FROM {0} WHERE address_id IN ({1})".format( tablename, ids) cr.execute(sql) messages.add_message(request, messages.SUCCESS, _(u'成功删除')) redis.rpush(EDM_WEB_USER_MAIL_IMPORT_COUNT_QUEUE, '{}_{}'.format(request.user.id, list_id)) return HttpResponseRedirect( "/address/subscribe/{}/".format(list_id)) var_lists = get_addr_var_fields(cr, request.user.id) field_lists = [] for i in xrange(len(var_lists) - 10): field_lists.append(u'变量{}'.format(11 + i)) return render(request, 'address/ml_subscribe_list.html', context={ 'subject': subject, 'list_id': list_id, 'is_subscribe': is_subscribe, 'field_lists': field_lists, 'is_modify_flag': is_modify_flag, })
def ajax_subscribe_list(request, list_id): data = request.GET order_column = data.get('order[0][column]', '') order_dir = data.get('order[0][dir]', '') search = data.get('search[value]', '') is_subscribe = data.get('is_subscribe', '') colums = [ 'address_id', 'address_id', 'address', 'is_subscribe', 'activity' ] obj = model_addresses.get_address_obj(request, list_id) user_id = obj.customer_id if request.user.id == user_id: is_modify_flag = obj.is_allow_export else: is_modify_flag = False # obj = get_object(MailList, request.user, list_id) # is_modify_flag = obj.is_allow_export where_str = u'list_id={}'.format(list_id) if is_subscribe == '1': where_str += u" and is_subscribe=0 " elif is_subscribe == '2': where_str += u" and is_subscribe=1 " elif is_subscribe == '3': where_str += u" and is_subscribe=2 " order_by_str = '' if order_column and int(order_column) < len(colums): if order_dir == 'desc': order_by_str = u'order by %s desc' % colums[int(order_column)] else: order_by_str = u'order by %s asc' % colums[int(order_column)] if not is_modify_flag: if validators.check_email(search): where_str += u""" and address='{}' """.format(search) elif search: where_str += u""" and 1=0 """ elif is_modify_flag and search: where_str += u""" and address like '%{0}%' """.format(search) cr = connections['mm-pool'].cursor() tablename = 'ml_subscriber_' + str(user_id) sql = u"SELECT COUNT(1) FROM %s WHERE %s;" % (tablename, where_str) cr.execute(sql) rows = cr.fetchall() count = rows[0][0] var_lists = get_addr_var_fields(cr, user_id) field_str = ','.join(var_lists) try: length = int(data.get('length', 1)) except ValueError: length = 1 if not is_modify_flag and length > 25: length = 25 else: length = min(length, 500) try: start_num = int(data.get('start', '0')) except ValueError: start_num = 0 if start_num >= count: start_num = 0 page = start_num / length + 1 if not is_modify_flag and page > 5: rows = [] else: limit_str = u'limit %s offset %s' % (length, start_num) sql = u""" SELECT address_id, address, fullname, is_subscribe, sex, birthday, phone, activity, area, created, updated, %s FROM %s WHERE %s %s %s; """ % (field_str, tablename, where_str, order_by_str, limit_str) cr.execute(sql) rows = cr.fetchall() rs = { "sEcho": 0, "iTotalRecords": count, "iTotalDisplayRecords": count, "aaData": [] } # number = length * (page - 1) + 1 _lambda_var = lambda s: s if s else '' for r in rows: address_id, address, fullname, is_subscribe, sex, birthday, phone, activity, area, created, updated = r[: 11] varList = [_lambda_var(i) for i in list(r[11:])] if is_modify_flag: operate = u""" <a data-toggle="modal" href="/address/subscribe/modify/{0}/{1}/" data-target="#myModal" data-whatever="" class="btn btn-outline btn-primary btn-xs">{2}</a> <a type="button" class="btn btn-outline btn-danger btn-xs" href="Javascript: SetStatus({1}, '-2')">{3}</a> """.format(list_id, address_id, _(u'修改'), _(u'删除')) else: operate = "" issubscribe = u'是' if is_subscribe else u'否' if sex == 'M': sex = _(u'男') elif sex == 'F': sex = _(u"女") else: sex = '' activity_obj = EmailOpenClick.objects.filter(email=address).first() activity = activity_obj.activity if activity_obj else 0 birthday = birthday if birthday != '0000-00-00' else '-' activity_s = u'<i class="fa fa-star myself-text-color-ccc"></i>' * 5 if 0 < activity < 5: activity_r = u'<i class="fa fa-star text-primary"></i>' * activity activity_v = u'<i class="fa fa-star myself-text-color-ccc"></i>' * ( 5 - activity) activity_s = u"{}{}".format(activity_r, activity_v) elif activity >= 5: activity_s = u'<i class="fa fa-star text-primary"></i>' * 5 other = u""" <span class="text-nowrap">{6}: <span>{0}</span></span><br> <span class="text-nowrap">{7}: <span>{1}</span></span><br> <span class="text-nowrap">{8}: <span>{2}</span></span><br> <span class="text-nowrap">{9}: <span>{3}</span></span><br> <span class="text-nowrap">{10}: <span>{4}</span></span><br> <span class="text-nowrap display_none">{11}: <span>{5}</span></span><br> """.format(fullname, sex, show_click_date(birthday), phone, area, activity_s, _(u'姓名'), _(u'性别'), _(u'生日'), _(u'手机'), _(u'地区'), _(u'活跃度')) aaData = [address_id, address, issubscribe, other] + varList + [ # u"<span class='text-nowrap'>{}</span><br><span class='text-nowrap'>{}</span>".format( # show_click_datetime(created), show_click_datetime(updated) # ), operate, "", ] rs["aaData"].append(aaData) # number += 1 return HttpResponse(json.dumps(rs, ensure_ascii=False), content_type="application/json")
def ajax_unsubscribe_list(request, list_id): data = request.GET order_column = data.get('order[0][column]', '') order_dir = data.get('order[0][dir]', '') search = data.get('search[value]', '') colums = ['list_id', 'address', 'datetime'] obj = model_addresses.get_address_obj(request, list_id) user_id = obj.customer_id if request.user.id == user_id: is_modify_flag = obj.is_allow_export else: is_modify_flag = False where_str = u'list_id={}'.format(list_id) if search: where_str += u""" and address like '%{0}%' """.format(search) order_by_str = '' if order_column and int(order_column) < len(colums): if order_dir == 'desc': order_by_str = u'order by %s desc' % colums[int(order_column)] else: order_by_str = u'order by %s asc' % colums[int(order_column)] cr = connections['mm-pool'].cursor() tablename = 'ml_unsubscribe_' + str(user_id) count_sql = u"SELECT COUNT(1) FROM %s WHERE %s;" % (tablename, where_str) cr.execute(count_sql) rows = cr.fetchall() count = rows[0][0] try: length = int(data.get('length', 1)) except ValueError: length = 1 try: start_num = int(data.get('start', '0')) except ValueError: start_num = 0 if start_num >= count: start_num = 0 limit_str = u'limit %s offset %s' % (length, start_num) sql = u"SELECT address, datetime, list_id FROM %s WHERE %s %s %s" % ( tablename, where_str, order_by_str, limit_str) cr.execute(sql) rows = cr.fetchall() rs = { "sEcho": 0, "iTotalRecords": count, "iTotalDisplayRecords": count, "aaData": [] } page = start_num / length + 1 number = length * (page - 1) + 1 for r in rows: if is_modify_flag: modify_str = u'''<a type="button" class="btn btn-outline btn-danger btn-xs" href="Javascript: SetStatus({}, '{}', '-2')">{}</a>'''.format( r[2], r[0], _(u'删除')) else: modify_str = "" rs["aaData"].append([ number, r[0], dateformat(r[1], 'Y-m-d H:i:s'), modify_str, "", ]) number += 1 return HttpResponse(json.dumps(rs, ensure_ascii=False), content_type="application/json")