Changeset 169 for trunk


Ignore:
Timestamp:
07/06/07 09:56:11 (17 years ago)
Author:
bas
Message:

email2trac.py.in:

  • Implemented full ticket field updates via email subject line, see ticket #7
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r167 r169  
    390390                        try:
    391391                                index, value = string.split(field,'=')
     392
     393                                # We can not change the description of a ticket via the subject
     394                                # line. The description is the body of the email
     395                                #
     396                                if index.lower() in ['description']:
     397                                        continue
     398
    392399                                if value:
    393400                                        result[index.lower()] = value
     401
    394402                        except ValueError:
    395403                                pass
     
    397405                return result
    398406
    399         def update_ticket_fields(self, system_fields, user_fields):
    400                 for field in system_fields:
    401                         print field['name']
     407        def update_ticket_fields(self, ticket, user_dict):
     408                """
     409                This will update the ticket fields when supplied via
     410                the subject mail line. It will only update the ticket
     411                field:
     412                        - If the field is known
     413                        - If the value supplied is valid for the ticket field
     414                        - Else we skip it and no error is given
     415                """
     416
     417                # Build a system dictionary from the ticket fields
     418                # with field as index and option as value
     419                #
     420                sys_dict = dict()
     421                for field in ticket.fields:
    402422                        try:
    403                                 print field['options']
     423                                sys_dict[field['name']] = field['options']
     424
    404425                        except KeyError:
    405                                 print field
     426                                sys_dict[field['name']] = None
    406427                                pass
     428
     429                # Check user supplied fields an compare them with the
     430                # system one's
     431                #
     432                for field,value in user_dict.items():
     433                        if self.DEBUG >= 5:
     434                                print  'user field : %s=%s' %(field,value)
     435
     436                        if sys_dict.has_key(field):
     437                                if self.DEBUG >= 5:
     438                                        print  'sys field  : ', sys_dict[field]
     439
     440                                # Check if value is an allowed system option, if TypeError then
     441                                # every value is allowed
     442                                #
     443                                try:
     444                                        if value in sys_dict[field]:
     445                                                ticket[field] = value
     446
     447                                except TypeError:
     448                                        ticket[field] = value
     449                                       
     450                               
    407451                               
    408452        def ticket_update(self, m):
     
    459503                                return False
    460504
    461                         # Must we update some ticket fields
    462                         #
    463                         self.update_ticket_fields(tkt.fields, update_tkt_fields)
    464                         sys.exit(1)
    465 
    466                         for key,value in tkt_fields.items():
    467                                 tkt[key] = value
     505                        # Must we update some ticket fields properties
     506                        #
     507                        self.update_ticket_fields(tkt, update_tkt_fields)
    468508
    469509                        tkt.save_changes(self.author, body_text, when)
Note: See TracChangeset for help on using the changeset viewer.