Ejemplo n.º 1
0
    def process_request(self, req):
        req.perm.require('WORK_VIEW')
        
        messages = []

        def addMessage(s):
            messages.extend([s]);

        # General protection (not strictly needed if Trac behaves itself)
        if not re.search('/worklog', req.path_info):
            return None
        
        add_stylesheet(req, "worklog/worklogplugin.css")

        # Specific pages:
        match = re.search('/worklog/users/(.*)', req.path_info)
        if match:
          mgr = WorkLogManager(self.env, self.config, match.group(1))
          if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log('user'))
            return None
          
          data = {"worklog": mgr.get_work_log('user'),
                  "ticket_href": req.href.ticket(),
                  "usermanual_href":req.href.wiki(user_manual_wiki_title),
                  "usermanual_title":user_manual_title
                  }
          return 'worklog_user.html', data, None

        match = re.search('/worklog/stop/([0-9]+)', req.path_info)
        if match:
          ticket = match.group(1)
          data = {'worklog_href': req.href.worklog(),
                  'ticket_href':  req.href.ticket(ticket),
                  'ticket':       ticket,
                  'action':       'stop',
                  'label':        'Stop Work'}
          xhr = req.get_header('X-Requested-With') == 'XMLHttpRequest'
          if xhr:
              data['xhr'] = True
          return 'worklog_stop.html', data, None
        
        mgr = WorkLogManager(self.env, self.config, req.authname)
        if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log())
            return None
        
        # Not any specific page, so process POST actions here.
        if req.method == 'POST':
            if req.args.has_key('startwork') and req.args.has_key('ticket'):
                if not mgr.start_work(req.args['ticket']):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You are now working on ticket #%s.' % (req.args['ticket'],))
                
                req.redirect(req.args['source_url'])
                return None
                
            elif req.args.has_key('stopwork'):
                stoptime = None
                if req.args.has_key('stoptime') and req.args['stoptime']:
                    stoptime = int(req.args['stoptime'])

                comment = ''
                if req.args.has_key('comment'):
                    comment = req.args['comment']

                if not mgr.stop_work(stoptime, comment):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You have stopped working.')
                
                req.redirect(req.args['source_url'])
                return None
        
        # no POST, so they're just wanting a list of the worklog entries
        data = {"messages": messages,
                "worklog": mgr.get_work_log('summary'),
                "worklog_href": req.href.worklog(),
                "ticket_href": req.href.ticket(),
                "usermanual_href": req.href.wiki(user_manual_wiki_title),
                "usermanual_title": user_manual_title
                }
        return 'worklog.html', data, None
Ejemplo n.º 2
0
    def process_request(self, req):
        req.perm.require('WORK_VIEW')

        messages = []

        def addMessage(s):
            messages.extend([s])

        # General protection (not strictly needed if Trac behaves itself)
        if not re.search('/worklog', req.path_info):
            return None

        add_stylesheet(req, "worklog/worklogplugin.css")

        # Specific pages:
        match = re.search('/worklog/users/(.*)', req.path_info)
        if match:
            mgr = WorkLogManager(self.env, self.config, match.group(1))
            if req.args.has_key('format') and req.args['format'] == 'csv':
                self.worklog_csv(req, mgr.get_work_log('user'))
                return None

            data = {
                "worklog": mgr.get_work_log('user'),
                "ticket_href": req.href.ticket(),
                "usermanual_href": req.href.wiki(user_manual_wiki_title),
                "usermanual_title": user_manual_title
            }
            return 'worklog_user.html', data, None

        match = re.search('/worklog/stop/([0-9]+)', req.path_info)
        if match:
            ticket = match.group(1)
            data = {
                'worklog_href': req.href.worklog(),
                'ticket_href': req.href.ticket(ticket),
                'ticket': ticket,
                'action': 'stop',
                'label': 'Stop Work'
            }
            xhr = req.get_header('X-Requested-With') == 'XMLHttpRequest'
            if xhr:
                data['xhr'] = True
            return 'worklog_stop.html', data, None

        mgr = WorkLogManager(self.env, self.config, req.authname)
        if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log())
            return None

        # Not any specific page, so process POST actions here.
        if req.method == 'POST':
            if req.args.has_key('startwork') and req.args.has_key('ticket'):
                if not mgr.start_work(req.args['ticket']):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You are now working on ticket #%s.' %
                               (req.args['ticket'], ))

                req.redirect(req.args['source_url'])
                return None

            elif req.args.has_key('stopwork'):
                stoptime = None
                if req.args.has_key('stoptime') and req.args['stoptime']:
                    stoptime = int(req.args['stoptime'])

                comment = ''
                if req.args.has_key('comment'):
                    comment = req.args['comment']

                if not mgr.stop_work(stoptime, comment):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You have stopped working.')

                req.redirect(req.args['source_url'])
                return None

        # no POST, so they're just wanting a list of the worklog entries
        data = {
            "messages": messages,
            "worklog": mgr.get_work_log('summary'),
            "worklog_href": req.href.worklog(),
            "ticket_href": req.href.ticket(),
            "usermanual_href": req.href.wiki(user_manual_wiki_title),
            "usermanual_title": user_manual_title
        }
        return 'worklog.html', data, None
Ejemplo n.º 3
0
    def process_request(self, req):
        messages = []

        def addMessage(s):
            messages.extend([s]);

        # General protection (not strictly needed if Trac behaves itself)
        if not re.search('/worklog', req.path_info):
            return None
        
        # Specific pages:
        match = re.search('/worklog/users/(.*)', req.path_info)
        if match:
          mgr = WorkLogManager(self.env, self.config, match.group(1))
          if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log('user'))
            return None
          
          req.hdf["worklog"] = {"worklog": mgr.get_work_log('user'),
                                "ticket_href": req.href.ticket(),
                                "usermanual_href":req.href.wiki(user_manual_wiki_title),
                                "usermanual_title":user_manual_title
                               }
          add_stylesheet(req, "worklog/worklogplugin.css")
          return 'worklog_user.cs', None

        mgr = WorkLogManager(self.env, self.config, req.authname)
        if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log())
            return None
        
        # Not any specific page, so process POST actions here.
        if req.method == 'POST':
            if req.args.has_key('startwork') and req.args.has_key('ticket'):
                if not mgr.start_work(req.args['ticket']):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You are now working on ticket #%s.' % (req.args['ticket'],))
                
                req.redirect(req.args['source_url'])
                return None
                
            elif req.args.has_key('stopwork'):
                stoptime = None
                if req.args.has_key('stoptime'):
                    stoptime = int(req.args['stoptime'])

                comment = ''
                if req.args.has_key('comment'):
                    comment = str(req.args['comment'])

                if not mgr.stop_work(stoptime, comment):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You have stopped working.')
                
                req.redirect(req.args['source_url'])
                return None
        
        # no POST, so they're just wanting a list of the worklog entries
        req.hdf["worklog"] = {"messages": messages,
                              "worklog": mgr.get_work_log('summary'),
                              "href": req.href.worklog(),
                              "ticket_href": req.href.ticket(),
                              "usermanual_href": req.href.wiki(user_manual_wiki_title),
                              "usermanual_title": user_manual_title
                             }
        add_stylesheet(req, "worklog/worklogplugin.css")
        return 'worklog.cs', None