Beispiel #1
0
 def update(self, request, *args, **kwargs):
     try:
         data = request.data
         token = data.get('token')
         signature = data.get('signature')
         if not checkSubhookKey(token, signature):
             raise InvestError(8888, msg='subhook验证未通过')
         send_id = data.get('send_id')
         data['isSend'] = True
         try:
             emailgroupsend = self.queryset.get(send_id=send_id)
         except emailgroupsendlist.DoesNotExist:
             return JSONResponse(SuccessResponse(None))
         with transaction.atomic():
             emailserializer = Emailgroupsendlistserializer(emailgroupsend,
                                                            data=data)
             if emailserializer.is_valid():
                 newemailgroupsend = emailserializer.save()
                 newemailgroupsend.isRead = True
                 newemailgroupsend.readtime = datetime.datetime.now()
                 newemailgroupsend.save()
             else:
                 raise InvestError(code=20071,
                                   msg='data有误_%s' % emailserializer.errors)
             return JSONResponse(SuccessResponse(None))
     except Exception:
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Beispiel #2
0
def sendProjEmailToUser(proj, user, datasource):
    emailaddress = user['email']
    financeAmount = '$' + str(proj.get('financeAmount_USD',
                                       'xxxxxxxx')) + '(美元)'
    if proj['Location'] == '中国':
        if proj['currency'] == '人民币':
            financeAmount = '¥' + str(proj.get('financeAmount',
                                               'xxxxxxxx')) + '(人民币)'
    data = {
        'proj': proj['id'],
        'projtitle': proj['Title'],
        'user': user['id'],
        'username': user['usernameC'],
        'userMobile': user['mobile'],
        'userEmail': emailaddress,
        'isRead': False,
        'readtime': None,
        'isSend': False,
        'sendtime': datetime.datetime.now(),
        'errmsg': None,
        'datasource': datasource,
    }
    if emailaddress and checkEmailTrue(emailaddress):
        varsdict = {
            'Title': proj['Title'],
            'Location': proj['Location'],
            'Industry': " ".join(proj['Industry']),
            'Tags': " ".join(proj['Tags']),
            'FA': financeAmount,
            'TransactionType': " ".join(proj['TransactionType']),
            'B_introducteC': proj['B_introducteC'],
        }
        response = xsendEmail(emailaddress, Email_project_sign, varsdict)
        if response.get('status') in ['success', True, 1]:
            if 'return' in response:
                if len(response['return']) > 0:
                    data['isSend'] = True
                    data['send_id'] = response['return'][0].get('send_id')
                    data['sendtime'] = datetime.datetime.now()
            data['errmsg'] = repr(response)
        else:
            data['errmsg'] = repr(response)
        emailsend = Emailgroupsendlistserializer(data=data)
        if emailsend.is_valid():
            emailsend.save()
        else:
            raise InvestError(8888,
                              msg='保存submail邮件发送记录失败',
                              detail=emailsend.error_messages)
Beispiel #3
0
 def list(self, request, *args, **kwargs):
     try:
         page_size = request.GET.get('page_size')
         page_index = request.GET.get('page_index')  # 从第一页开始
         if not page_size:
             page_size = 10
         if not page_index:
             page_index = 1
         queryset = self.filter_queryset(
             self.queryset).filter(datasource=request.user.datasource_id)
         sortfield = request.GET.get('sort', 'createdtime')
         desc = request.GET.get('desc', 1)
         queryset = mySortQuery(queryset, sortfield, desc)
         try:
             count = queryset.count()
             queryset = Paginator(queryset, page_size)
             queryset = queryset.page(page_index)
         except EmptyPage:
             return JSONResponse(SuccessResponse({'count': 0, 'data': []}))
         serializer = Emailgroupsendlistserializer(queryset, many=True)
         return JSONResponse(
             SuccessResponse({
                 'count': count,
                 'data': serializer.data
             }))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
 def update(self, request, *args, **kwargs):
     try:
         emailgroupsend = self.get_object()
         with transaction.atomic():
             data = {
                 'isRead': True,
                 'readtime': datetime.datetime.now(),
             }
             emailserializer = Emailgroupsendlistserializer(emailgroupsend,
                                                            data=data)
             if emailserializer.is_valid():
                 emailserializer.save()
             else:
                 raise InvestError(code=20071,
                                   msg='data有误_%s' % emailserializer.errors)
             return JSONResponse(SuccessResponse(emailserializer.data))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
def sendProjEmailToUser(proj, user, datasource):
    emailaddress = user['email']
    data = {
        'proj': proj['id'],
        'projtitle': proj['Title'],
        'user': user['id'],
        'username': user['usernameC'],
        'userEmail': emailaddress,
        'isRead': False,
        'readtime': None,
        'isSend': False,
        'sendtime': datetime.datetime.now(),
        'errmsg': None,
        'datasource': datasource,
    }
    if emailaddress:
        varsdict = {
            'Title': proj['Title'],
            'Location': proj['Location'],
            'Industry': " ".join(proj['Industry']),
            'Tags': " ".join(proj['Tags']),
            'FAUSD': proj['FAUSD'],
            'TransactionType': " ".join(proj['TransactionType']),
            'B_introducteC': proj['B_introducteC'],
        }
        # response = xsendEmail(emailaddress, Email_project_sign, varsdict)
        # if response.get('status'):
        #     data['isSend'] = True
        #     data['sendtime'] = datetime.datetime.now()
        # else:
        #     data['errmsg'] = response
        data['errmsg'] = 'test group send'
    else:
        data['errmsg'] = 'email 缺失'
    emailsend = Emailgroupsendlistserializer(data=data)
    if emailsend.is_valid():
        emailsend.save()
    else:
        logexcption(msg=emailsend.error_messages)