def reference_job_to_other(request): if request.method == 'POST': job = request.POST.get('rfj') message = request.POST.get('rf') group = request.POST.get('rg') if not validate_integer(job): return _return_error_(_('invalid dashboard'), request) if not validate_empty_str(message): return _return_error_(_('please enter message'), request) if not validate_integer(group): return _return_error_(_('invalid group'), request) dash = get_current_user_dashboard(request.user, True) if int(job) not in dash: return _return_error_(_('invalid dashboard'), request) if not Group.objects.filter(pk=group).exists(): return _return_error_(_('invalid group'), request) d = Dashboard.objects.get(pk=job) if DashboardReferences.objects.filter( dashboard=d.pk, target_group_id=group, source_group_id=d.group_id).exists(): dr = DashboardReferences.objects.get(dashboard=d.pk, target_group_id=group, source_group_id=d.group_id) else: dr = DashboardReferences() if request.user.is_superuser: src_id = d.group_id else: user_groups = request.user.groups.all().values_list('pk', flat=True) if d.group_id in user_groups: src_id = d.group_id else: src_id = user_groups[0] d.last_state = 0 d.save() dr.dashboard = d dr.reason = message dst = Group.objects.get(pk=group) src = Group.objects.get(pk=src_id) dr.target_group = dst dr.source_group = src dr.user = request.user dr.save() uw = UserWorkHistory() uw.group = src uw.dashboard = d uw.message = _('job referenced to other group' ) + ' - ' + dst.name + ' - ' + message uw.start_date = now() uw.state = 5 # referenced uw.user = request.user uw.save() dc = DashboardCurrentGroup.objects.get(dashboard=d.pk) dc.group_id = group dc.save() if check_ajax(request): return HttpResponse('200') return redirect(reverse(view_dashboard) + '?j=%s' % job) return _return_error_('invalid method', request)
def __get_new_notifications__(request): if request.method == 'GET': last_job = get_current_user_dashboard( request.user).filter(last_state=0) jobs = last_job.count() return HttpResponse(jobs) else: return HttpResponse(0)
def start_user_job(request): if request.method == 'GET': job = request.GET.get('sj') job_done = request.GET.get('jd') if not validate_integer(job): return _return_error_(_('invalid dashboard'), request) dash = get_current_user_dashboard(request.user, True) if int(job) not in dash: return _return_error_(_('invalid dashboard'), request) d = Dashboard.objects.get(pk=job) uw = UserWorkHistory() uw.dashboard = d uw.user = request.user uw.state = 2 # Jobs Started uw.message = _('job started') if request.user.is_superuser: uw.group = Group.objects.get(pk=d.group_id) else: uw.group_id = request.user.groups.first().pk uw.start_date = now() uw.save() d.last_state = 2 if validate_integer(job_done) and request.user.has_perm( 'CRM.set_task_done') and d.is_read: d.is_done = True d.done_date = now() uw.state = 3 uw.message = _('job finished') uw.save() d.last_state = 3 remove_calendar_event(d) if not d.reader: d.is_read = True d.reader = request.user to = d.target.content_object if hasattr(to, 'start_job'): to.start_job() if hasattr(to, 'assign_job'): to.assign_job(request.user) d.save() if check_ajax(request): return HttpResponse('200') return redirect(reverse(view_dashboard) + '?j=%s' % job) return _return_error_(_('invalid method'), request)
def get_all(self): """ Get all system status @return: dict contains all status data @rtype: str """ rqu = self.requester res = {} if rqu.has_perm('CRM.view_dashboard') and rqu.is_staff: res['dashboard'] = get_current_user_dashboard(rqu).filter(last_state=0).count() res['today_queue'] = get_today_jobs() if rqu.has_perm('CRM.accept_orders'): res['orders'] = EquipmentOrder.objects.filter(is_processing=False).count() if rqu.has_perm('CRM.view_online_users'): ibs = IBSManager() users = ibs.get_online_users_count() res['online_customers'] = users if rqu.has_perm('CRM.view_online_crm_users'): res['online_personnel'] = UserManager.get_online() res['total_personnel'] = UserManager.get_personnel_count() return json.dumps(list(res))
def set_job_as_canceled(request): ia = check_ajax(request) if request.method == 'POST': dash = request.POST.get('d') if not validate_integer(dash): print '[UNEXPECTED] Dashboard parameters are invalid!' return _return_error_(_('invalid dashboard'), request) dashboards = get_current_user_dashboard(request.user, True) reason = request.POST.get('cre') if not Dashboard.objects.filter(pk=dash).exists(): print '[UNEXPECTED] Dashboard %s not found to cancel' % dash return _return_error_(_('no such dashboard'), request) if int(dash) not in dashboards: print '[UNEXPECTED] Dashboard %s not in user groups' % dash return _return_error_(_('invalid dashboard selected'), request) if not validate_empty_str(reason): return _return_error_(_('please enter reason'), request) dashboard = Dashboard.objects.get(pk=dash) dashboard.is_done = True dashboard.done_date = now() dashboard.last_state = 6 dashboard.save() uw = UserWorkHistory() uw.user = request.user uw.dashboard = dashboard uw.group = Group.objects.get(pk=dashboard.group_id) uw.message = reason uw.start_date = now() uw.state = 6 uw.save() if dashboard.fk_calendar_dashboard.exists(): dashboard.fk_calendar_dashboard.get().delete() if ia: return HttpResponse('200') return redirect(reverse(view_dashboard) + '?j=%s' % dash) if ia: return HttpResponseBadRequest(_('invalid method')) return redirect(reverse(view_dashboard))
def get_job_details(request): if request.method == 'GET': did = request.GET.get('d') if not validate_integer(did): return _return_error_(_('invalid dashboard'), request) current_dash = get_current_user_dashboard(request.user) current_dash_ids = current_dash.values_list('pk', flat=True) is_in_list = False if int(did) in current_dash_ids: is_in_list = True dashboard = Dashboard.objects.get(pk=did) can_start = False can_end = False can_report = False can_cancel = False can_ref = False can_restart = False can_use_calendar = False can_delete_calendar = False can_choose_transport = ( request.user.has_perm('CRM.add_tickettransportation') and not dashboard.is_done and dashboard.is_read and not dashboard.fk_ticket_transportation_dashboard.exists() ) and is_in_list can_delete_transport = request.user.has_perm('CRM.delete_tickettransportation') and not dashboard.is_done and \ dashboard.is_read and \ dashboard.fk_ticket_transportation_dashboard.exists() and is_in_list can_add_partner = request.user.has_perm('CRM.add_ticket_partner') and not \ dashboard.is_done and dashboard.is_read and is_in_list if request.user.has_perm( 'CRM.fill_working_time') and not dashboard.is_done: if dashboard.fk_calendar_dashboard.exists( ) and request.user.has_perm('CRM.delete_calendar'): can_delete_calendar = True and is_in_list else: can_use_calendar = True and is_in_list if request.user.has_perm('CRM.restart_job') and dashboard.is_done: can_restart = True and is_in_list if request.user.has_perm('CRM.reference_to_others'): if not dashboard.is_done: can_ref = True and is_in_list if request.user.has_perm('CRM.cancel_job'): if not dashboard.is_done and dashboard.is_read: can_cancel = True and is_in_list if request.user.has_perm('CRM.add_userworkhistory'): if dashboard.is_read or request.user.has_perm( 'CRM.report_before_start'): if not dashboard.is_done: can_report = True and is_in_list if request.user.has_perm('CRM.start_jobs') and not dashboard.is_read: if dashboard.last_state != 6: # Can not start a canceled job! can_start = True and is_in_list elif request.user.has_perm( 'CRM.set_task_done') and not dashboard.is_done: can_end = True and is_in_list if request.user.has_perm('CRM.view_work_history'): # Fix a Bug In Infinity Loop :( history = list( UserWorkHistory.objects.filter( dashboard_id=did).order_by('start_date').values_list( 'pk', 'user__first_name', 'start_date', 'group__name', 'state', 'message', 'ext')) else: history = [] try: url = dashboard.target.content_object.get_url() can_add_call = False except: url = reverse('show user navigation menu') + '?uid=' + str( dashboard.target_user_id) can_add_call = True target_name = unicode(dashboard.target.content_object) if hasattr(dashboard.target.content_object, 'first_name'): target_name = dashboard.target.content_object.first_name if not dashboard.is_done: max_days = int(read_config('dashboard_expire', 7)) passed_days = datetime.today() - fix_unaware_time( dashboard.create_date) if passed_days.days < 1: passed_days = 1 else: passed_days = passed_days.days passed_percent = (passed_days * 100) / max_days if passed_percent > 100: passed_percent = 100 else: passed_percent = 0 res = { 'detail': { 'title': dashboard.title, 'message': dashboard.message, 'pk': dashboard.pk, 'start_group': dashboard.group.name, 'target': target_name, 'target_link': url, 'user_id': dashboard.target_user_id }, 'can_report': can_report, 'can_start': can_start, 'can_end': can_end, 'can_restart': can_restart, 'can_use_calendar': can_use_calendar, 'can_delete_calendar': can_delete_calendar, 'can_choose_transport': can_choose_transport, 'can_cancel': can_cancel, 'can_ref': can_ref, 'can_add_partner': can_add_partner, 'can_delete_transport': can_delete_transport, 'can_add_call': can_add_call, 'passed_time': passed_percent, 'history': history } x_res = json.dumps(res, default=date_handler) return HttpResponse(x_res) return send_error(request, _('invalid method'))
def get_user_new_jobs(request): uds = get_current_user_dashboard( request.user).filter(is_done=False).values('pk', 'sender__first_name', 'create_date', 'title', 'message') return HttpResponse(json.dumps(list(uds), default=date_handler))
def __get_dashboard__(user): return get_current_user_dashboard(user, True).filter(last_state=0).count()