Ejemplo n.º 1
0
class WorkLogTicketObserver(Component):

    implements(ITicketChangeListener)

    def __init__(self):
        self.mgr = WorkLogManager(self.env)

    def ticket_created(self, ticket):
        """Called when a ticket is created."""
        pass

    def ticket_changed(self, ticket, comment, author, old_values):
        """Called when a ticket is modified.
        
        `old_values` is a dictionary containing the previous values of the
        fields that have changed.
        """
        syllabus_id = ticket.syllabus_id
        if self.mgr.autostop.syllabus(syllabus_id) \
               and 'closed' == ticket['status'] \
               and 'closed' != old_values.get('status'):
            who, since = self.mgr.who_is_working_on(ticket.id)
            if who:
                self.mgr.stop_work(who, ticket.pid)

    def ticket_deleted(self, ticket):
        """Called when a ticket is deleted."""
        pass
Ejemplo n.º 2
0
 def ticket_changed(self, ticket, comment, author, old_values):
     """Called when a ticket is modified.
     
     `old_values` is a dictionary containing the previous values of the
     fields that have changed.
     """
     if self.config.getbool('worklog', 'autostop') \
            and 'closed' == ticket['status'] \
            and old_values.has_key('status') \
            and 'closed' != old_values['status']:
         mgr = WorkLogManager(self.env, self.config)
         who, since = mgr.who_is_working_on(ticket.id)
         if who:
             mgr = WorkLogManager(self.env, self.config, who)
             mgr.stop_work()
Ejemplo n.º 3
0
 def ticket_changed(self, ticket, comment, author, old_values):
     """Called when a ticket is modified.
     
     `old_values` is a dictionary containing the previous values of the
     fields that have changed.
     """
     if self.config.getbool('worklog', 'autostop') \
            and 'closed' == ticket['status'] \
            and old_values.has_key('status') \
            and 'closed' != old_values['status']:
         mgr = WorkLogManager(self.env, self.config)
         who,since = mgr.who_is_working_on(ticket.id)
         if who:
             mgr = WorkLogManager(self.env, self.config, who)
             mgr.stop_work()
Ejemplo n.º 4
0
class WorlLogRPC(Component):
    """ Interface to the [http://trac-hacks.org/wiki/WorkLogPlugin Work Log Plugin] """
    implements(IXMLRPCHandler)

    def __init__(self):
        self.mgr = WorkLogManager(self.env)

    def xmlrpc_namespace(self):
        return 'worklog'

    def xmlrpc_methods(self):
        yield ('WIKI_VIEW', ((int,),), self.getRPCVersionSupported)
        yield ('WIKI_VIEW', ((str, int),), self.startWork)
        yield ('WIKI_VIEW', ((str, int), (str, int, str), (str, int, str, int),), self.stopWork)
        yield ('WIKI_VIEW', ((dict, int), (dict, int, str),), self.getLatestTask)
        yield ('WIKI_VIEW', ((dict, int), (dict, int, str),), self.getActiveTask)
        yield ('WIKI_VIEW', ((str, int,),), self.whoIsWorkingOn)
        yield ('WIKI_VIEW', ((str, int,),), self.whoLastWorkedOn)

    def getRPCVersionSupported(self, req):
        """ Returns 1 with this version of the Work Log XMLRPC API. """
        return 1

    def startWork(self, req, ticket):
        """ Start work on a ticket. Returns the string 'OK' on success or an explanation on error (requires authentication)"""
        res, err = self.mgr.start_work(req.authname, ticket)
        if res:
            return 'OK'
        else:
            return err
            
    def stopWork(self, req, pid, comment=None, stoptime=None):
        """ Stops work. Returns the string 'OK' on success or an explanation on error (requires authentication, stoptime is seconds since epoch) """
        res, err = self.mgr.stop_work(req.authname, pid, stoptime, comment)
        if res:
            return 'OK'
        else:
            return err

    def getLatestTask(self, req, pid, username=None):
        """ Returns a structure representing the info about the latest task. """
        if not username:
            username = req.authname
        return self.mgr.get_latest_task(username, pid)
        
    def getActiveTask(self, req, pid, username=None):
        """ Returns a structure representing the info about the active task (identical to getLatestTask but does not return anything if the work has stopped). """
        if not username:
            username = req.authname
        return self.mgr.get_active_task(username, pid)
        
    def whoIsWorkingOn(self, req, ticket):
        """ Returns the username of the person currently working on the given ticket """
        who, since = self.mgr.who_is_working_on(ticket)
        return who
            
    def whoLastWorkedOn(self, req, ticket):
        """ Returns the username of the person last worked on the given ticket """
        return self.mgr.who_last_worked_on(ticket)
Ejemplo n.º 5
0
 def ticket_changed(self, ticket, comment, author, old_values):
     """Called when a ticket is modified.
     
     `old_values` is a dictionary containing the previous values of the
     fields that have changed.
     """
     if (
         self.config.getbool("worklog", "autostop")
         and "closed" == ticket["status"]
         and old_values.has_key("status")
         and "closed" != old_values["status"]
     ):
         mgr = WorkLogManager(self.env, self.config)
         who, since = mgr.who_is_working_on(ticket.id)
         if who:
             mgr = WorkLogManager(self.env, self.config, who)
             mgr.stop_work()
Ejemplo n.º 6
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.º 7
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.º 8
0
 def stopWork(self, req, comment='', stoptime=None):
     """ Stops work. Returns the string 'OK' on success or an explanation on error (requires authentication, stoptime is seconds since epoch) """
     mgr = WorkLogManager(self.env, self.config, req.authname)
     if mgr.stop_work(stoptime, comment):
         return 'OK'
     return mgr.get_explanation()
Ejemplo n.º 9
0
 def stopWork(self, req, comment='', stoptime=None):
     """ Stops work. Returns the string 'OK' on success or an explanation on error (requires authentication, stoptime is seconds since epoch) """
     mgr = WorkLogManager(self.env, self.config, req.authname)
     if mgr.stop_work(stoptime, comment):
         return 'OK'
     return mgr.get_explanation()
Ejemplo n.º 10
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