Commits

hideki nara committed 96dc6ae

split schema description table for each django models tables

Comments (0)

Files changed (2)

src/schema2rst/management/commands/schemadoc.py

             default='',
             help=u'Django Databases index name'),
 
+
         make_option('--with_title',
             action='store',
             dest='with_title',
             default=True,
             help=u'True(default) if using title'),
 
+        make_option('--out',
+            action='store',
+            dest='directory',
+            default='./',
+            help=u'out directory'),
+
         make_option('--encoding',
             action='store',
             dest='encoding',
         config['with_title'] = str(options['with_title']) == 'True'
         schema2rst.main(config,pattern)
 
+    def handle_generate_each(self,*args,**options):
+        ''' for each tables
+        '''
+        config = settings.DATABASES[ options['db'] ]
+        config = dict( [(k.lower(),v ) for k,v in config.items()] )
+        config['db'] = config['name']
+        config['passwd'] = config['password']
+        config['title'] = options['title'].decode('utf8')  if len(options['title'] )>0 \
+            else  u"Database Scheme:%s" % options['db']
+
+        pattern = [ r'^%s'%p for p in options['apps'].split(',') if len(p)>0 ]
+        config['with_title'] = str(options['with_title']) == 'True'
+
+        from django.db import models
+        for m in models.get_models():
+            config['outfile'] = os.path.join(os.path.abspath(options['directory']),m._meta.db_table +".rst") 
+            schema2rst.main(config,[ r'^%s' % m._meta.db_table ] )
+
     def handle_help(self  ,*args, **options):
         ''' help '''
         print "do something later" 

src/schema2rst/schema2rst.py

 
     insp = inspectors.create_inspector(engine)
 
-    sphinx = SphinxDocGenerator()
+    f =  open(config['outfile'],'w')  if config.has_key('outfile') else None
+    sphinx = SphinxDocGenerator(f)
 
     if config.get('with_title',True):
         title = config['title'] if config.has_key('title') \
             #:table name filters
             if sum([re.search(p,table['name']) != None for p in patterns ])==0:
                 continue
-        
 
         if config.get('with_title',True):
             # FIXME: support fullname (table comment)