def create_feedback(sms_dict, phone_number, email, name, dealer_email, with_detail=False): ''' Save the feedback or complain from SA and sends SMS for successfully receive ''' manager_obj = User.objects.get(groups__name=Roles.SDMANAGERS) try: servicedesk_user = create_servicedesk_user(name, phone_number, email) if with_detail: gladminds_feedback_object = models.Feedback(reporter=servicedesk_user, type=sms_dict['type'], summary=sms_dict['summary'], description=sms_dict['description'], status="Open", created_date=datetime.datetime.now() ) else: gladminds_feedback_object = models.Feedback(reporter=servicedesk_user, message=sms_dict['message'], status="Open", created_date=datetime.datetime.now() ) gladminds_feedback_object.save() if sms_dict['file_location']: file_obj = sms_dict['file_location'] filename_prefix = gladminds_feedback_object.id filename_suffix = str(uuid.uuid4()) ext = file_obj.name.split('.')[-1] file_obj.name = 'GM'+str(filename_prefix)+'_'+'_'+filename_suffix+'.'+ext destination = settings.SDFILE_DIR.format(settings.ENV) bucket = settings.SDFILE_BUCKET path = utils.upload_file(destination, bucket, file_obj, logger_msg="SDFile") gladminds_feedback_object.file_location = path gladminds_feedback_object.save() message = templates.get_template('SEND_RCV_FEEDBACK').format(type=gladminds_feedback_object.type) except Exception as ex: LOG.error(ex) message = templates.get_template('SEND_INVALID_MESSAGE') finally: LOG.info("Send complain message received successfully with %s" % message) if phone_number: phone_number = utils.get_phone_number_format(phone_number) sms_log(settings.BRAND, receiver=phone_number, action=AUDIT_ACTION, message=message) send_job_to_queue(send_servicedesk_feedback_detail, {"phone_number":phone_number, "message":message, "sms_client":settings.SMS_CLIENT}) if dealer_email: context = utils.create_context('FEEDBACK_DETAIL_TO_DEALER', gladminds_feedback_object) send_dealer_feedback(context, dealer_email) context = utils.create_context('FEEDBACK_DETAIL_TO_ADIM', gladminds_feedback_object) send_feedback_received(context, manager_obj.email) context = utils.create_context('FEEDBACK_CONFIRMATION', gladminds_feedback_object) send_servicedesk_feedback(context, get_reporter_details(gladminds_feedback_object.reporter, "email")) return {'status': True, 'message': message}
def create_feedback(sms_dict, phone_number, email, name, dealer_email, user, with_detail=False): ''' Save the feedback or complain from SA and sends SMS for successfully receive ''' manager_obj = User.objects.get(groups__name=Roles.SDMANAGERS) try: servicedesk_user = create_servicedesk_user(name, phone_number, email) sub_category = get_model('DepartmentSubCategories').objects.get(id=sms_dict['sub-department']) if json.loads(sms_dict['sub-department-assignee']): sub_department_assignee = get_model('ServiceDeskUser').objects.filter(id=sms_dict['sub-department-assignee']) else: sub_department_assignee = '' if len(sub_department_assignee)>0: gladminds_feedback_object = get_model('Feedback')(reporter=servicedesk_user, type=sms_dict['type'], summary=sms_dict['summary'], description=sms_dict['description'], status="Open", created_date=datetime.datetime.now(), priority=sms_dict['priority'], sub_department = sub_category, assignee=sub_department_assignee[0] ) else: gladminds_feedback_object = get_model('Feedback')(reporter=servicedesk_user, type=sms_dict['type'], summary=sms_dict['summary'], description=sms_dict['description'], status="Open", created_date=datetime.datetime.now(), priority=sms_dict['priority'], sub_department = sub_category ) gladminds_feedback_object.save(using=settings.BRAND) update_feedback_activities(gladminds_feedback_object, SDActions.STATUS, None, gladminds_feedback_object.status, user) if gladminds_feedback_object.assignee: date = set_due_date(sms_dict['priority'], gladminds_feedback_object) gladminds_feedback_object.due_date = date['due_date'] gladminds_feedback_object.reminder_date = date['reminder_date'] gladminds_feedback_object.save(using=settings.BRAND) if sms_dict['file_location']: file_obj = sms_dict['file_location'] filename_prefix = gladminds_feedback_object.id filename_suffix = str(uuid.uuid4()) ext = file_obj.name.split('.')[-1] file_obj.name = 'GM'+str(filename_prefix)+'_'+'_'+filename_suffix+'.'+ext destination = settings.SDFILE_DIR.format(settings.ENV) bucket = settings.SDFILE_BUCKET path = utils.upload_file(destination, bucket, file_obj, logger_msg="SDFile") gladminds_feedback_object.file_location = path gladminds_feedback_object.save(using=settings.BRAND) message = templates.get_template('SEND_RCV_FEEDBACK').format(type="feedback") except Exception as ex: LOG.error(ex) message = templates.get_template('SEND_INVALID_MESSAGE') finally: LOG.info("Send complain message received successfully with %s" % message) if phone_number: phone_number = utils.get_phone_number_format(phone_number) sms_log(settings.BRAND, receiver=phone_number, action=AUDIT_ACTION, message=message) LOG.info("[create_feedback]: {0}".format(settings.SMS_CLIENT)) send_job_to_queue(send_servicedesk_feedback_detail, {"phone_number":phone_number, "message":message, "sms_client":settings.SMS_CLIENT}) if dealer_email: context = utils.create_context('FEEDBACK_DETAIL_TO_DEALER', gladminds_feedback_object) send_dealer_feedback(context, dealer_email) context = utils.create_context('FEEDBACK_DETAIL_TO_ADIM', gladminds_feedback_object) send_feedback_received(context, manager_obj.email) context = utils.create_context('FEEDBACK_CONFIRMATION', gladminds_feedback_object) send_servicedesk_feedback(context, get_reporter_details(gladminds_feedback_object.reporter, "email")) return {'status': True, 'message': message}