Пример #1
0
    def timeline(self, environ, projectname, wurl):
        """Aggregate activities under project wiki or individual wiki
        URLS :
            /p/{projectname}/wiki/timeline/*(wurl)
        """
        from zeta.config.environment import projcomp, wikicomp

        c.rclose = h.ZResp()

        logid = request.params.get('logid', None)
        dir = request.params.get('dir', None)
        fromoff = request.params.get('fromoff', 1)
        logid = logid and int(logid)
        fromoff = int(fromoff)

        # Setup context for page generation
        c.projsummary = c.project.summary
        wikiurl = self.url_wikiurl(projectname, wurl)
        c.wiki = wikicomp.get_wiki(unicode(wikiurl))
        c.wikipagenames = self.wikipagename(wikicomp.wikiurls(c.project))
        c.wikipagename = wurl
        routeargs = {'projectname': projectname, 'wurl': wurl}
        self.tline_controller(h.r_projwikitline, routeargs, 'wiki', fromoff,
                              logid, dir, c.wiki)
        c.title = '%s:timeline' % wurl
        c.datatline, c.startdt = h.tlineplot(c.logs[:])
        c.rclose.append(render('/derived/projects/wikitline.html'))
        return c.rclose
Пример #2
0
    def do_chart14(self, projects):
        """Compute project activity based on functions,
        chart14_data,
        { projectname : { review:count, wiki:count, ticket:count,
                          vcs:count, admin:count },
          ...
        }"""
        from zeta.config.environment    import  \
                projcomp, tckcomp, vcscomp, revcomp, wikicomp

        chart14_data = dict([(p.projectname, {
            'ticket': 0,
            'vcs': 0,
            'review': 0,
            'wiki': 0,
            'admin': 0
        }) for p in projcomp.get_project()])

        for t in tckcomp.get_ticket(attrload=['project']):
            d = chart14_data[t.project.projectname]
            d['ticket'] += len(t.logs)
        for v in vcscomp.get_vcs(attrload=['project']):
            d = chart14_data[v.project.projectname]
            d['vcs'] += len(v.logs)
        for r in revcomp.get_review(attrload=['project']):
            d = chart14_data[r.project.projectname]
            d['review'] += len(r.logs)
        for w in wikicomp.get_wiki(attrload=['project']):
            d = chart14_data[w.project.projectname]
            d['wiki'] += len(w.logs)
        for p in projcomp.get_project():
            d = chart14_data[p.projectname]
            d['admin'] += len(p.logs)
        return chart14_data
Пример #3
0
    def wiki_vote( self, projectname, wikiurl, vote, user ) :
        """Upvote or Downvote a wiki page"""
        from zeta.config.environment import wikicomp

        wiki     = wikicomp.get_wiki( wikiurl )
        if wiki :
            ( vote == 'up' and wikicomp.voteup( wiki, user ) ) \
            or \
            ( vote == 'down' and wikicomp.votedown( wiki, user ) )
            rc, failmsg = True, ''

        else :
            rc, failmsg = False, ('Invalid wiki page, %s'%wikiurl)
        return (rc, wiki, failmsg)
Пример #4
0
    def config_wiki( self, projectname, wikiurl, wtype=None, summary=None,
                     sourceurl=None, byuser=None ) :
        """Config wiki page for project `projectname`"""
        from zeta.config.environment import wikicomp

        wiki = wikicomp.get_wiki( wikiurl )
        if wiki :
            wikicomp.config_wiki(wiki, wtype=wtype, summary=summary,
                                 sourceurl=sourceurl, byuser=byuser)
            rc, wiki, failmsg = True, wiki, ''

        else :
            rc, wiki, failmsg = ( False, None, ('Invalid wiki page, %s'%wikiurl) )
        return ( rc, wiki, failmsg )
Пример #5
0
    def analyse(self):
        from zeta.config.environment import wikicomp

        wikis = wikicomp.get_wiki(
            attrload=['project', 'comments', 'votes', 'tags'])

        self.id2url = dict([(w.id, w.wikiurl) for w in wikis])
        self.url2id = dict([(w.wikiurl, w.id) for w in wikis])
        self.wdets = self.do_wdets(wikis)

        self.chart16_data, self.chart16_wiki = self.do_chart16(wikis)
        self.chart17_data = self.do_chart17(wikis)
        self.chart18_data, self.chart18_usrs = self.do_chart18(wikicomp, wikis)
        self.chart19_data, self.chart19_usrs = self.do_chart19(wikis)
        self.pagesnippets = self.do_pagesnippets(wikicomp, wikis)
Пример #6
0
    def wiki_tags( self, projectname, wikiurl, addtags=None, deltags=None,
                   byuser=None ) :
        """Add or delete tags from wiki page"""
        from zeta.config.environment import wikicomp

        wiki     = wikicomp.get_wiki( wikiurl )
        if wiki :
            if addtags != None :
                wikicomp.add_tags( wiki, tags=addtags, byuser=byuser )
            if deltags != None :
                wikicomp.remove_tags( wiki, tags=deltags, byuser=byuser )
            rc, failmsg = True, ''

        else :
            rc, failmsg = True, ('Invalid wiki page, %s'%wikiurl)
        return (rc, wiki, failmsg )
Пример #7
0
    def projecthome( self, environ, projectname ) :
        """Project main-page for `projectname`
        URLS :
            /p/<projectname>
            /p/<projectname>?translate=1
            /p/<projectname>?jsonobj=projectlogo&view=js
            /p/<projectname>?jsonobj=projecticon&view=js
            /p/<projectname>?form=submit&formname=projfav&view=js
        """
        from zeta.config.environment    import projcomp, wikicomp, vfcomp

        c.rclose = h.ZResp()

        # Form handling
        def errhandler(errmsg) :
            c.errmsg = errmsg
        vfcomp.process(
            request, c, defer=True, errhandler=h.hitchfn(errhandler),
            formnames=['projfav'], user=c.authuser
        )

        # Setup context for page generation
        c.projsummary = c.project.summary
        pt = {}
        [ pt.setdefault( t.teamtype.team_type, [] ).append( t.user.username )
          for t in c.project.team ]
        c.projectteams = pt
        c.att_editable = h.authorized( h.ProjectAdmin() )
        c.tag_editable = c.att_editable
        c.isfavorite = projcomp.checkfavorite( c.project.id, c.authuser.id )
        c.tags = self._prjtags( c.project )
        c.title = c.projectname

        fpurl = unicode( self.url_wikiurl( c.projectname, PROJHOMEPAGE ))
        w = wikicomp.get_wiki( fpurl, attrload=[ 'tablemap' ] )
        c.fpwcnt = wikicomp.get_content( w, translate=True ) if w else None
        c.fphtml = wikipage2html( c.fpwcnt, c.translate )

        # Html page generation
        if c.errmsg :
            html = self.returnerrmsg(environ)
        elif c.jsonobj and c.view == 'js' :
            html = self.handlejson(environ)
        elif c.view != 'js' :
            html = render( '/derived/projects/project.html' )
        c.rclose.append(html)
        return c.rclose
Пример #8
0
    def _optimized_fetch(self, controllername, projectname):
        """Fetch the project object and wiki object from the database in
        an optimized manner based on the action and json request"""
        from zeta.config.environment import projcomp, wikicomp

        # For Ajax request
        if c.jsonobj == 'wikicomments':
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo))

        elif c.jsonobj == 'wikircomments':
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo))

        elif c.jsonobj == 'wikilist':
            l = [
                'logofile', 'wikis', 'wikis.tablemap', 'wikis.votes',
                'wikis.type'
            ]
            c.project = projcomp.get_project(c.projectname, attrload=l)

        elif c.textobj == 'wikipreview':
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo))

        elif controllername == 'wiki' and c.wikiedit:
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo),
                                       attrload=['tablemap'])

        elif controllername == 'wiki' and c.wtalkpage:
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo),
                                       attrload=['tablemap'])

        elif controllername == 'wiki' and c.whistory:
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo),
                                       attrload=['tablemap'])

        elif controllername == 'wiki' and c.wikidiff:
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo),
                                       attrload=['tablemap'])

        elif controllername == 'wiki':
            l = ['creator', 'type', 'attachments', 'tags', 'tablemap', 'votes']
            c.wiki = wikicomp.get_wiki(unicode(c.pathinfo), attrload=l)

        l = ['logofile']
        c.project = c.project or projcomp.get_project(projectname, attrload=l)
Пример #9
0
    def wiki_fav( self, projectname, wikiurl, favorite, user ) :
        """Add or remove wiki page as favorite"""
        from zeta.config.environment import wikicomp

        wiki     = wikicomp.get_wiki( wikiurl )

        if wiki and favorite==True :
            wikicomp.addfavorites( wiki, [user], byuser=user )
            rc, failmsg = True, ''
            
        elif wiki and favorite==False :
            wikicomp.delfavorites( wiki, [user], byuser=user )
            rc, failmsg = True, ''

        else :
            rc, failmsg = False, ('Invalid wiki page, %s' % wikiurl)
        return (rc, wiki, failmsg )
Пример #10
0
    def comment_wiki( self, projectname, wikiurl, comment, commentor ) :
        """Comment on wiki page for project `projectname`"""
        from zeta.config.environment import wikicomp

        wiki     = wikicomp.get_wiki( wikiurl )

        if wiki and wiki.latest_version :
            wcmtdet = [ None, commentor, wiki.latest_version, comment ]
            wcmt    = wikicomp.create_wikicomment(
                            wiki, wcmtdet, byuser=commentor )
            rc, wcmt, failmsg = ( bool(wcmt), wcmt,
                                  ('Unable to create comment for wiki page %s' % \
                                              wikiurl)
                                )
        else :
            rc, wcmt, failmsg = ( False, None, ('Invalid wiki page, %s'%wikiurl) )
        return ( rc, wcmt, failmsg )
Пример #11
0
    def read_wiki( self, projectname, wikiurl ) :
        """Read a wiki page for project `projectname`"""
        from zeta.config.environment import wikicomp

        wiki     = wikicomp.get_wiki( wikiurl )

        if wiki :
            wcnt = wikicomp.get_content( wiki )
            text = wcnt and wcnt.text or ''
            d={ 'type'      : wiki.type.wiki_typename,
                'summary'   : wiki.summary,
                'sourceurl' : wiki.sourceurl,
                'text'      : text
              }
            rc, failmsg = True, ''
        else :
            rc, d, failmsg = ( False, {},
                               ('Unable to read wiki page, %s' % wikiurl) )
        return ( rc, d, failmsg )
Пример #12
0
    def indexwiki( self, wikis=[], clear=False, replace=False, flush=True ) :
        """Index all the wikis passed as argument, or index all the wikis in
        the database if 'wikis' is empty.
        If clear == True,
            then do the reverse, (i.e) clear the list of wikis from index
        If replace == True,
            then replace the list of wikis with new data"""
        from zeta.config.environment import wikicomp

        config = self.compmgr.config
        if config['zeta.xapiansearch'] :
            do_onetime( config )
            wikis = wikis or wikicomp.get_wiki()
            if clear :
                [ self.clear( 'id:wiki_%s' % w.id, flush=flush ) for w in wikis]
            else :
                [ self.index( wikicomp.documentof( w ), replace, flush=flush )
                  for w in wikis ]
        return
Пример #13
0
    def update_wiki( self, projectname, wikiurl, content, author ) :
        """Update a wiki page for project `projectname`"""
        from zeta.config.environment import wikicomp

        wiki     = wikicomp.get_wiki( wikiurl )
        try :
            if wiki :
                wpage = wikicomp.create_content( wiki, author, content )
                rc, wiki, failmsg = ( bool(wpage), wiki, 
                                      ('Unable to update wiki page, %s' % wikiurl)
                                    )
            else :
                rc, wiki, failmsg = ( False, None, 
                                      ('wiki page, %s does not exist' % wikiurl)
                                    )
        except :
            rc, wiki, failmsg = ( False, None,
                                  ("Type : %s, Value : %s" % sys.exc_info()[:2])
                                )
        return ( rc, wiki, failmsg )
Пример #14
0
    def feed(self, environ, projectname, wurl):
        """Aggregate activities under project wiki or individual wiki
        URLS :
            /p/{projectname}/wiki/feed/*(wurl)
        """
        from zeta.config.environment import projcomp, wikicomp

        # Setup context for page generation
        title = '%s-wiki:%s' % (projectname, wurl)
        link = h.urlroot(environ)
        descr = 'Timeline for wikipage, %s in project %s' % (wurl, projectname)
        c.projsummary = c.project.summary
        wikiurl = self.url_wikiurl(projectname, wurl)
        c.wiki = wikicomp.get_wiki(unicode(wikiurl))
        routeargs = {'projectname': projectname, 'wurl': wurl}
        feed = h.FeedGen(title, link, descr)
        self.tline_controller(h.r_projwikitline, routeargs, 'wiki', 1, None,
                              None, c.wiki)
        feedhtml = self.feeds(environ, link, feed, c.logs)
        response.content_type = 'application/atom+xml'
        return feedhtml
Пример #15
0
    def create_wiki( self, projectname, wikiurl, wtype=None, summary=u'',
                     sourceurl=u'', byuser=None ) :
        """Create a wiki page for the project `projectname`"""
        from zeta.config.environment import wikicomp, projcomp

        wtype = wtype and unicode(wtype) \
               or unicode(c.sysentries['def_wikitype'])
        wiki = wikicomp.get_wiki( wikiurl )
        rc, wiki, failmsg = ( bool(wiki), wiki, 
                              ('wiki page, %s already exists' % wikiurl) )
        try :
            if not wiki :
                wiki = wikicomp.create_wiki( wikiurl, wtype, summary,
                                             sourceurl, creator=byuser )
                wiki and wikicomp.config_wiki(
                                wiki, project=projectname, byuser=byuser )
                rc, wiki, failmsg = ( bool(wiki), wiki,
                                      ('Unable to create wiki page %s'%wikiurl) )
        except :
            rc, wiki, failmsg = ( False, None, 
                                  "Type : %s, Value : %s" % sys.exc_info()[:2] )
        return (rc, wiki, failmsg)
Пример #16
0
    def commit(self, config, byuser, tz='UTC', attachments=[]):
        """If the identified structure is Wiki, commit the data to DB"""
        from zeta.config.environment import attcomp, projcomp, wikicomp
        from zeta.lib.base import BaseController

        cntlr = BaseController()
        data = self.dataset
        attrs = [
            'wikiid', 'pagename', 'wikiurl', 'projectname', 'projectid',
            'type', 'summary', 'sourceurl', 'tags', 'favorite', 'vote', 'text',
            'comment'
        ]

        kwargs = dict([(k, data.get(k, None)) for k in attrs])
        pagename = kwargs.pop('pagename', None)
        wikiurl = kwargs.pop('wikiurl', None)

        p = kwargs.pop('projectname', None)
        p = p or kwargs.pop('projectid', None)
        p = projcomp.get_project(p)

        w = kwargs.pop('wikiid', None)
        w = w or wikiurl
        w = w and wikicomp.get_wiki(w)

        if pagename and p:
            wikiurl = cntlr.url_wikiurl(p.projectname, pagename)
            w = w or wikicomp.get_wiki(unicode(wikiurl))

        if w:
            # Favorite
            fav = kwargs.pop('favorite', None)
            fav == True and wikicomp.addfavorites(w, [byuser], byuser=byuser)
            fav == False and wikicomp.delfavorites(w, [byuser], byuser=byuser)

            # Vote
            vote = kwargs.pop('vote', '')
            vote == 'up' and wikicomp.voteup(w, byuser)
            vote == 'down' and wikicomp.votedown(w, byuser)

            # Tags
            tags = kwargs.pop('tags', [])
            tags and wikicomp.add_tags(w, tags=tags, byuser=byuser)

            # Comment
            comment = kwargs.pop('comment', None)
            comment and wikicomp.create_wikicomment(
                w, (None, byuser, w.latest_version, comment), byuser=byuser)

            # Type, summary, sourceurl
            wtype = kwargs.pop('type', None)
            wtype = wtype and wikicomp.get_wikitype(wtype)
            summary = kwargs.pop('summary', None)
            sourceurl = kwargs.pop('sourceurl', None)
            if wtype or summary or sourceurl:
                wikicomp.config_wiki(w,
                                     wtype=wtype,
                                     summary=summary,
                                     sourceurl=sourceurl,
                                     byuser=byuser)

            # Content
            text = kwargs.pop('text', None)
            text and wikicomp.create_content(w, byuser, text)

        elif wikiurl:
            wtype = kwargs.pop('type', None)
            wtype = wtype and wikicomp.get_wikitype(wtype)
            summary = kwargs.pop('summary', u'')
            sourceurl = kwargs.pop('sourceurl', u'')

            w = wikicomp.create_wiki(unicode(wikiurl),
                                     wtype=wtype,
                                     summary=summary,
                                     sourceurl=sourceurl,
                                     creator=byuser)

            if w:
                # Favorite
                fav = kwargs.pop('favorite', None)
                fav == True and wikicomp.addfavorites(w, [byuser],
                                                      byuser=byuser)
                fav == False and wikicomp.delfavorites(w, [byuser],
                                                       byuser=byuser)

                # Vote
                vote = kwargs.pop('vote', '')
                vote == 'up' and wikicomp.voteup(w, byuser)
                vote == 'down' and wikicomp.votedown(w, byuser)

                # Tags
                tags = kwargs.pop('tags', [])
                tags and wikicomp.add_tags(w, tags=tags, byuser=byuser)

                # Wiki content
                text = kwargs.pop('text', None)
                text and wikicomp.create_content(w, byuser, text)

        # Attachments
        if w:
            for fname, fcont in attachments:
                att = attcomp.create_attach(fname,
                                            FileC(fcont),
                                            uploader=byuser)
                wikicomp.add_attach(w, att, byuser=byuser)
Пример #17
0
    def phomepage( self, environ, do=None, file=None, project=None ) :
        r"""
        ==== Project home-page

        Update project homepage.

        > [<PRE paster request <.ini file> /pasteradmin/phomepage <do> <file> [project] >]

        where,
        :do ::
          can be, \\ 
          //push//, to push the <file> as project home-page for [project] \\ 
          //pull//, to pull <project> homepage from database and save it in <file> \\ 

        if [project] is not specified (for //push//), the operation will be
        done on all hosted projects.
        """
        from zeta.config.environment    import syscomp, projcomp, wikicomp

        if environ['paste.command_request'] :
            args = cmd_parse_request()
            do   = args.get( 'do', None )
            file = args.get( 'file', None )
            proj = args.get( 'project', None )

        file     = file and abspath( file )
        project  = projcomp.get_project( unicode(proj) )

        if project :
            projects = [ project ]
        else :
            projects = projcomp.get_project()

        if do == 'push' and file :
            for p in projects :
                print "Pushing homepage %s for project %s ... " % (
                      file, p.projectname )
                c.project = p
                w    = wikicomp.get_wiki(
                            unicode( self.url_wikiurl( p.projectname, 'homepage' ))
                       )
                if not w :
                    w = wikicomp.create_wiki(
                            unicode(self.url_wikiurl( p.projectname, 'homepage')),
                            type=c.sysentries.get( 'def_wikitype', None ),
                            creator=u'admin'
                        )
                    wikicomp.config_wiki( w, project=p )

                text = open( file ).read()
                wcnt = wikicomp.create_content( w.id, u'admin', unicode(text) )

        elif do == 'pull' and file and project :
            print "Pulling homepage for project %s to %s ... " % (
                  p.projectname, file )
            w    = wikicomp.get_wiki( 
                        unicode( self.url_wikiurl( p.projectname, 'homepage' ))
                   )
            wcnt = w and wikicomp.get_content( w.id )
            wcnt and open( file, 'w' ).write( wcnt.text )

        else :
            response.status_int = 400
            print "Invalid request ... \n"
Пример #18
0
 def sr_wikiurl(self, projectname, id):
     from zeta.config.environment import wikicomp
     wiki = wikicomp.get_wiki(id)
     return wiki.wikiurl
Пример #19
0
    def wiki(self, environ, projectname, wurl=None):
        """Project wiki pages.
        URLS :
            /p/{projectname}/wiki/*(wurl)
            /p/{projectname}/wiki/*(wurl)?ver=<num>
            /p/{projectname}/wiki/*(wurl)?wikiedit=1
            /p/{projectname}/wiki/*(wurl)?wikitalkpage=1
            /p/{projectname}/wiki/*(wurl)?wikihistory=1
            /p/{projectname}/wiki/*(wurl)?wikidiff=1
            /p/{projectname}/wiki/*(wurl)?translate=1
            /p/{projectname}/wiki/*(wurl)?downloadas=text
            /p/{projectname}/wiki/*(wurl)?downloadas=ps
            /p/{projectname}/wiki/*(wurl)?downloadas=pdf
            /p/{projectname}/wiki/*(wurl)?jsonobj=wikicomments&view=js
            /p/{projectname}/wiki/*(wurl)?jsonobj=wikircomments&view=js
            /p/{projectname}/wiki/*(wurl)?jsonobj=wikiattach&view=js
            /p/{projectname}/wiki/*(wurl)?jsonobj=wikitag&view=js
            /p/{projectname}/wiki/*(wurl)?textobj=wikipreview&view=text
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=addwikiattachs&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=delwikiattachs&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=addwikitags&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=delwikitags&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=wikicont&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=createwcmt&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=updatewcmt&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=replywcmt&view=js
            /p/{projectname}/wiki/*(wurl)?wikidiff=1&form=submit&formname=wikidiff
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=wikifav&view=js
            /p/{projectname}/wiki/*(wurl)?form=submit&formname=votewiki&view=js
        """
        from zeta.config.environment import projcomp, wikicomp, votcomp, vfcomp

        version = request.params.get('ver', None)
        wurl = wurl.rstrip('/')
        c.rclose = h.ZResp()

        # Handle forms
        def errhandler(errmsg):
            c.errmsg = errmsg

        if self.formpermission():
            c.errmsg = 'Do not have %s permission !!' % tckperm[c.formname]
        else:
            vfcomp.process(request,
                           c,
                           defer=True,
                           errhandler=h.hitchfn(errhandler),
                           formnames=[
                               'addwikiattachs', 'delwikiattachs',
                               'addwikitags', 'delwikitags', 'wikicont',
                               'createwcmt', 'updatewcmt', 'replywcmt',
                               'wikidiff', 'wikifav', 'votewiki'
                           ],
                           user=c.authuser)

        # Setup context for page generation
        c.projsummary = c.project.summary
        if not c.jsonobj:
            c.wikipagenames = self.wikipagename(wikicomp.wikiurls(c.project))
            c.wikipagename = wurl
            c.wikieditable = h.authorized(h.HasPermname('WIKI_CREATE'))
            c.wiki = c.wiki or wikicomp.get_wiki(unicode(c.pathinfo))

        # If there is no wiki page by that name then create the wiki and
        # show the edit page.
        if not c.wiki and c.wikieditable:
            c.wiki = wikicomp.create_wiki(unicode(c.pathinfo),
                                          wtype=c.sysentries.get(
                                              'def_wikitype', None),
                                          creator=c.authusername)
            c.project and wikicomp.config_wiki(c.wiki, project=c.project)
            c.wikiedit = '1'

        elif not c.wiki:
            raise NotAuthorizedError(
                'Do not have permission to create wiki page, WIKI_CREATE')

        # If the wiki page is empty (ie) no wiki content ever created, then
        # show the edit page.
        if not c.wiki.latest_version and c.wikieditable:
            h.flash(MESSAGE_FLASH + 'Empty page, write some text ...')
            c.wikiedit = '1'

        elif not c.wiki.latest_version:
            raise NotAuthorizedError(
                'Do not have permission to create wiki page, WIKI_CREATE')

        if c.wiki:
            c.isuserfavorite = wikicomp.isfavorite(c.authuser.id, c.wiki.id)

        c.title = wurl

        # HTML page generation
        html = ''
        typename = c.wiki.type.wiki_typename
        if c.errmsg:
            html = self.returnerrmsg(environ)

        if c.view == 'js' and c.formname in ['addwikiattachs']:
            html = IFRAME_RET

        elif c.view == 'js' and c.jsonobj:
            html = self.handlejson(environ)

        elif c.view == 'text' and c.textobj:
            html = self.handletext(environ)

        elif typename == h.WIKITYPE_REDIRECT and c.wiki.sourceurl:  # Page redirect
            h.redirect_url(c.wiki.sourceurl)

        elif c.wikiedit:
            c.wcnt = wikicomp.get_content(c.wiki)
            c.wikitypenames = wikicomp.typenames
            c.title += ':edit'
            html = render('/derived/projects/wiki.html')

        elif c.wtalkpage:
            c.items_wikicomments = self._json_wikicomments()
            c.title += ':talkpage'
            html = render('/derived/projects/wiki.html')

        elif c.whistory:
            c.wikicontents = wikicomp.get_content(c.wiki, all=True)
            c.title += ':history'
            html = render('/derived/projects/wiki.html')

        elif c.wikidiff:
            v = c.oldver or 1
            c.wcnt_oldver = wikicomp.get_content(c.wiki, version=v)
            c.wcnt_newver = wikicomp.get_content(c.wiki, version=c.newver)
            c.oldver = c.wcnt_oldver.id
            c.newver = c.wcnt_newver.id
            c.title += ':diff'
            html = render('/derived/projects/wiki.html')

        elif c.downloadas:
            c.wcnt = wikicomp.get_content(c.wiki)
            wikihtml = c.wcnt.translate(
                wiki=c.wiki,
                cache=True) if not c.wcnt.texthtml else c.wcnt.texthtml
            fmtobj = h.Html2Doc(wikihtml, format=c.downloadas)
            c.title = '-Skip-'
            html = fmtobj.convert()

            response.headers['Content-disposition'] = \
                str( 'attachment; filename="%s.%s"' % (c.wiki.wikiurl, c.downloadas) )

        elif c.view != 'js':
            # Refetch the wiki entry from DB with prepared query
            c.attachs = self._wikiattachs(c.wiki)
            c.tags = self._wikitags(c.wiki)
            c.att_editable = c.tag_editable = c.wikieditable
            c.wcnts = wikicomp.get_content(c.wiki, all=True)
            c.wikiauthors = h.computecount(c.wcnts, lambda x: x.author)
            c.wcnt = (version and c.wcnts[int(version) - 1]
                      or c.wcnts[-1]) if c.wcnts else None
            c.wikitypenames = wikicomp.typenames

            c.wikihtml = ''
            if c.wcnt:
                if not c.wcnt.texthtml:
                    c.wikihtml = c.wcnt.translate(wiki=c.wiki, cache=True)
                elif c.translate:
                    c.wikihtml = c.wcnt.translate(wiki=c.wiki, cache=True)
                else:
                    c.wikihtml = c.wcnt.texthtml

            lastver = c.wiki.latest_version
            fn = lambda v: [
                self.url_wikiurl(projectname, wurl, ver=str(v)),
                str(v)
            ]
            c.wversions = map(fn, range(1, lastver + 1))
            c.wdownload = [
                [h.url_wikidownastext, 'as text'],
                [h.url_wikidownasps, 'as post-script'],
                [h.url_wikidownaspdf, 'as pdf'],
            ]
            uservote = votcomp.get_wikivote(c.authuser, c.wiki)
            votes = wikicomp.countvotes(votes=c.wiki.votes)
            c.upvotes = votes.get('up', 0)
            c.downvotes = votes.get('down', 0)
            c.currvote = uservote and uservote.votedas or ''
            h.url_reviewwiki = self.url_wikireview(projectname, c.wiki.wikiurl,
                                                   c.wcnt.id)
            html = render('/derived/projects/wiki.html')

        c.rclose.append(html)
        return c.rclose
Пример #20
0
    def urlfor_match( self, m, urlconstructor ) :
        """Construct url for the matching document"""
        from zeta.config.environment import \
                    userscomp, attcomp, liccomp, syscomp, projcomp, tckcomp, \
                    revcomp, wikicomp

        do_onetime( self.compmgr.config )
        doc     = m.document
        doctype = doc.get_value( DOCTYPE )
        id      = doc.get_value( ID )
        if doctype == 'user' :
            user    = userscomp.get_user( int(id ))
            text    = 'User : %s' % user.username
            url     = urlconstructor['user']( int(id)  )
        elif doctype == 'attach' :
            attach  = attcomp.get_attach( int(id ))
            # Attachments can be deleted
            if attach :
                text = 'Attachment : %s' % attach.filename
                url  = urlconstructor['attach']( int(id) )
            else :
                text = '-- Missing attachment. May be deleted'
                url  = ''
        elif doctype == 'license' :
            license = liccomp.get_license( int(id ))
            # License can be deleted
            if license :
                text = 'License : %s' % license.licensename
                url  = urlconstructor['license']( int(id) )
            else :
                text = '-- Missing License. May be deleted'
                url  = ''
        elif doctype == 'staticwiki' :  # id is 'path'
            swiki = syscomp.get_staticwiki( unicode(id) )
            text = 'Guest Wiki : %s' % swiki.path
            url = urlconstructor['staticwiki']( id )
        elif doctype == 'project' :
            project = projcomp.get_project( int(id) )
            text = 'Project : %s' % project.projectname
            url = urlconstructor['project']( int(id) )
        elif doctype == 'ticket' :
            projectname = doc.get_value( PROJECTNAME )
            ticket = tckcomp.get_ticket( int(id) )
            text = '(%s) Ticket : %s' % (projectname, ticket.summary)
            url = urlconstructor['ticket']( projectname, int(id) )
        elif doctype == 'review' :
            projectname = doc.get_value( PROJECTNAME )
            review  = revcomp.get_review( int(id) )
            text    = '(%s) Review : %s' % (projectname, review.id)
            url = urlconstructor['review']( projectname, int(id) )
        elif doctype == 'wiki' :
            projectname = doc.get_value( PROJECTNAME )
            wiki    = wikicomp.get_wiki( int(id) )
            text    = '(%s) Wiki : %s' % \
                            (projectname, os.path.basename(wiki.wikiurl))
            url = urlconstructor['wiki']( projectname, int(id) )
        else :
            text = ''
            url  = ''

        return text, url