Commits

Anonymous committed 8d75ad4

added 2 methods into HandlerDocumentation: get_doc returns the __doc__ of the current handler, and get_resource_uri_template converts resource_uri to a URI template (http://bitworking.org/projects/URI-Templates/)

Comments (0)

Files changed (2)

 import inspect, handler
 
+from django.core.urlresolvers import get_resolver, get_callable, get_script_prefix
+
 def generate_doc(handler_cls):
     """
     Returns a `HandlerDocumentation` object
 
     def get_model(self):
         return getattr(self, 'model', None)
+            
+    def get_doc(self):
+        return self.handler.__doc__
     
+    doc = property(get_doc)
+
     @property
     def name(self):
         return self.handler.__name__
     
+    def get_resource_uri_template(self):
+        """URI template processor"""
+        
+        def _convert(template, params=[]):
+            """URI template converter"""
+            paths = template % dict([p, "{%s}" % p] for p in params)
+            return u'%s%s' % (get_script_prefix(), paths)
+        
+        try:
+            resource_uri = self.handler.resource_uri()
+            
+            components = [None, [], {}]
+            for i, value in enumerate(resource_uri):
+                components[i] = value
+        
+            lookup_view, args, kwargs = components
+        
+            lookup_view = get_callable(lookup_view, True)
+
+            possibilities = get_resolver(None).reverse_dict.getlist(lookup_view)
+            
+            for possibility, pattern in possibilities:
+                for result, params in possibility:
+                    if args:
+                        if len(args) != len(params):
+                            continue
+                        return _convert(result, params)
+                    else:
+                        if set(kwargs.keys()) != set(params):
+                            continue
+                        return _convert(result, params)
+        except:
+            pass
+        
+        return None
+        
+    resource_uri_template = property(get_resource_uri_template)
+    
     def __repr__(self):
         return u'<Documentation for "%s">' % self.name

tests/test_project/apps/testapp/models.py

 class ExpressiveTestModel(models.Model):
     title = models.CharField(max_length=255)
     content = models.TextField()
+    never_shown = models.TextField()
     
 class Comment(models.Model):
     parent = models.ForeignKey(ExpressiveTestModel, related_name='comments')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.