Commits

Odd Simon Simonsen committed 1f69756

CustomFieldAdminPlugin: Minor code cleaning based on 'lint' advice.

Comments (0)

Files changed (5)

0.11/customfieldadmin/__init__.py

 
-__version__ = __import__('pkg_resources').get_distribution('TracCustomFieldAdmin').version
+__version__ = __import__('pkg_resources').get_distribution(
+                                        'TracCustomFieldAdmin').version

0.11/customfieldadmin/admin.py

 (c) 2007-2009 ::: www.Optaros.com (.....)
 """
 
+from pkg_resources import resource_filename
+
 from trac.config import Option
 from trac.core import *
-from trac.web.chrome import ITemplateProvider, add_stylesheet, add_script, \
-                            add_warning
+from trac.web.chrome import ITemplateProvider, add_script, add_warning
 from trac.admin.api import IAdminPanelProvider
 
 from customfieldadmin.api import CustomFields, _
                     order = dict([(key[6:], req.args.get(key)) for key
                                   in req.args.keys()
                                   if key.startswith('order_')])
-                    values = dict([(val, True) for val in order.values()])
                     cfields = cf_api.get_custom_fields()
                     for current_cfield in cfields:
                         current_cfield['order'] = order[current_cfield['name']]
 
     # ITemplateProvider methods
     def get_templates_dirs(self):
-        from pkg_resources import resource_filename
         return [resource_filename(__name__, 'templates')]
 
     def get_htdocs_dirs(self):
-        from pkg_resources import resource_filename
         return [('customfieldadmin', resource_filename(__name__, 'htdocs'))]

0.11/customfieldadmin/api.py

         if not cfield:    # return full list
             return TicketSystem(self.env).get_custom_fields()
         else:                  # only return specific item with cfname
-            all = TicketSystem(self.env).get_custom_fields()
-            for item in all:
+            for item in TicketSystem(self.env).get_custom_fields():
                 if item['name'] == cfield['name']:
                     return item
             return None        # item not found
         cfield['name'] = cfield['name'].lower()
         # Only alphanumeric characters (and [-_]) allowed for custom fieldname
         if re.search('^[a-z][a-z0-9_]+$', cfield['name']) == None:
-           raise TracError(_("Only alphanumeric characters allowed for " \
+            raise TracError(_("Only alphanumeric characters allowed for " \
                              "custom field name ('a-z' or '0-9' or '_'), " \
                              "with 'a-z' as first character."))
         # Name must begin with a character - anything else not supported by Trac
             self._save(cfield)
 
     def _save(self, cfield=None):
-        # Saves a value, clear caches if needed / supported
+        """ Saves a value, clear caches if needed / supported. """
         self.config.save()
         try:
             # cache support for Trac >= 0.12

0.11/customfieldadmin/tests/admin.py

 
 from trac.perm import PermissionSystem, PermissionCache
 from trac.test import EnvironmentStub, Mock
-from trac.ticket.api import TicketSystem
 from trac.web.api import RequestDone
 from trac.web.href import Href
 
     def test_apply_optional_select(self):
         # Reuse the added custom field that test verified to work
         self.test_add_optional_select()
-        self.assertEquals('select', self.env.config.get('ticket-custom', 'test'))
+        self.assertEquals('select',
+                            self.env.config.get('ticket-custom', 'test'))
         # Now check that details are maintained across order change
         # that reads fields, deletes them, and creates them again
         # http://trac-hacks.org/ticket/1834#comment:5

0.11/customfieldadmin/tests/api.py

                 self.cf_api.get_custom_fields(cfield={'name': 'two'}))
 
     def test_delete_unknown_options(self):
-        cf = customfield = {'name': 'foo', 'type': 'text', 'label': 'Foo'}
+        cf = {'name': 'foo', 'type': 'text', 'label': 'Foo'}
         self.cf_api.create_custom_field(cf)
         self.assertEquals('text',
                     self.env.config.get('ticket-custom', 'foo'))
                     self.env.config.get('ticket-custom', 'foo.answer'))
 
     def test_not_delete_unknown_options_for_modify(self):
-        cf = customfield = {'name': 'foo', 'type': 'text', 'label': 'Foo'}
+        cf = {'name': 'foo', 'type': 'text', 'label': 'Foo'}
         self.cf_api.create_custom_field(cf)
         self.assertEquals('text',
                     self.env.config.get('ticket-custom', 'foo'))