예제 #1
0
class ScannedDocumentsJSONViewer(BaseViewer):
    def __init__(self, request):
        super(ScannedDocumentsJSONViewer, self).__init__(request)
        self.sdm = ScannedDocumentsManager(self.request.db)
        self.render_docs()
        
    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 _get_start_end_userid(self):
        start = self.request.GET['start']
        end = self.request.GET['end']
        user_id = self.request.session['user'].id
        return start, end, user_id

    def render_docs(self):
        start, end, user_id = self._get_start_end_userid()
        serialize = self.serialize_scandoc_for_calendar
        dlist = self.sdm.get_documents(start, end, timestamps=True)
        self.response = [serialize(doc) for doc in dlist]
예제 #2
0
파일: main.py 프로젝트: umeboshi2/mslemon
    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()
예제 #3
0
class ScannedDocumentsViewer(BaseViewer):
    def __init__(self, request):
        super(ScannedDocumentsViewer, self).__init__(request)
        prepare_main_layout(self.request)
        self.sdm = ScannedDocumentsManager(self.request.db)
        dirname = self.request.registry.settings['mslemon.scans.directory']
        self.sdm.set_scans_directory(dirname)
        self.sdm.update_database()
        self.dtformat = '%A - %B %d %H:%m'
        
        self._dispatch_table = dict(
            main=self.main_view,
            export=self.export_document,
            view=self.view_document,)
        self.context = self.request.matchdict['context']
        self._view = self.context

        self.dispatch()

    def main_view(self):
        template = 'mslemon:templates/msl/main-scandoc-view.mako'
        default_view = 'agendaDay'
        env = dict()
        content = self.render(template, env)
        self.layout.content = content
        self.layout.resources.main_scandoc_view.need()
        #self.layout.resources.cornsilk.need()


    def _name_document_form_submitted(self, sdoc, form):
        controls = self.request.POST.items()
        self.layout.subheader = "Name submitted to database"
        try:
            data = form.validate(controls)
        except deform.ValidationFailure, e:
            self.layout.content = e.render()
            return
        name = data['name']
        user_id = self.request.session['user'].id
        self.sdm.name_document(sdoc.created, name, user_id)
        self.response = HTTPFound(self.url(context='main', id='all'))
예제 #4
0
    def __init__(self, request):
        super(ScannedDocumentsViewer, self).__init__(request)
        prepare_main_layout(self.request)
        self.sdm = ScannedDocumentsManager(self.request.db)
        dirname = self.request.registry.settings['mslemon.scans.directory']
        self.sdm.set_scans_directory(dirname)
        self.sdm.update_database()
        self.dtformat = '%A - %B %d %H:%m'
        
        self._dispatch_table = dict(
            main=self.main_view,
            export=self.export_document,
            view=self.view_document,)
        self.context = self.request.matchdict['context']
        self._view = self.context

        self.dispatch()
예제 #5
0
 def __init__(self, request):
     super(ScannedDocumentsJSONViewer, self).__init__(request)
     self.sdm = ScannedDocumentsManager(self.request.db)
     self.render_docs()
예제 #6
0
파일: main.py 프로젝트: umeboshi2/mslemon
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