Example #1
0
 def create(self, request, *args, **kwargs):
     response = {'status': 0, 'message': 'Something went wrong'}
     data = Box(request.data)
     get_dict = data.to_dict()
     serializer = self.get_serializer(data=get_dict)
     serializer_child = self.serializer_class_secondary(data=get_dict)
     if serializer.is_valid() and serializer_child.is_valid():
         response = {'status': 2, 'message': 'Successfully created.'}
         primary, secondary = self.perform_create(serializer,
                                                  serializer_child,
                                                  get_dict)
     else:
         response.update(unpack_errors(serializer.errors))
         response.update(unpack_errors(serializer_child.errors))
     return Response(response)
Example #2
0
 def put(self, request, *args, **kwargs):
     """
     To Create the WorkState.
     ---
     parameters:
     - name: users
       description: Pass users by comma separeted ids.
       required: true
       type: string
       paramType: form
     """
     response = {'status': 0, 'message': 'Something went wrong.'}
     instance = self.get_object()
     serializer = self.get_serializer(instance,
                                      data=request.data,
                                      partial=False)
     if serializer.is_valid():
         response_ = self.perform_update_(instance, data=request.data)
         if response_.get('status'):
             response = {
                 'status': 2,
                 'message': 'Successfully updated the data.'
             }
         else:
             response = response_
     else:
         response.update(
             self.bo.stripmessage(unpack_errors(serializer.errors)))
     return Response(response)
Example #3
0
 def create(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     response = {'status': 0, 'message': 'Something went wrong.'}
     if serializer.is_valid():
         self.perform_create(serializer)
         response = {
             'status': 2,
             'message': 'Successfully configured survey and workflow.'
         }
     else:
         response.update(
             self.bo.stripmessage(unpack_errors(serializer.errors)))
     return Response(response)
Example #4
0
 def post(self, request, *args, **kwargs):
     response = {'status': 0, 'message': 'Something went wrong.'}
     data = Box(request.data)
     serializer = self.get_serializer(data=data.to_dict())
     if serializer.is_valid():
         response = {'status': 2, 'message': 'Successfully data retrieved'}
         get_data = self.get_queryset().filter(
             curr_user__id=data.user_id,
             batch__current_status__workflow__id=data.workflow_id)
         if get_data:
             get_response = get_data[0]
             response.update(get_response.get_current_status())
         else:
             response.update(name='No Data for the User.')
     else:
         response.update(unpack_errors(serializer.errors))
     return Response(response)
Example #5
0
 def post(self, request, *args, **kwargs):
     response = {'status': 0, 'message': 'Something went wrong.'}
     data = Box(request.data)
     serializer = self.get_serializer(data=data.to_dict())
     if serializer.is_valid():
         get_ = self.get_queryset().filter(id=data.batch_id).order_by('-id')
         if get_:
             response = {
                 'status': 2,
                 'message': 'Successfully data retrieved'
             }
             get_data = get_[0].get_current_batch_status()
             response.update(get_data)
         else:
             response.update(name='No Data for the Batch.')
     else:
         response.update(unpack_errors(serializer.errors))
     return Response(response)
Example #6
0
 def create(self, request, *args, **kwargs):
     response = {'status': 0, 'message': 'Something went wrong.'}
     data = Box(request.data)
     get_dict = data.to_dict()
     serializer = self.get_serializer(data=get_dict)
     if serializer.is_valid():
         get_object = self.perform_create(serializer)
         if self.bo.split_value(data.flow_state):
             get_object.flow_state.add(
                 *self.bo.split_value(data.flow_state))
         tag_survey, created = WorkFlowSurveyRelation.objects.get_or_create(
             workflow=get_object, survey_id=data.survey_id)
         get_object.tag_id = tag_survey.id
         get_object.save()
         response = {'status': 2, 'message': 'Successfully created.'}
     else:
         response.update(
             self.bo.stripmessage(unpack_errors(serializer.errors)))
     return Response(response)
Example #7
0
 def create(self, request, *args, **kwargs):
     data = Box(request.data)
     get_dict = data.to_dict()
     response = {'status': 0, 'message': 'Something went wrong.'}
     serializer = self.get_serializer(data=get_dict)
     if serializer.is_valid():
         ws = self.perform_create(serializer)
         get_response = self.validate(ws, data)
         if get_response.get('status'):
             wsu = WorkStateUserRelation.objects.create(workstate=ws)
             wsu.users.add(*self.bo.split_value(data.users))
             response = {'status': 2, 'message': 'Successfully created.'}
         else:
             ws.delete()
             response.update(self.bo.stripmessage(get_response))
     else:
         response.update(
             self.bo.stripmessage(unpack_errors(serializer.errors)))
     return Response(response)
Example #8
0
 def update(self, request, *args, **kwargs):
     response = {'status': 0, 'message': 'Something went wrong.'}
     data = Box(request.data)
     partial = kwargs.pop('partial', False)
     instance = self.get_object()
     serializer = self.get_serializer(instance,
                                      data=request.data,
                                      partial=partial)
     if serializer.is_valid():
         get_wtf = self.perform_update(instance, data)
         if get_wtf.get('status'):
             response = {
                 'status': 2,
                 'message': 'Successfully Updated the object.'
             }
         else:
             response = get_wtf
     else:
         response.update(
             self.bo.stripmessage(unpack_errors(serializer.errors)))
     return Response(response)
Example #9
0
 def post(self, request, *args, **kwargs):
     response = {'status': 0, 'message': 'Something went wrong.'}
     data = Box(request.data)
     serializer = self.get_serializer(data=data.to_dict())
     if serializer.is_valid():
         get_zero = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             curr_state__id=data.previour_state,
             commented_to__isnull=True).order_by('-id')
         get_first = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             commented_by__id=data.curr_user,
             curr_state__id=data.curr_state_id,
             commented_to__isnull=True).order_by('-id')
         get_second = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             commented_by__id=data.previous_user,
             curr_state__id=data.previour_state,
             commented_to__isnull=True).order_by('-id')
         get_third = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             commented_by__id=data.next_user,
             curr_state__id=data.next_state,
             commented_to__isnull=True).order_by('-id')
         get_fourth = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             commented_by__id=data.curr_user,
             commented_to__id=data.next_user,
             curr_state__id=data.next_state,
             previour_state__id=data.curr_state_id,
         ).order_by('-id')
         get_fifth = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             commented_by__id=data.next_user,
             commented_to__id=data.curr_user,
             curr_state__id=data.curr_state_id).order_by('-id')
         get_sixth = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             commented_by__id=data.previous_user,
             commented_to__id=data.curr_user,
             previour_state__id=data.previour_state).order_by('-id')
         get_seventh = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             commented_by__id=data.curr_user,
             commented_to__id=data.previous_user,
             curr_state__id=data.previour_state).order_by('-id')
         get_eigth = self.get_queryset().filter(
             workflow_cmt__batch__id=data.batch_id,
             curr_state__id=data.next_state).order_by('-id')
         query1 = list(set(list(get_first))) + \
             list(set(list(get_second)))
         query2 = list(set(list(get_third))) + list(set(list(get_zero)))
         query3 = list(set(list(get_fourth))) + \
             list(set(list(get_fifth)))
         query4 = list(set(list(get_sixth))) + \
             list(set(list(get_seventh)))
         query5 = list(set(list(get_eigth)))
         get_ = list(set(query1 + query2 + query3 + query4 + query5))
         get_.sort(key=lambda x: x.id, reverse=True)
         if get_:
             response = {
                 'status': 2,
                 'message': 'Successfully data retrieved'
             }
             get_data = [q.get_current_status() for q in get_]
             response.update(data=get_data)
         else:
             response.update(name='No Data for the WorkFlow.')
     else:
         response.update(unpack_errors(serializer.errors))
     return Response(response)
Example #10
0
 def create(self, request, *args, **kwargs):
     response = {
         'status': 0,
         'message': 'Something went wrong.',
         'name': 'No User or Survey exists.'
     }
     data = Box(request.data)
     serializer = self.get_serializer(data=data.to_dict())
     if serializer.is_valid():
         user_to_native = map(int, [data.user_id])
         response = OrderedDict()
         getwfc = WorkFlowComment.objects.filter(
             batch__current_status__survey__id=data.survey_id,
             batch__id=data.batch_id,
             next_tag_user__id__in=user_to_native).order_by('-id')
         if getwfc:
             get_survey = getwfc[0]
             work_flow_id = get_survey.batch.current_status.workflow.id
             get_workflow_stat = get_survey.batch.current_status.workflow.get_users_work_state(
             )
             get_curren_state = get_workflow_stat.get(int(
                 data.user_id)).get('curr_state_id')
             get_workflow_pre_nxt = get_survey.batch.current_status.workflow.previous_next_state(
                 get_curren_state)
             response.update({
                 'status': 2,
                 'message': 'Successfully retrieved the list.'
             })
             response.update(get_workflow_stat.get(int(data.user_id)))
             response.update(get_workflow_pre_nxt)
             response.update(get_survey.get_batch_id())
         else:
             wf = self.get_queryset().filter(
                 survey__id=data.survey_id,
                 workflow__flow_state__users__id__in=user_to_native)
             if wf:
                 get_survey = wf[0]
                 work_flow_id = get_survey.workflow.id
                 get_workflow_stat = get_survey.workflow.get_users_work_state(
                 )
                 get_curren_state = get_workflow_stat.get(int(
                     data.user_id)).get('curr_state_id')
                 get_workflow_pre_nxt = get_survey.workflow.previous_next_state(
                     get_curren_state)
                 response.update({
                     'status':
                     2,
                     'message':
                     'Successfully retrieved the list.'
                 })
                 response.update(get_workflow_stat.get(int(data.user_id)))
                 response.update(get_workflow_pre_nxt)
         end_key = get_flat_count = 0
         getwfc_status = WorkFlowComment.objects.filter(
             batch__current_status__survey__id=data.survey_id,
             batch__id=data.batch_id,
             batch__current_status__workflow__id=work_flow_id).count()
         get_flow_stat = WorkFlowSurveyRelation.objects.filter(
             survey__id=data.survey_id,
             workflow__id=work_flow_id).order_by('-id')
         if get_flow_stat:
             get_flat_count = get_flow_stat[0].workflow.flow_state.filter(
                 active=2).count()
         if getwfc_status == get_flat_count:
             end_key = 1
         response.update(end_key=end_key)
     else:
         response.update(unpack_errors(serializer.errors))
     return Response(response)
Example #11
0
    def post(self, request, *args, **kwargs):
        response = {'status': 0, 'message': 'Something went wrong.'}
        data = Box(request.data)
        serializer = self.get_serializer(data=data.to_dict())
        if serializer.is_valid():
            get_ = self.get_queryset().filter(
                batch__id=data.batch_id,
                curr_user__id=data.user_id).order_by('-id')
            if get_:
                response = {
                    'status': 2,
                    'message': 'Successfully data retrieved'
                }
                full_data = get_[0]
                get_data = full_data.get_current_status()
                get_types = full_data.batch.current_status.workflow.get_buttons_status(
                )
                response['button_status'] = get_types.get(
                    int(full_data.curr_state.id), 0)
                response.update(get_data)
                response.update(self.get_level_status(full_data))
            else:
                user_to_native = map(int, [data.user_id])
                wf = WorkFlowSurveyRelation.objects.filter(
                    active=2,
                    survey__id=data.survey_id,
                    workflow__flow_state__users__id__in=user_to_native)
                if wf:
                    get_batch = WorkFlowBatch.objects.get(id=data.batch_id)
                    get_survey = wf[0]

                    get_workflow_stat = get_survey.workflow.get_users_work_state(
                    )
                    get_curren_state = get_workflow_stat.get(int(
                        data.user_id)).get('curr_state_id')
                    get_workflow_pre_nxt = get_survey.workflow.previous_next_state(
                        get_curren_state)
                    response.update({
                        'status':
                        2,
                        'message':
                        'Successfully retrieved the list.'
                    })
                    response.update(get_workflow_stat.get(int(data.user_id)))
                    response.update(get_workflow_pre_nxt)
                    response.update(get_batch.get_current_batch_status())
                    get_work = self.get_queryset().filter(
                        batch__id=data.batch_id,
                        previour_state__id=get_curren_state)
                    if get_work:
                        response['previous_state_users'] = ""
                        response['previous_tag_user_id'] = 0
                        response['previous_tag_user_name'] = ''
                        response['next'] = 0
                        response['previous'] = 0
                        response['approved'] = 0
                        response['com_btn'] = 1
                        response['next_user'] = 0
                    else:
                        response['next'] = 1 if not get_workflow_pre_nxt.get(
                            'previour_state_id') else 0
                        response['previous'] = 0
                        response['approved'] = 0
                        response['com_btn'] = 0
                        response['previous_state_users'] = ""
                        response['previous_tag_user_id'] = 0
                        response['previous_tag_user_name'] = ''
                        response['next_user'] = 0
                else:
                    response.update(name='No Data for the WorkFlow.')
        else:
            response.update(unpack_errors(serializer.errors))
        return Response(response)