~justizin/meteor/cmfin

« back to all changes in this revision

Viewing changes to src/meteor/view.py

  • Committer: FGR Admin
  • Date: 2009-03-30 05:16:18 UTC
  • Revision ID: fgr@intrepid.sfo1.labs.vongogo.net-20090330051618-vbofdsxde4d50zu7
removing docgrok bits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
311
311
            raise KeyError(message)
312
312
 
313
313
 
314
 
class Server(GAIAView, ZODBControlView):
 
314
class Server(MeteorView, ZODBControlView):
315
315
    """Zope3 management screen."""
316
316
 
317
317
    grok.require('grok.ManageApplications')
383
383
            self.flash('ERROR packing ZODB `%s`: %s' % (dbName, err))
384
384
 
385
385
 
386
 
class Users(GAIAView):
 
386
class Users(MeteorView):
387
387
    """Users management screen."""
388
388
 
389
389
    grok.name('users')
390
 
    grok.require('grok.ManageApplications')
 
390
    grok.require('meteor.ManageSite')
391
391
 
392
392
    def getPrincipals(self):
393
393
        from grok.admin import AUTH_FOLDERNAME, USERFOLDER_NAME
429
429
        part_path += "/"
430
430
    return result
431
431
 
432
 
 
433
 
class DocGrokView(GAIAView):
434
 
    """A base DocGrok view.
435
 
 
436
 
    This view is used for all things not covered by other, more
437
 
    specialized views.
438
 
    """
439
 
 
440
 
    grok.context(DocGrok)
441
 
    grok.name('index')
442
 
    grok.require('grok.ManageApplications')
443
 
 
444
 
    def getDoc(self, text=None, heading_only=False):
445
 
        """Get the doc string of the module STX formatted."""
446
 
        if text is None:
447
 
            return None
448
 
            if (hasattr(self.context, "apidoc") and
449
 
                hasattr(self.context.apidoc, "getDocString")):
450
 
                text = self.context.apidoc.getDocString()
451
 
            else:
452
 
                return None
453
 
        lines = text.strip().split('\n')
454
 
        if len(lines) and heading_only:
455
 
            # Find first empty line to separate heading from trailing text.
456
 
            headlines = []
457
 
            for line in lines:
458
 
                if line.strip() == "":
459
 
                    break
460
 
                headlines.append(line)
461
 
            lines = headlines
462
 
        # Get rid of possible CVS id.
463
 
        lines = [line for line in lines if not line.startswith('$Id')]
464
 
        return renderText('\n'.join(lines), self.context.getPath())
465
 
 
466
 
    def getDocHeading(self, text=None):
467
 
        return self.getDoc(text, True)
468
 
 
469
 
    def getPathParts(self, path=None):
470
 
        """Get parts of a dotted name as url and name parts.
471
 
        """
472
 
        if path is None:
473
 
            path = self.context.path
474
 
        if path is None:
475
 
            return None
476
 
        return getDottedPathDict(path)
477
 
        result = []
478
 
        part_path = ""
479
 
        for part in path.split('.'):
480
 
            name = part
481
 
            if part_path != "":
482
 
                name = "." + part
483
 
            part_path += part
484
 
            result.append({
485
 
                'name':name,
486
 
                'url':"/docgrok/%s" % (part_path,)
487
 
                })
488
 
            part_path += "/"
489
 
        return result
490
 
 
491
 
    def getEntries(self, columns=True):
492
 
        """Return info objects for all modules and classes in the
493
 
        associated apidoc container.
494
 
 
495
 
        """
496
 
        if (not hasattr(self.context, "apidoc") or
497
 
            not hasattr(self.context.apidoc, "items")):
498
 
            return None
499
 
        entries = []
500
 
        for name, obj in self.context.apidoc.items():
501
 
            entry = {
502
 
                'name': name,
503
 
                'obj' : obj,
504
 
                'path': getPythonPath(removeAllProxies(obj)),
505
 
                'url' : u'',
506
 
                'doc' : None,
507
 
                'ispackage' : False,
508
 
                'ismodule' : False,
509
 
                'isinterface' : False,
510
 
                'isclass' : False,
511
 
                'isfunction' : False,
512
 
                'istextfile' : False,
513
 
                'iszcmlfile' : False,
514
 
                'signature' : None
515
 
                }
516
 
            entry['url'] = "%s/%s" % (self.context.path.replace('.','/'), name)
517
 
            if hasattr(obj,"getDocString"):
518
 
                entry['doc'] = self.getDocHeading(obj.getDocString())
519
 
            elif hasattr(obj, "getDoc") and isinstance(
520
 
                removeAllProxies(obj), InterfaceClass):
521
 
                entry['doc'] = self.getDocHeading(obj.getDoc())
522
 
            if isinstance(obj, Class):
523
 
                entry['isclass'] = True
524
 
            elif isinstance(obj, TextFile):
525
 
                entry['istextfile'] = True
526
 
            elif isinstance(obj, ZCMLFile):
527
 
                entry['iszcmlfile'] = True
528
 
            elif isinstance(obj,Function):
529
 
                entry['isfunction'] = True
530
 
                if hasattr(obj, 'getSignature'):
531
 
                    entry['signature'] = obj.getSignature()
532
 
            elif (isinstance(obj, Module) and
533
 
                  os.path.basename(obj.getFileName()) in
534
 
                    ['__init.py__', '__init__.pyc', '__init__.pyo']):
535
 
                entry['ispackage'] = True
536
 
            elif isinstance(obj, Module):
537
 
                entry['ismodule'] = True
538
 
            elif isinstance(obj, InterfaceClass):
539
 
                entry['isinterface'] = True
540
 
            entries.append(entry)
541
 
 
542
 
        entries.sort(lambda x, y: cmp(x['name'], y['name']))
543
 
        return entries
544
 
 
545
 
    def update(self):
546
 
        self.docgrok_root = self.context._traversal_root
547
 
        self.app_root = self.docgrok_root.__parent__
548
 
        pass
549
 
 
550
 
 
551
 
class DocGrokPackageView(DocGrokView):
552
 
    """A view for packages handled by DocGrok."""
553
 
 
554
 
    grok.context(DocGrokPackage)
555
 
    grok.name('index')
556
 
 
557
 
 
558
 
class DocGrokModuleView(DocGrokView):
559
 
    """A view for modules handled by DocGrok."""
560
 
 
561
 
    grok.context(DocGrokModule)
562
 
    grok.name('index')
563
 
 
564
 
 
565
 
class DocGrokClassView(DocGrokView):
566
 
    """A view for classes handled by DocGrok."""
567
 
 
568
 
    grok.context(DocGrokClass)
569
 
    grok.name('index')
570
 
 
571
 
    def getBases(self):
572
 
        return self._listClasses(self.context.apidoc.getBases())
573
 
 
574
 
    def getInterfaces(self):
575
 
        return self._listClasses(
576
 
          [iface for iface in self.context.apidoc.getInterfaces()])
577
 
 
578
 
    def getAttributes(self):
579
 
        attrs = self.context.getAttributes()
580
 
        for a in attrs:
581
 
            a['interface'] = self._listClasses([a['interface']])
582
 
        return attrs
583
 
 
584
 
    def getMethods(self):
585
 
        methods = self.context.getMethods()
586
 
        for m in methods:
587
 
            m['doc'] = renderText(m['attr'].__doc__ or '',
588
 
                                  inspect.getmodule(m['attr']))
589
 
            m['interface'] = self._listClasses([m['interface']])
590
 
        return methods
591
 
 
592
 
    def _listClasses(self, classes):
593
 
        info = []
594
 
        for cls in classes:
595
 
            unwrapped_cls = removeAllProxies(cls)
596
 
            fullpath = getPythonPath(unwrapped_cls)
597
 
            if not fullpath:
598
 
                continue
599
 
            path, name = fullpath.rsplit('.', 1)
600
 
            info.append({
601
 
                'path': path or None,
602
 
                'path_parts' : self.getPathParts(path) or None,
603
 
                'name': name,
604
 
                'url': fullpath and fullpath.replace('.','/') or None,
605
 
                'doc': self.getDocHeading(cls.__doc__) or None
606
 
                })
607
 
        return info
608
 
 
609
 
 
610
 
class DocGrokInterfaceView(DocGrokClassView):
611
 
 
612
 
    grok.context(DocGrokInterface)
613
 
    grok.name('index')
614
 
 
615
 
 
616
 
class DocGrokGrokApplicationView(DocGrokClassView):
617
 
 
618
 
    grok.context(DocGrokGrokApplication)
619
 
    grok.name('index')
620
 
 
621
 
 
622
 
class DocGrokTextFileView(DocGrokView):
623
 
 
624
 
    grok.context(DocGrokTextFile)
625
 
    grok.name('index')
626
 
 
627
 
    def getContent(self):
628
 
        lines = self.context.getContent()
629
 
        if self.context.path.endswith('.stx'):
630
 
            format = 'zope.source.stx'
631
 
        else:
632
 
            format = 'zope.source.rest'
633
 
        return renderText(lines, format=format)
634
 
 
635
 
    def getPackagePathParts(self):
636
 
        return self.getPathParts(
637
 
            self.context.getPackagePath())