示例#1
0
def home_agent(request):
    if request.session.has_key('agent')and(Agents.objects.get(username=request.session['agent'])).status == 1:
        agent = Agents.objects.get(username=request.session.get('agent'))
        svag = ServiceAgent.objects.filter(agentid=agent).values('serviceid')
        service = Services.objects.filter(id__in=svag)
        list_leader = [sv.leader for sv in service]
        process = Tickets.objects.filter(serviceid__in=service, status__in=[1, 2])
        done = Tickets.objects.filter(status=3, serviceid__in=service)
        tk_open = Tickets.objects.filter(status=0, serviceid__in=service).count()
        tk_processing = TicketAgent.objects.filter(agentid=agent, ticketid__in=process).count()
        tk_done = TicketAgent.objects.filter(agentid=agent, ticketid__in=done).count()
        tp = ServiceAgent.objects.filter(agentid=agent)
        list_tp = ""
        for tp in tp:
            list_tp += str(tp.serviceid.name) + "!"
        content = {
                    'agent': agent,
                    'agent_name': mark_safe(json.dumps(agent.username)),
                    'fullname': mark_safe(json.dumps(agent.fullname)),
                    'service_total': service.count(),
                    'tk_open': tk_open,
                    'tk_processing': tk_processing,
                    'tk_done': tk_done,
                    'noti_noti': agent.noti_noti,
                    'noti_chat': agent.noti_chat,
                    'list_tp': mark_safe(json.dumps(list_tp)),
                    'list_leader': list_leader,
                    'admin': agent.position,
                   }
        if request.method == 'POST':
            if 'tkid' in request.POST:
                ticket = Tickets.objects.get(id=request.POST['tkid'])
                ticket.status = 1
                ticket.save()
                TicketLog.objects.create(agentid=agent, ticketid=ticket, action='nhận xử lý yêu cầu',
                                         date=timezone.now().date(),
                                         time=timezone.now().time())
                TicketAgent.objects.create(agentid=agent, ticketid=ticket)
                user = Agents.objects.get(id=ticket.sender.id)
                if user.receive_email == 1:
                    email = EmailMessage(
                        'nhận xử lý yêu cầu',
                        render_to_string('agent/mail/assign_mail.html',
                                         {'receiver': user,
                                          'domain': (get_current_site(request)).domain,
                                          'sender': agent,
                                          'ticketid': ticket.id}),
                        to=[user.email],
                    )
                    thread = EmailThread(email)
                    thread.start()
            if 'noti_noti' in request.POST:
                agent.noti_noti = 0
                agent.save()
            if 'noti_chat' in request.POST:
                agent.noti_chat = 0
                agent.save()
        return render(request, 'agent/home_agent.html', content)
    else:
        return redirect("/")
示例#2
0
def home_leader(request):
    if request.session.has_key('leader') and (Agents.objects.get(
            username=request.session['leader'])).status == 1:
        if Agents.objects.get(
                username=request.session['leader']).position == 2:
            leader = Agents.objects.get(username=request.session['leader'])
            list_topic = Services.objects.filter(leader=leader)
            list_ticket = {}
            list_ag = {}
            for tp in list_topic:
                list_ticket[tp] = Tickets.objects.filter(serviceid=tp)
                ag = ServiceAgent.objects.filter(serviceid=tp)
                list_ag[tp.name] = [a.agentid for a in ag]
            content = {
                'tickets': list_ticket,
                'leng': len(list_topic),
                'topic': list_topic,
                'list_ag': list_ag,
                'agent_name': mark_safe(json.dumps(leader.username)),
                'fullname': mark_safe(json.dumps(leader.fullname)),
                'topic_all': Services.objects.all(),
                'leader': leader
            }
            if request.method == 'POST':
                if 'close' in request.POST:
                    ticketid = request.POST['close']
                    tk = Tickets.objects.get(id=ticketid)
                    if tk.status == 3:
                        if not TicketAgent.objects.filter(ticketid=tk):
                            tk.status = 0
                            action = "mở lại yêu cầu"
                        else:
                            tk.status = 1
                            action = "xử lý lại yêu cầu"
                    else:
                        tk.status = 3
                        action = "đóng yêu cầu"
                    tk.save()
                    TicketLog.objects.create(agentid=leader,
                                             ticketid=tk,
                                             action=action,
                                             date=timezone.now().date(),
                                             time=timezone.now().time())
                elif 'delete' in request.POST:
                    ticketid = request.POST['delete']
                    tk = Tickets.objects.get(id=ticketid)
                    tk.delete()
                    try:
                        os.remove(r'notification/chat/chat_' + ticketid +
                                  '.txt')
                    except:
                        pass
                elif 'ticketid' in request.POST:
                    list_agent = request.POST['list_agent[]']
                    list_agent = json.loads(list_agent)
                    ticketid = request.POST['ticketid']
                    if not list_agent:
                        try:
                            tk = Tickets.objects.get(id=ticketid)
                            tkag1 = TicketAgent.objects.filter(ticketid=tk)
                            tkag1.delete()
                            tk.status = 0
                            tk.save()
                            action = "nhận xử lý yêu cầu được giao từ quản trị viên"
                            tklog = TicketLog.objects.filter(action=action)
                            tklog.delete()
                        except:
                            tk.status = 0
                            tk.save()
                    else:
                        try:
                            tk = Tickets.objects.get(id=ticketid)
                            tkag1 = TicketAgent.objects.filter(ticketid=tk)
                            tkag1.delete()
                            action = "nhận xử lý yêu cầu được giao từ quản trị viên"
                            tklog = TicketLog.objects.filter(action=action)
                            tklog.delete()
                        except:
                            pass
                        for agentid in list_agent:
                            agent = Agents.objects.get(username=agentid)
                            tk = Tickets.objects.get(id=ticketid)
                            tkag = TicketAgent(agentid=agent, ticketid=tk)
                            tkag.save()
                            tk.status = 1
                            tk.save()
                            action = "nhận xử lý yêu cầu được giao từ quản trị viên"
                            if agent.receive_email == 1:
                                email = EmailMessage(
                                    'Chuyển yêu cầu',
                                    render_to_string(
                                        'agent/mail/forward_mail_leader.html',
                                        {
                                            'receiver': agent,
                                            'domain':
                                            (get_current_site(request)).domain,
                                            'sender': 'Leader'
                                        }),
                                    to=[agent.email],
                                )
                                thread = EmailThread(email)
                                thread.start()
                            TicketLog.objects.create(
                                agentid=agent,
                                ticketid=tk,
                                action=action,
                                date=timezone.now().date(),
                                time=timezone.now().time())
                elif 'ticketid_change' in request.POST:
                    tp = Services.objects.get(id=request.POST['serviceid'])
                    tk = Tickets.objects.get(
                        id=request.POST['ticketid_change'])
                    tk.serviceid = tp
                    tk.save()
            return render(request, 'leader/home_leader.html', content)
        else:
            leader = Agents.objects.get(username=request.session['leader'])
            list_topic = Services.objects.filter(leader_bk=leader)
            list_ticket = {}
            list_ag = {}
            for tp in list_topic:
                list_ticket[tp] = Tickets.objects.filter(serviceid=tp)
                ag = ServiceAgent.objects.filter(serviceid=tp)
                list_ag[tp.name] = [a.agentid for a in ag]
            content = {
                'tickets': list_ticket,
                'leng': len(list_topic),
                'topic': list_topic,
                'list_ag': list_ag,
                'agent_name': mark_safe(json.dumps(leader.username)),
                'fullname': mark_safe(json.dumps(leader.fullname)),
                'topic_all': Services.objects.all(),
                'leader': leader
            }
            if request.method == 'POST':
                if 'close' in request.POST:
                    ticketid = request.POST['close']
                    tk = Tickets.objects.get(id=ticketid)
                    if tk.status == 3:
                        if not TicketAgent.objects.filter(ticketid=tk):
                            tk.status = 0
                            action = "mở lại yêu cầu"
                        else:
                            tk.status = 1
                            action = "xử lý lại yêu cầu"
                    else:
                        tk.status = 3
                        action = "đóng yêu cầu"
                    tk.save()
                    TicketLog.objects.create(agentid=leader,
                                             ticketid=tk,
                                             action=action,
                                             date=timezone.now().date(),
                                             time=timezone.now().time())
                elif 'delete' in request.POST:
                    ticketid = request.POST['delete']
                    tk = Tickets.objects.get(id=ticketid)
                    tk.delete()
                    try:
                        os.remove(r'notification/chat/chat_' + ticketid +
                                  '.txt')
                    except:
                        pass
                elif 'ticketid' in request.POST:
                    list_agent = request.POST['list_agent[]']
                    list_agent = json.loads(list_agent)
                    ticketid = request.POST['ticketid']
                    if not list_agent:
                        try:
                            tk = Tickets.objects.get(id=ticketid)
                            tkag1 = TicketAgent.objects.filter(ticketid=tk)
                            tkag1.delete()
                            tk.status = 0
                            tk.save()
                            action = "nhận xử lý yêu cầu được giao từ quản trị viên"
                            tklog = TicketLog.objects.filter(action=action)
                            tklog.delete()
                        except:
                            tk.status = 0
                            tk.save()
                    else:
                        try:
                            tk = Tickets.objects.get(id=ticketid)
                            tkag1 = TicketAgent.objects.filter(ticketid=tk)
                            tkag1.delete()
                            action = "nhận xử lý yêu cầu được giao từ quản trị viên"
                            tklog = TicketLog.objects.filter(action=action)
                            tklog.delete()
                        except:
                            pass
                        for agentid in list_agent:
                            agent = Agents.objects.get(username=agentid)
                            tk = Tickets.objects.get(id=ticketid)
                            tkag = TicketAgent(agentid=agent, ticketid=tk)
                            tkag.save()
                            tk.status = 1
                            tk.save()
                            action = "nhận xử lý yêu cầu được giao từ quản trị viên"
                            if agent.receive_email == 1:
                                email = EmailMessage(
                                    'Chuyển yêu cầu',
                                    render_to_string(
                                        'agent/mail/forward_mail_leader.html',
                                        {
                                            'receiver': agent,
                                            'domain':
                                            (get_current_site(request)).domain,
                                            'sender': 'Leader'
                                        }),
                                    to=[agent.email],
                                )
                                thread = EmailThread(email)
                                thread.start()
                            TicketLog.objects.create(
                                agentid=agent,
                                ticketid=tk,
                                action=action,
                                date=timezone.now().date(),
                                time=timezone.now().time())
                elif 'ticketid_change' in request.POST:
                    tp = Services.objects.get(id=request.POST['serviceid'])
                    tk = Tickets.objects.get(
                        id=request.POST['ticketid_change'])
                    tk.serviceid = tp
                    tk.save()
            return render(request, 'leader/home_leader.html', content)
    else:
        return redirect("/")
示例#3
0
def inbox(request):
    if request.session.has_key('agent') and (Agents.objects.get(username=request.session['agent'])).status == 1:
        agent = Agents.objects.get(username=request.session.get('agent'))
        admin = agent.position
        svag = ServiceAgent.objects.filter(agentid=agent)
        svag1 = ServiceAgent.objects.filter(agentid=agent).values('serviceid')
        idleader = Services.objects.filter(id__in=svag1).values('leader')
        list_leader = Agents.objects.filter(id__in=idleader)
        list_tp = ""
        for tp1 in svag:
            list_tp += str(tp1.serviceid.name) + "!"
        content = {'forwardin': ForwardTickets.objects.filter(receiverid=agent),
                   'noti_noti': agent.noti_noti,
                   'noti_chat': agent.noti_chat,
                   'addin': AddAgents.objects.filter(receiverid=agent),
                   'agent_name': mark_safe(json.dumps(agent.username)),
                   'fullname': mark_safe(json.dumps(agent.fullname)),
                   'list_tp': mark_safe(json.dumps(list_tp)),
                   'list_leader': list_leader,
                   'admin': admin}
        if request.method == 'POST':

            if 'forward' in request.POST:
                ticket = Tickets.objects.get(id=request.POST['tkid'])
                try:
                    addagent = AddAgents.objects.get(ticketid=ticket, receiverid=agent)
                except ObjectDoesNotExist:
                    pass
                else:
                    addagent.delete()
                fwticket = ForwardTickets.objects.get(ticketid=ticket, receiverid=agent)
                sender = fwticket.senderid
                agticket = TicketAgent.objects.get(ticketid=ticket, agentid=fwticket.senderid)
                fwticket.delete()
                if 'agree' not in request.POST:
                    if sender.receive_email == 1:
                        email = EmailMessage(
                            'Từ chối nhận xử lý yêu cầu',
                            render_to_string('agent/mail/deny_mail.html',
                                             {'receiver': sender,
                                              # 'domain': "113.190.232.90:8892",
                                              'domain': (get_current_site(request)).domain,
                                              'sender': agent}),
                            to=[sender.email]
                        )
                        thread = EmailThread(email)
                        thread.start()
                else:
                    try:
                        TicketAgent.objects.get(ticketid=ticket, agentid=agent)
                    except TicketAgent.DoesNotExist:
                        agticket.agentid = agent
                        agticket.save()
                        action = "nhận xử lý yêu cầu được gửi bởi nhân viên " + sender.username
                        TicketLog.objects.create(agentid=agent, ticketid=ticket, action=action,
                                                 date=timezone.now().date(),
                                                 time=timezone.now().time())
                        if sender.receive_email == 1:
                            email = EmailMessage(
                                'Chấp nhận yêu cầu chuyển đến',
                                render_to_string('agent/mail/accept_mail.html',
                                                 {'receiver': sender,
                                                  # 'domain': "113.190.232.90:8892",
                                                  'domain': (get_current_site(request)).domain,
                                                  'sender': agent}),
                                to=[sender.email]
                            )
                            thread = EmailThread(email)
                            thread.start()
                    else:
                        agticket.delete()
            elif 'add' in request.POST:
                ticket = Tickets.objects.get(id=request.POST['tkid'])
                try:
                    fwticket = ForwardTickets.objects.get(ticketid=ticket, receiverid=agent)
                except ObjectDoesNotExist:
                    pass
                else:
                    fwticket.delete()
                addagent = AddAgents.objects.get(ticketid=ticket, receiverid=agent)
                sender = addagent.senderid
                addagent.delete()
                if 'agree' not in request.POST:
                    if sender.receive_email == 1:
                        email = EmailMessage(
                            'Từ chối',
                            render_to_string('agent/mail/deny_mail.html',
                                             {'receiver': sender,
                                              # 'domain': "113.190.232.90:8892",
                                                'domain': (get_current_site(request)).domain,
                                              'sender': agent}),
                            to=[sender.email]
                        )
                        thread = EmailThread(email)
                        thread.start()
                else:
                    try:
                        TicketAgent.objects.get(ticketid=ticket, agentid=agent)
                    except TicketAgent.DoesNotExist:
                        TicketAgent.objects.create(ticketid=ticket, agentid=agent)
                        action = 'tham gia xử lý yêu cầu'
                        TicketLog.objects.create(agentid=agent, ticketid=ticket, action=action,
                                                 date=timezone.now().date(),
                                                 time=timezone.now().time())
                        if sender.receive_email == 1:
                            email = EmailMessage(
                                'Chấp nhận yêu cầu',
                                render_to_string('agent/mail/accept_mail.html',
                                                 {'receiver': sender,
                                                  # 'domain': "113.190.232.90:8892",
                                                    'domain': (get_current_site(request)).domain,
                                                  'sender': agent}),
                                to=[sender.email]
                            )
                            thread = EmailThread(email)
                            thread.start()
            elif 'noti_noti' in request.POST:
                agent.noti_noti = 0
                agent.save()
            elif 'noti_chat' in request.POST:
                agent.noti_chat = 0
                agent.save()
        return render(request, 'agent/inbox.html', content)
    else:
        return redirect("/")
示例#4
0
def processing_ticket(request):
    if request.session.has_key('agent')and(Agents.objects.get(username=request.session['agent'])).status == 1:
        sender = Agents.objects.get(username=request.session['agent'])
        admin = sender.position
        agent = Agents.objects.exclude(Q(username=request.session['agent']) | Q(position__in=[0, 2, 3]))
        tpag = ServiceAgent.objects.filter(agentid=sender).values('serviceid')
        sv = Services.objects.filter(id__in=tpag)
        idleader = Services.objects.filter(id__in=tpag).values('leader')
        list_leader = Agents.objects.filter(id__in=idleader)
        list_ag = {}
        for t in sv:
            ag = ServiceAgent.objects.filter(serviceid=t, agentid__in=agent)
            list_ag[t.name] = [a.agentid for a in ag]
        form = ForwardForm()
        form1 = AddForm()
        tksd = TicketAgent.objects.filter(agentid=sender)
        tksdpr = Tickets.objects.filter(id__in=tksd.values('ticketid'), status__in=[1, 2])
        service = ServiceAgent.objects.filter(agentid=sender)
        list_tp = ""
        for tp1 in service:
            list_tp += str(tp1.serviceid.name) + "!"
        content = {'list_ag': list_ag,
                   'service': sv,
                   'noti_noti': sender.noti_noti,
                   'noti_chat': sender.noti_chat,
                   'agent': agent, 'ticket': tksdpr,
                   'form': form,
                   'form1': form1,
                   'agent_name': mark_safe(json.dumps(sender.username)),
                   'fullname': mark_safe(json.dumps(sender.fullname)),
                   'list_tp': mark_safe(json.dumps(list_tp)),
                   'list_leader': list_leader,
                   'admin': admin}
        if request.method == 'POST':
            if 'noti_noti' in request.POST:
                sender.noti_noti = 0
                sender.save()
            elif 'noti_chat' in request.POST:
                sender.noti_chat = 0
                sender.save()
            elif 'type' in request.POST:
                if request.POST['type'] == 'forward_agent':
                    list_agent = request.POST['list_agent[]']
                    list_agent = json.loads(list_agent)
                    tk = Tickets.objects.get(id=request.POST['ticketid'])
                    receiver = Agents.objects.filter(username__in=list_agent)
                    text = request.POST['content']
                    for rc in receiver:
                        if rc != sender:
                            try:
                                TicketAgent.objects.get(ticketid=tk, agentid=rc)
                            except ObjectDoesNotExist:
                                try:
                                    ForwardTickets.objects.get(senderid=sender, receiverid=rc, ticketid=tk)
                                except ObjectDoesNotExist:
                                    ForwardTickets.objects.create(senderid=sender, receiverid=rc, ticketid=tk,content=text)
                                    if rc.receive_email == 1:
                                        email = EmailMessage(
                                            'Chuyển yêu cầu',
                                            render_to_string('agent/mail/forward_mail.html',
                                                            {'receiver': rc,
                                                            # 'domain': "113.190.232.90:8892",
                                                            'domain': (get_current_site(request)).domain,
                                                            'sender': sender}),
                                            to=[rc.email],
                                        )
                                        thread = EmailThread(email)
                                        thread.start()
                    return redirect("/agent/processing_ticket")
                elif request.POST['type'] == 'add_agent':
                    list_agent = request.POST['list_agent[]']
                    list_agent = json.loads(list_agent)
                    tk = Tickets.objects.get(id=request.POST['ticketid'])
                    receiver = Agents.objects.filter(username__in=list_agent)
                    text = request.POST['content']
                    for rc in receiver:
                        if rc != sender:
                            try:
                                TicketAgent.objects.get(ticketid=tk,agentid=rc)
                            except ObjectDoesNotExist:
                                try:
                                    AddAgents.objects.get(senderid=sender, receiverid=rc, ticketid=tk)
                                except ObjectDoesNotExist:
                                    AddAgents.objects.create(senderid=sender, receiverid=rc, ticketid=tk, content=text)
                                    if rc.receive_email == 1:
                                        email = EmailMessage(
                                            'Thêm vào xử lý yêu cầu',
                                            render_to_string('agent/mail/add_mail.html',
                                                            {'receiver': rc,
                                                            'domain': "113.190.232.90:8892",
                                                            # 'domain': (get_current_site(request)).domain,
                                                            'sender': sender}),
                                            to=[rc.email]
                                        )
                                        thread = EmailThread(email)
                                        thread.start()
                    return redirect("/agent/processing_ticket")
                elif request.POST['type'] == 'process_done':
                    tkid = request.POST['tkid']
                    stt = request.POST['stt']
                    ticket = Tickets.objects.get(id=tkid)
                    ticket.status = stt
                    ticket.save()
                    action =''
                    if stt == '1':
                        action += 'xử lý lại yêu cầu'
                    else:
                        action += 'xử lý xong yêu cầu'
                        ticket.note = request.POST['comment']
                        ticket.save()
                        user = Agents.objects.get(id=ticket.sender.id)
                        if user.receive_email == 1:
                            email = EmailMessage(
                                'Yêu cầu đã xử lý xong',
                                render_to_string('agent/mail/done_mail.html',
                                                {'receiver': user,
                                                'domain': (get_current_site(request)).domain,
                                                'sender': sender,
                                                'ticketid': ticket.id}),
                                to=[user.email],
                            )
                            thread = EmailThread(email)
                            thread.start()
                    TicketLog.objects.create(agentid=sender, ticketid=ticket,
                                            action=action,
                                            date=timezone.now().date(),
                                            time=timezone.now().time())
                elif request.POST['type'] == 'give_up':
                    ticket = Tickets.objects.get(id=request.POST['tkid'])
                    try:
                        TicketAgent.objects.get(ticketid=ticket)
                    except MultipleObjectsReturned:
                        tk = TicketAgent.objects.get(ticketid=ticket, agentid=sender)
                        tk.delete()
                        TicketLog.objects.create(agentid=sender, ticketid=ticket, action='từ bỏ xử lý yêu cầu',
                                                date=timezone.now().date(),
                                                time=timezone.now().time())
        return render(request, 'agent/processing_ticket.html', content)
    else:
        return redirect("/")