Exemplo n.º 1
0
    def __init__(self, request):
        super(MainCalJSONViewer, self).__init__(request)
        self.events = EventManager(self.request.db)
        self.tickets = TicketManager(self.request.db)
        self.phonecalls = PhoneCallManager(self.request.db)
        self.cases = CaseManager(self.request.db)
        self.docs = DocumentManager(self.request.db)
        self.scandocs = ScannedDocumentsManager(self.request.db)

        self.get_everthing()
Exemplo n.º 2
0
class MainCalJSONViewer(BaseViewer):
    def __init__(self, request):
        super(MainCalJSONViewer, self).__init__(request)
        self.events = EventManager(self.request.db)
        self.tickets = TicketManager(self.request.db)
        self.phonecalls = PhoneCallManager(self.request.db)
        self.cases = CaseManager(self.request.db)
        self.docs = DocumentManager(self.request.db)
        self.scandocs = ScannedDocumentsManager(self.request.db)

        self.get_everthing()

    def _get_start_end_userid(self, user_id=True):
        start = self.request.GET['start']
        end = self.request.GET['end']
        if user_id:
            user_id = self.request.session['user'].id
        return start, end, user_id
        
    def serialize_ticket_current_status_for_calendar(self, cstatus):
        url = self.request.route_url('msl_tickets',
                                     context='viewticket',
                                     id=cstatus.ticket_id)
        status = cstatus.status
        title = cstatus.ticket.title
        data = dict(id=cstatus.ticket_id,
                    #start=cstatus.last_change.isoformat(),
                    start=cstatus.ticket.created.isoformat(),
                    end=cstatus.last_change.isoformat(),
                    title=title,
                    url=url)
        if status == 'pending':
            data['color'] = 'blue'
        return data
        
    def serialize_phonecall_for_calendar(self, pcall, cstatus):
        url = self.request.route_url('msl_phonecalls',
                                     context='view',
                                     id=pcall.id)
        start = pcall.received
        end = cstatus.last_change
        thirty_minutes = timedelta(minutes=30)
        if end - start < thirty_minutes:
            end = start + thirty_minutes
            
        title = pcall.caller
        data = dict(id=pcall.id, start=start.isoformat(),
                    end=end.isoformat(),
                    title=title, url=url)
        if cstatus.status == 'pending':
            data['color'] = 'blue'
            if pcall.callee_id != cstatus.handler_id:
                data['color'] = 'red'
        return data

    def serialize_case_for_calendar(self, cstatus):
        case = cstatus.case
        url = self.request.route_url('msl_cases',
                                     context='view',
                                     id=case.id)
        start = case.created
        end = cstatus.last_change
        thirty_minutes = timedelta(minutes=30)
        if end - start < thirty_minutes:
            end = start + thirty_minutes
            
        title = cstatus.case.name
        data = dict(id=case.id, start=start.isoformat(),
                    end=end.isoformat(),
                    title=title, url=url)
        if cstatus.status == 'pending':
            data['color'] = 'blue'
        return data

    def serialize_scandoc_for_calendar(self, sdoc):
        url = self.request.route_url('msl_scandocs',
                                     context='view',
                                     id=sdoc.created.isoformat())
        start = sdoc.created
        end = start + timedelta(minutes=60)
        data = dict(id=start.isoformat(),
                    start=start.isoformat(),
                    end=end.isoformat(),
                    title='PDF',
                    url=url)
        return data

    def serialize_event(self, event):
        url = self.request.route_url('consult_calendar',
                                     context='view',
                                     id=event.id)
        start = event.start
        end = event.end
        thirty_minutes = timedelta(minutes=30)
        if end - start < thirty_minutes:
            end = start + thirty_minutes
        title = event.title
        id = event.id
        data = dict(id=str(id), title=title,
                    start=start.isoformat(),
                    end=end.isoformat(), url=url)
        return data
    


    def get_tickets(self):
        start, end, user_id = self._get_start_end_userid()
        serialize = self.serialize_ticket_current_status_for_calendar
        clist = set()
        for ctype in ['assigned', 'pending', 'unread', 'delegated']:
            method = getattr(self.tickets, 'get_%s' % ctype)
            clist = clist.union(
                set(method(user_id, start, end, timestamps=True)))
        return [serialize(cstatus) for cstatus in list(clist)]
        
    def get_calls(self):
        start, end, user_id = self._get_start_end_userid()
        serialize = self.serialize_phonecall_for_calendar
        #context = self.request.matchdict['context']
        clist = set()
        for ctype in ['received', 'taken',
                      'assigned', 'pending', 'unread', 'delegated']:
            method = getattr(self.phonecalls, 'get_%s_calls' % ctype)
            clist = clist.union(
                set(method(user_id, start, end, timestamps=True)))
        return [serialize(pc, cstatus) for pc, cstatus in list(clist)]
        
    def get_cases(self):
        start, end, user_id = self._get_start_end_userid()
        serialize = self.serialize_case_for_calendar
        clist = self.cases.get_accessible(user_id, start, end, timestamps=True)

        return [serialize(cstatus) for cstatus in clist]

    def get_documents(self):
        start, end, user_id = self._get_start_end_userid()
        sdocs = self.scandocs.get_documents(start, end, timestamps=True)
        serialize = self.serialize_scandoc_for_calendar
        return [serialize(doc) for doc in sdocs]

    def get_events(self):
        start, end, user_id = self._get_start_end_userid()
        events = self.events.get_events(user_id, start, end, timestamps=True)
        return [self.serialize_event(e) for e in events]
    
    def get_everthing(self):
        tickets = self.get_tickets()
        phonecalls = self.get_calls()
        cases = self.get_cases()
        sdocs = self.get_documents()
        events = self.get_events()
        
        for t in tickets:
            t['color'] = 'green'
        for p in phonecalls:
            p['color'] = 'yellow'
            p['textColor'] = 'black'
        for c in cases:
            c['color'] = 'purple'
        for d in sdocs:
            d['color'] = '#8B7355'
        for e in events:
            e['color'] = 'RoyalBlue'
            
        self.response = tickets + phonecalls + cases + sdocs + events
Exemplo n.º 3
0
 def assign_to_case(self, doc_id, case_id, user_id):
     cases = CaseManager(self.session)
     casedoc = cases.attach_document(case_id, doc_id, user_id)
     self._tidy_assignments(doc_id)
     return casedoc