Esempio n. 1
0
 def update(self, request, *args, **kwargs):
     try:
         data = request.data
         lang = request.GET.get('lang')
         instance = self.get_object()
         oldmanager = instance.manager
         data.pop('createuser', None)
         data.pop('datasource', None)
         if request.user.has_perm('BD.manageOrgBD'):
             pass
         elif request.user.has_perm('BD.user_manageOrgBD', instance):
             data = {
                 'bd_status':
                 data.get('bd_status', instance.bd_status_id),
                 'isimportant':
                 bool(data.get('isimportant', instance.isimportant))
             }
         else:
             raise InvestError(2009)
         with transaction.atomic():
             orgBD = OrgBDCreateSerializer(instance, data=data)
             if orgBD.is_valid():
                 neworgBD = orgBD.save()
                 oldmanager_id = data.get('manager', None)
                 if oldmanager_id and oldmanager_id != oldmanager.id:
                     add_perm('BD.user_manageOrgBD', neworgBD.manager,
                              neworgBD)
                     rem_perm('BD.user_manageOrgBD', oldmanager, neworgBD)
                     if request.user != neworgBD.manager:
                         sendmessage_orgBDMessage(
                             neworgBD,
                             receiver=neworgBD.manager,
                             types=['app', 'wenmsg', 'sms'],
                             sender=request.user)
             else:
                 raise InvestError(5004,
                                   msg='机构BD修改失败——%s' %
                                   orgBD.error_messages)
             return JSONResponse(
                 SuccessResponse(
                     returnDictChangeToLanguage(
                         OrgBDSerializer(neworgBD).data, lang)))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Esempio n. 2
0
 def update(self, request, *args, **kwargs):
     try:
         data = request.data
         data.pop('createuser', None)
         data.pop('datasource', None)
         lang = request.GET.get('lang')
         instance = self.get_object()
         oldmanager = instance.manager
         if request.user.has_perm('BD.manageMeetBD'):
             pass
         elif request.user.has_perm('BD.user_manageMeetBD', instance):
             # data = {'comments': data.get('comments', instance.comments),
             #         'attachment': data.get('attachment', instance.attachment),
             #         'attachmentbucket': data.get('attachmentbucket', instance.attachmentbucket),}
             pass
         elif request.user in [
                 instance.proj.takeUser, instance.proj.makeUser
         ]:
             pass
         else:
             raise InvestError(2009)
         with transaction.atomic():
             meetBD = MeetingBDCreateSerializer(instance, data=data)
             if meetBD.is_valid():
                 newMeetBD = meetBD.save()
                 oldmanager_id = data.get('manager', None)
                 if oldmanager_id and oldmanager_id != oldmanager.id:
                     add_perm('BD.user_manageMeetBD', newMeetBD.manager,
                              newMeetBD)
                     rem_perm('BD.user_manageMeetBD', oldmanager, newMeetBD)
             else:
                 raise InvestError(5005,
                                   msg='会议BD修改失败——%s' %
                                   meetBD.error_messages)
             return JSONResponse(
                 SuccessResponse(
                     returnDictChangeToLanguage(
                         MeetingBDSerializer(newMeetBD).data, lang)))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Esempio n. 3
0
 def update(self, request, *args, **kwargs):
     try:
         data = request.data
         lang = request.GET.get('lang')
         instance = self.get_object()
         oldmanager = instance.manager
         data.pop('createuser', None)
         data.pop('datasource', None)
         if request.user.has_perm('BD.manageProjectBD'):
             pass
         elif request.user.has_perm('BD.user_manageProjectBD', instance):
             data = {
                 'bd_status': data.get('bd_status', instance.bd_status_id)
             }
         else:
             raise InvestError(2009)
         with transaction.atomic():
             projectBD = ProjectBDCreateSerializer(instance, data=data)
             if projectBD.is_valid():
                 newprojectBD = projectBD.save()
                 oldmanager_id = data.get('manager', None)
                 if oldmanager_id and oldmanager_id != oldmanager.id:
                     add_perm('BD.user_manageProjectBD',
                              newprojectBD.manager, newprojectBD)
                     rem_perm('BD.user_manageProjectBD', oldmanager,
                              newprojectBD)
             else:
                 raise InvestError(4009,
                                   msg='项目BD修改失败——%s' %
                                   projectBD.error_messages)
             return JSONResponse(
                 SuccessResponse(
                     returnDictChangeToLanguage(
                         ProjectBDSerializer(newprojectBD).data, lang)))
     except InvestError as err:
         return JSONResponse(InvestErrorResponse(err))
     except Exception:
         catchexcption(request)
         return JSONResponse(
             ExceptionResponse(traceback.format_exc().split('\n')[-2]))
Esempio n. 4
0
 def save(self, force_insert=False, force_update=False, using=None,
          update_fields=None):
     if self.pk:
         if self.is_deleted:
             rem_perm('timeline.user_getlineremark', self.createuser, self)
             rem_perm('timeline.user_changelineremark', self.createuser, self)
             rem_perm('timeline.user_deletelineremark', self.createuser, self)
     super(timelineremark, self).save(force_insert, force_update, using, update_fields)
Esempio n. 5
0
 def save(self, *args, **kwargs):
     if not self.datasource or not self.createuser or self.datasource != self.createuser.datasource:
         raise InvestError(code=8888,msg='项目datasource不合法')
     if self.lastProject and (self.lastProject == self.pk or self.lastProject.is_deleted):
         raise InvestError(20071, msg='关联项目不能为自身或者已删除项目')
     if self.pk:
         if self.is_deleted:
             rem_perm('proj.user_getproj',self.createuser,self)
             rem_perm('proj.user_changeproj', self.createuser, self)
             rem_perm('proj.user_deleteproj', self.createuser, self)
     if self.projstatus_id >= 4 and self.is_deleted == False:
         self.checkProjInfo()
     if self.supportUser is None:
         self.supportUser = self.createuser
     if self.code is None:
         self.code = 'P' + datetime.datetime.now().strftime('%Y%m%d%H%M%S')
     if not self.is_deleted and self.isHidden and self.isSendEmail:
         raise InvestError(20071, msg='该项目为隐藏项目, 无法发送群发邮件')
     super(project,self).save(*args, **kwargs)
Esempio n. 6
0
 def save(self,
          force_insert=False,
          force_update=False,
          using=None,
          update_fields=None):
     if not self.datasource or not self.createuser or self.datasource != self.createuser.datasource:
         raise InvestError(code=8888, msg='项目datasource不合法')
     if self.pk:
         if self.is_deleted:
             rem_perm('proj.user_getproj', self.createuser, self)
             rem_perm('proj.user_changeproj', self.createuser, self)
             rem_perm('proj.user_deleteproj', self.createuser, self)
     if self.projstatus_id >= 4 and self.is_deleted == False:
         self.checkProjInfo()
     if self.supportUser is None:
         self.supportUser = self.createuser
     if self.code is None:
         self.code = 'P' + datetime.datetime.now().strftime('%Y%m%d%H%M%S')
     super(project, self).save(force_insert, force_update, using,
                               update_fields)
Esempio n. 7
0
 def save(self,
          force_insert=False,
          force_update=False,
          using=None,
          update_fields=None):
     if not self.proj:
         raise InvestError(code=7004, msg='proj缺失')
     if self.proj.projstatus_id < 4:
         raise InvestError(5003, msg='项目尚未终审发布')
     if self.proj.supportUser and self.proj.supportUser == self.investor:
         raise InvestError(7003, msg='项目上传者不能作为投资人')
     if self.trader.userstatus_id != 2 or self.investor.userstatus_id != 2:
         raise InvestError(2022)
     if self.pk:
         if self.isPublic == False and self.user is None:
             if self.is_deleted:
                 userlist = [
                     self.investor,
                     self.trader,
                     self.createuser,
                     self.proj.makeUser,
                     self.proj.takeUser,
                 ]
                 userlist = set(userlist)
                 for user in userlist:
                     rem_perm('dataroom.user_getdataroom', user, self)
                 rem_perm('dataroom.user_changedataroom', self.investor,
                          self)
             else:
                 oldrela = dataroom.objects.get(pk=self.pk)
                 userlist1 = [
                     oldrela.investor,
                     oldrela.trader,
                     oldrela.createuser,
                     oldrela.proj.makeUser,
                     oldrela.proj.takeUser,
                 ]
                 userlist2 = [
                     self.investor,
                     self.trader,
                     self.createuser,
                     self.proj.makeUser,
                     self.proj.takeUser,
                 ]
                 userset1 = set(userlist1)
                 userset2 = set(userlist2)
                 if userset1 != userset2:
                     for user in userset1:
                         rem_perm('dataroom.user_getdataroom', user, self)
                     rem_perm('dataroom.user_changedataroom',
                              oldrela.investor, self)
                     for user in userset2:
                         add_perm('dataroom.user_getdataroom', user, self)
                     add_perm('dataroom.user_changedataroom', self.investor,
                              self)
         elif self.isPublic == False and self.user is not None:
             if self.is_deleted:
                 userlist = [
                     self.createuser,
                     self.proj.makeUser,
                     self.proj.takeUser,
                 ]
                 userlist = set(userlist)
                 for user in userlist:
                     rem_perm('dataroom.user_getdataroom', user, self)
                 rem_perm('dataroom.user_getdataroom', self.user, self)
                 rem_perm('dataroom.user_changedataroom', self.user, self)
             else:
                 oldrela = dataroom.objects.get(pk=self.pk)
                 userlist1 = [
                     oldrela.createuser,
                     oldrela.proj.makeUser,
                     oldrela.proj.takeUser,
                 ]
                 userlist2 = [
                     self.createuser,
                     self.proj.makeUser,
                     self.proj.takeUser,
                 ]
                 userset1 = set(userlist1)
                 userset2 = set(userlist2)
                 if userset1 != userset2:
                     for user in userset1:
                         rem_perm('dataroom.user_getdataroom', user, self)
                     rem_perm('dataroom.user_getdataroom', oldrela.user,
                              self)
                     rem_perm('dataroom.user_changedataroom', oldrela.user,
                              self)
                     for user in userset2:
                         add_perm('dataroom.user_getdataroom', user, self)
                     add_perm('dataroom.user_getdataroom', self.user, self)
                     add_perm('dataroom.user_changedataroom', self.user,
                              self)
         else:
             pass
     super(dataroom, self).save(force_insert, force_update, using,
                                update_fields)
Esempio n. 8
0
    def save(self,
             force_insert=False,
             force_update=False,
             using=None,
             update_fields=None):
        if not self.createdtime:
            self.createdtime = datetime.datetime.now()
        if self.datasource:
            pass
        else:
            raise InvestError(
                20071, msg='datasource/proj/investor/trader cannot be null')
        if self.proj.projstatus_id < 4:
            raise InvestError(5003, msg='项目尚未终审发布')
        if self.trader.userstatus_id != 2 or self.investor.userstatus_id != 2:
            raise InvestError(2022)
        try:
            if self.pk:
                timeline.objects.exclude(pk=self.pk).get(
                    is_deleted=False,
                    datasource=self.datasource,
                    proj=self.proj,
                    investor=self.investor,
                    trader=self.trader)
            else:
                timeline.objects.get(is_deleted=False,
                                     datasource=self.datasource,
                                     proj=self.proj,
                                     investor=self.investor,
                                     trader=self.trader)
        except timeline.DoesNotExist:
            pass
        else:
            raise InvestError(code=6003)
        if self.pk:
            if self.is_deleted:
                userlist = [
                    self.investor, self.trader, self.createuser,
                    self.proj.makeUser, self.proj.takeUser,
                    self.proj.supportUser
                ]
                userlist = set(userlist)
                for user in userlist:
                    rem_perm('timeline.user_getline', user, self)
                rem_perm('timeline.user_changeline', self.trader, self)
            else:
                oldrela = timeline.objects.get(pk=self.pk)
                userlist1 = [
                    oldrela.investor, oldrela.trader, oldrela.createuser,
                    oldrela.proj.makeUser, oldrela.proj.takeUser,
                    oldrela.proj.supportUser
                ]
                userlist2 = [
                    self.investor, self.trader, self.createuser,
                    self.proj.makeUser, self.proj.takeUser,
                    self.proj.supportUser
                ]
                userset1 = set(userlist1)
                userset2 = set(userlist2)
                if userset1 != userset2:
                    for user in userset1:
                        rem_perm('timeline.user_getline', user, self)
                    rem_perm('timeline.user_changeline', oldrela.trader, self)

                    for user in userset2:
                        add_perm('timeline.user_getline', user, self)
                    add_perm('timeline.user_changeline', self.trader, self)
        super(timeline, self).save(force_insert, force_update, using,
                                   update_fields)