Ejemplo n.º 1
0
 def destroy(self, request, *args, **kwargs):
     try:
         timelineidlist = request.data.get('timelines')
         timelinelist = []
         lang = request.GET.get('lang')
         if not timelineidlist or not  isinstance(timelineidlist,list):
             raise InvestError(code=20071, msg='except a not null list')
         with transaction.atomic():
             for timelineid in timelineidlist:
                 instance = self.get_object(timelineid)
                 if not (request.user.has_perm('timeline.admin_deleteline') or request.user.has_perm(
                         'timeline.user_deleteline', instance)):
                     raise InvestError(2009, msg='没有相应权限')
                 for link in ['timeline_transationStatus','timeline_remarks']:
                     if link in []:
                         manager = getattr(instance, link, None)
                         if not manager:
                             continue
                         # one to one
                         if isinstance(manager, models.Model):
                             if hasattr(manager, 'is_deleted') and not manager.is_deleted:
                                 raise InvestError(code=2010,msg=u'{} 上有关联数据'.format(link))
                         else:
                             try:
                                 manager.model._meta.get_field('is_deleted')
                                 if manager.all().filter(is_deleted=False).count():
                                     raise InvestError(code=2010,msg=u'{} 上有关联数据'.format(link))
                             except FieldDoesNotExist:
                                 if manager.all().count():
                                     raise InvestError(code=2010,msg=u'{} 上有关联数据'.format(link))
                     else:
                         manager = getattr(instance, link, None)
                         if not manager:
                             continue
                         # one to one
                         if isinstance(manager, models.Model):
                             if hasattr(manager, 'is_deleted') and not manager.is_deleted:
                                 manager.is_deleted = True
                                 manager.save()
                         else:
                             try:
                                 manager.model._meta.get_field('is_deleted')
                                 if manager.all().filter(is_deleted=False).count():
                                     manager.all().update(is_deleted=True)
                             except FieldDoesNotExist:
                                 pass
                 instance.is_deleted = True
                 instance.deleteduser = request.user
                 instance.deletedtime = datetime.datetime.now()
                 instance.save()
                 instance.timeline_transationStatus.all().update(is_deleted=True)
                 instance.timeline_remarks.all().update(is_deleted=True)
                 cache_delete_key(self.redis_key + '_%s' % instance.id)
                 timelinelist.append(TimeLineSerializer(instance).data)
             return JSONResponse(SuccessResponse(returnListChangeToLanguage(timelinelist, lang)))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Ejemplo n.º 2
0
def deleteUpload(request):
    try:
        data = request.data
        record = data.get('record')
        recordDic = read_from_cache(record)
        if recordDic is None:
            raise InvestError(8003, msg='没有这条记录')
        if recordDic['key'] and recordDic['bucket']:
            deleteqiniufile(key=recordDic['key'], bucket=recordDic['bucket'])
        cache_delete_key(record)
        return JSONResponse(SuccessResponse({record: read_from_cache(record)}))
    except InvestError as err:
        return JSONResponse(InvestErrorResponse(err))
    except Exception:
        return JSONResponse(
            ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Ejemplo n.º 3
0
 def update(self, request, *args, **kwargs):
     try:
         timeline = self.get_object()
         if request.user.has_perm(
                 'timeline.admin_changeline') or request.user.has_perm(
                     'timeline.user_changeline',
                     timeline) or request.user in [
                         timeline.proj.takeUser, timeline.proj.makeUser
                     ]:
             pass
         else:
             raise InvestError(2009, msg='没有相应权限')
         data = request.data
         lang = request.GET.get('lang')
         timelinedata = data.pop('timelinedata', None)
         statudata = data.pop('statusdata', None)
         sendmessage = False
         with transaction.atomic():
             newactivetimelinestatu, newtimeline = None, None
             if statudata:
                 timelinetransationStatus = statudata.get(
                     'transationStatus')
                 if timelinetransationStatus:
                     statudata['lastmodifyuser'] = request.user.id
                     statudata['lastmodifytime'] = datetime.datetime.now()
                     statudata['timeline'] = timeline.id
                     statudata['isActive'] = True
                     timelinestatus = timeline.timeline_transationStatus.all(
                     ).filter(transationStatus__id=timelinetransationStatus,
                              is_deleted=False)
                     if timelinestatus.exists():
                         activetimelinestatu = timelinestatus.first()
                         if not activetimelinestatu.isActive:
                             sendmessage = True
                     else:
                         activetimelinestatu = None
                         sendmessage = True
                     timeline.timeline_transationStatus.all().update(
                         isActive=False)
                     timelinestatu = TimeLineStatuCreateSerializer(
                         activetimelinestatu, data=statudata)
                     if timelinestatu.is_valid():
                         newactivetimelinestatu = timelinestatu.save()
                     else:
                         raise InvestError(code=20071,
                                           msg=timelinestatu.errors)
             if timelinedata:
                 timelinedata['lastmodifyuser'] = request.user.id
                 timelinedata['lastmodifytime'] = datetime.datetime.now()
                 timelinedata['datasource'] = request.user.datasource_id
                 timelinedata['proj'] = timeline.proj_id
                 timelinedata['investor'] = timeline.investor_id
                 if timelinedata.get('trader', None) is None:
                     timelinedata['trader'] = timeline.trader_id
                 if timelinedata.get('isClose', None) in [
                         'true', 'True', '1', 1, 'Yes', 'yes'
                 ]:
                     timelinedata['closeDate'] = datetime.datetime.now()
                 else:
                     timelinedata['closeDate'] = None
                 timelineseria = TimeLineUpdateSerializer(timeline,
                                                          data=timelinedata)
                 if timelineseria.is_valid():
                     newtimeline = timelineseria.save()
                 else:
                     raise InvestError(code=20071, msg=timelineseria.errors)
             cache_delete_key(self.redis_key + '_%s' % newtimeline.id)
             if sendmessage:
                 sendmessage_timelineauditstatuchange(
                     newactivetimelinestatu,
                     newtimeline.proj.takeUser, ['app', 'email', 'webmsg'],
                     sender=request.user)
             return JSONResponse(
                 SuccessResponse(
                     returnDictChangeToLanguage(
                         TimeLineSerializer(timeline).data, lang)))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Ejemplo n.º 4
0
 def destroy(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         lang = request.GET.get('lang')
         if request.user.has_perm('org.admin_deleteorg'):
             pass
         elif request.user.has_perm('org.user_deleteorg', instance):
             pass
         else:
             raise InvestError(code=2009)
         with transaction.atomic():
             for link in [
                     'org_users', 'org_orgTransactionPhases', 'org_remarks',
                     'org_unreachuser'
             ]:
                 if link in ['org_users']:
                     manager = getattr(instance, link, None)
                     if not manager:
                         continue
                     # one to one
                     if isinstance(manager, models.Model):
                         if hasattr(
                                 manager,
                                 'is_deleted') and not manager.is_deleted:
                             raise InvestError(
                                 code=2010, msg=u'{} 上有关联数据'.format(link))
                     else:
                         try:
                             manager.model._meta.get_field('is_deleted')
                             if manager.all().filter(
                                     is_deleted=False).count():
                                 raise InvestError(
                                     code=2010,
                                     msg=u'{} 上有关联数据'.format(link))
                         except FieldDoesNotExist:
                             if manager.all().count():
                                 raise InvestError(
                                     code=2010,
                                     msg=u'{} 上有关联数据,且没有is_deleted字段'.
                                     format(link))
                 else:
                     manager = getattr(instance, link, None)
                     if not manager:
                         continue
                     # one to one
                     if isinstance(manager, models.Model):
                         if hasattr(
                                 manager,
                                 'is_deleted') and not manager.is_deleted:
                             manager.is_deleted = True
                             manager.save()
                     else:
                         try:
                             manager.model._meta.get_field('is_deleted')
                             if manager.all().filter(
                                     is_deleted=False).count():
                                 manager.all().update(is_deleted=True)
                         except FieldDoesNotExist:
                             pass
             instance.is_deleted = True
             instance.deleteduser = request.user
             instance.deletetime = datetime.datetime.utcnow()
             instance.save()
             cache_delete_key(self.redis_key + '_%s' % instance.id)
             return JSONResponse(
                 SuccessResponse(
                     returnDictChangeToLanguage(
                         OrgDetailSerializer(instance).data, lang)))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Ejemplo n.º 5
0
 def update(self, request, *args, **kwargs):
     data = request.data
     lang = request.GET.get('lang')
     IPOdate = data.pop('IPOdate', None)
     if IPOdate not in ['None', None, u'None', 'none']:
         data['IPOdate'] = datetime.datetime.strptime(
             IPOdate[0:10], '%Y-%m-%d')
     data['lastmodifyuser'] = request.user.id
     data['lastmodifytime'] = datetime.datetime.now()
     try:
         org = self.get_object()
         if request.user.has_perm('org.admin_changeorg'):
             pass
         elif request.user.has_perm('org.user_changeorg', org):
             pass
         else:
             raise InvestError(code=2009)
         with transaction.atomic():
             orgTransactionPhases = data.pop('orgtransactionphase', None)
             orgupdateserializer = OrgUpdateSerializer(org, data=data)
             if orgupdateserializer.is_valid():
                 org = orgupdateserializer.save()
                 if orgTransactionPhases:
                     transactionPhaselist = TransactionPhases.objects.filter(
                         is_deleted=False).in_bulk(orgTransactionPhases)
                     addlist = [
                         item for item in transactionPhaselist
                         if item not in org.orgtransactionphase.all()
                     ]
                     removelist = [
                         item for item in org.orgtransactionphase.all()
                         if item not in transactionPhaselist
                     ]
                     org.org_orgTransactionPhases.filter(
                         transactionPhase__in=removelist,
                         is_deleted=False).update(
                             is_deleted=True,
                             deletedtime=datetime.datetime.now(),
                             deleteduser=request.user)
                     usertaglist = []
                     for transactionPhase in addlist:
                         usertaglist.append(
                             orgTransactionPhase(
                                 org=org,
                                 transactionPhase_id=transactionPhase,
                                 createuser=request.user,
                                 createdtime=datetime.datetime.now()))
                     org.org_orgTransactionPhases.bulk_create(usertaglist)
             else:
                 raise InvestError(code=20071,
                                   msg='data有误_%s\n%s' %
                                   (orgupdateserializer.error_messages,
                                    orgupdateserializer.errors))
             cache_delete_key(self.redis_key + '_%s' % org.id)
             return JSONResponse(
                 SuccessResponse(
                     returnDictChangeToLanguage(
                         OrgDetailSerializer(org).data, lang)))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))