Cleaned up the controller plugin and started removing some cruft.
Cleaned up the controller plugin and started removing some cruft.

Make sure the new plugin implemented IConfigurable in case it was used in
isolation (we need to make sure the template folder was in config)

file:a/README.rst -> file:b/README.rst
--- a/README.rst
+++ b/README.rst
@@ -12,6 +12,9 @@
 * A custom Pylons controller for overriding some core CKAN behaviour
 
 * A custom Package edit form
+
+* A plugin that allows for custom forms to be used for datasets based on 
+  their "type".
 
 * A custom User registration and edition form
 

--- a/ckanext/example/controller_plugin.py
+++ b/ckanext/example/controller_plugin.py
@@ -1,23 +1,24 @@
-import logging
-from ckan.lib.base import BaseController, render, c, model, abort, request
-from ckan.lib.base import redirect, _, config, h
+import os, logging
+from ckan.authz import Authorizer
 import ckan.logic.action.create as create
 import ckan.logic.action.update as update
 import ckan.logic.action.get as get
 from ckan.logic.converters import date_to_db, date_to_form, convert_to_extras, convert_from_extras
-from ckan.lib.navl.dictization_functions import DataError, flatten_dict, unflatten
 from ckan.logic import NotFound, NotAuthorized, ValidationError
 from ckan.logic import tuplize_dict, clean_dict, parse_params
+import ckan.logic.schema as default_schema
 from ckan.logic.schema import package_form_schema
-from ckan.plugins import IDatasetForm
-from ckan.plugins import implements, SingletonPlugin
+import ckan.logic.validators as val
+from ckan.lib.base import BaseController, render, c, model, abort, request
+from ckan.lib.base import redirect, _, config, h
 from ckan.lib.package_saver import PackageSaver
 from ckan.lib.field_types import DateType, DateConvertError
-from ckan.authz import Authorizer
 from ckan.lib.navl.dictization_functions import Invalid
 from ckan.lib.navl.dictization_functions import validate, missing
-import ckan.logic.validators as val
-import ckan.logic.schema as default_schema
+from ckan.lib.navl.dictization_functions import DataError, flatten_dict, unflatten
+from ckan.plugins import IDatasetForm, IConfigurer
+from ckan.plugins import implements, SingletonPlugin
+
 from ckan.lib.navl.validators import (ignore_missing,
                                       not_empty,
                                       empty,
@@ -30,11 +31,33 @@
 
 
 class ExampleDatasetForm(SingletonPlugin):
+    """This plugin demonstrates how a theme packaged as a CKAN
+    extension might extend CKAN behaviour.
+
+    In this case, we implement three extension interfaces:
+
+      - ``IConfigurer`` allows us to override configuration normally
+        found in the ``ini``-file.  Here we use it to specify where the
+        form templates can be found.
+      - ``IDatasetForm`` allows us to provide a custom form for a dataset
+        based on the type_name that may be set for a package.  Where the 
+        type_name matches one of the values in package_types then this 
+        class will be used. 
     """
-
-    """
-
     implements(IDatasetForm, inherit=True)
+    implements(IConfigurer, inherit=True)    
+    
+    def update_config(self, config):
+        """
+        This IConfigurer implementation causes CKAN to look in the
+        ```templates``` directory when looking for the package_form()
+        """
+        here = os.path.dirname(__file__)
+        rootdir = os.path.dirname(os.path.dirname(here))
+        template_dir = os.path.join(rootdir, 'ckanext',
+                                    'example', 'theme', 'templates')
+        config['extra_template_paths'] = ','.join([template_dir,
+                config.get('extra_template_paths', '')])
 
     def package_form(self):
         """
@@ -68,10 +91,11 @@
 
     def setup_template_variables(self, context, data_dict=None):
         """
-        Add variables to c just prior to the template being rendered.
+        Adds variables to c just prior to the template being rendered that can
+        then be used within the form
         """        
         c.licences = [('', '')] + model.Package.get_license_options()
-        c.publishers = self.get_publishers()
+        c.publishers = [('Example publisher', 'Example publisher 2')]
         c.is_sysadmin = Authorizer().is_sysadmin(c.user)
         c.resource_columns = model.Resource.get_columns()
 
@@ -149,14 +173,8 @@
 
     def check_data_dict(self, data_dict):
         """
-        Check if the return data is correct.
-
-        raise a DataError if not.
+        Check if the return data is correct and raises a DataError if not.
         """
         return
 
-    def get_publishers(self):
-        """
-        """
-        return [('pub1', 'pub2')]