Beispiel #1
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
Beispiel #2
0
    def index( self, environ ) :
        """List all the projects.
        URLS :
            /p
            /p?alphaindex=<alphaindex>
        """
        from zeta.config.environment    import projcomp, vfcomp

        c.rclose = h.ZResp()

        # Setup context for page generation
        x = projcomp.get_project( attrload=['admin', 'project_info'] )
        c.projects = x
        c.urlprojects = dict([ ( p.id, self.url_forproject( p.projectname )) for p in x ])
        c.title = 'ProjectIndex'

        byindex = {}
        [ byindex.setdefault( p.projectname[0], [] ).append(p) for p in x ]
        c.indexlist = sorted( byindex.keys() )
        if (c.alphaindex == None) and (len(c.projects) > h.MAX2SWITCH_ALPHAINDEX) :
            c.alphaindex = c.indexlist[0]
        if c.alphaindex :
            c.projects = byindex[c.alphaindex]

        # Html page generation
        c.rclose.append(render( '/derived/projects/index.html' ))
        return c.rclose
Beispiel #3
0
    def commit(self, config, byuser, tz='UTC', attachments=[]):
        """If the identified structure is Attachment, commit the data to DB"""
        from zeta.config.environment import attcomp, projcomp

        data = self.dataset
        aid = data.get('id', None)
        summary = data.get('summary', None)
        tags = data.get('tags', [])
        p = data.get('projectname', None)
        p = p or data.get('projectid', None)
        p = p and projcomp.get_project(p)
        if aid:
            att = attcomp.get_attach(aid)
            if summary != None:
                attcomp.edit_summary(att, summary, byuser=byuser)
            if tags:
                attcomp.add_tags(att, tags, byuser=byuser)
        elif attachments:
            for fname, file in attachments:
                att = attcomp.create_attach(fname,
                                            FileC(file),
                                            uploader=byuser,
                                            summary=summary)
                p and projcomp.add_attach(p, att, byuser=byuser)
                tags and attcomp.add_tags(att, tags, byuser=byuser)
        return
Beispiel #4
0
    def timeline( self, environ, projectname ) :
        """Aggregate all the activities under the project
        URLS :
            /p/<projectname>/timeline
        """
        from zeta.config.environment    import projcomp, tlcomp

        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.project = c.project or projcomp.get_project( projectname )
        c.projectname = c.project.projectname
        c.projsummary = c.project.summary
        c.title = projectname + ':timeline'
        c.alllogs = tlcomp.fetchprojlogs(
                        c.project, limit=h.TLCOUNT+2, id=logid, direction=dir
                    )
        routeargs = { 'projectname' : projectname }
        self.tline_controller(
            h.r_projtline, routeargs, [], fromoff, logid, dir, c.project
        )
        h.url_rssfeed = h.url_for( h.r_projfeed, projectname=projectname )
        c.datatline, c.startdt = h.tlineplot( c.logs[:] )

        c.rclose.append(render( '/derived/projects/projtline.html' ))
        return c.rclose
Beispiel #5
0
    def _optimized_fetch( self, controllername, projname ) :
        """Fetch the project object (details) from the database in an optimized
        manner based on the action and json request"""
        from zeta.config.environment    import projcomp, tckcomp

        attrload, attrload_all = ( ['logofile'], [] )
        if c.jsonobj == 'pcomplist' :
            attrload_all.extend([ 'components.owner' ])
        elif c.jsonobj == 'mstnlist' :
            attrload.extend([ 'milestones' ])
        elif c.jsonobj == 'verlist' :
            attrload.extend([ 'versions' ])
        elif controllername == 'projadmin' :
            attrload.extend([ 'iconfile', 'license', 'project_info',
                              'mailinglists', 'ircchannels', 'admin', 
                           ])
        elif controllername == 'projectmilestone' :
            attrload.extend([ 'milestones' ])
            c.mstntickets= tckcomp.mstntickets( c.project )
        elif controllername == 'projectroadmap' :
            attrload.extend([ 'milestones' ])
            c.mstntickets= tckcomp.mstntickets( c.project )
        elif controllername == 'projectcharts' :
            attrload.extend([ 'milestones', 'versions', 'components' ])
            c.mstntickets= tckcomp.mstntickets( c.project )
        elif controllername == 'projecthome' :
            attrload.extend([ 'mailinglists', 'ircchannels', 'license', 'tags',
                              'admin' ])
            attrload_all.extend([ 'team.user' ])

        c.project = projcomp.get_project(
                        projname, attrload=attrload, attrload_all=attrload_all
                    ) if projname else None
Beispiel #6
0
    def analyse(self):
        from zeta.config.environment import projcomp

        projects = projcomp.get_project()

        self.id2name = dict([(p.id, p.projectname) for p in projects])
        self.name2id = dict([(p.projectname, p.id) for p in projects])

        self.chart14_data = self.do_chart14(projects)
Beispiel #7
0
    def config_wiki(self,
                    wiki,
                    wtype=None,
                    summary=None,
                    sourceurl=None,
                    project=None,
                    doclose=None,
                    byuser=None):
        """For the wiki page identified by
        `wiki`, which can be,
            `id` or `wikiurl` or `Wiki` instance.
        Set the wiki wtype.
        `wtype`, can be
            `id` or `wiki_typename` or `WikiType` instance.
        Add the project to which the wiki belongs to.
        `project` can be,
            `id` or `projectname` or `Project` instance
            if project can also be a string."""
        from zeta.config.environment import projcomp, tlcomp, srchcomp

        wiki = self.get_wiki(wiki)
        wtype = wtype and self.get_wikitype(wtype)
        project = project and projcomp.get_project(project)
        msession = meta.Session()
        summary = summary and summary.replace('\n', ' ').replace('\r', ' ')
        with msession.begin(subtransactions=True):
            # Construct log based on attributes that have changed
            loglines = []
            wtype and loglines.append(
                ('type', wiki.type.wiki_typename, wtype.wiki_typename))
            summary and loglines.append(('summary', wiki.summary, summary))
            sourceurl and loglines.append(
                ('sourceurl', wiki.sourceurl, sourceurl))
            log = h.logfor(loglines)
            if log:
                log = 'Changed,\n%s' % log
            # Logging ends here

            if wtype:
                wiki.type = wtype

            if summary != None:
                wiki.summary = unicode(summary)

            if sourceurl != None:
                wiki.sourceurl = unicode(sourceurl)

            if project != None:
                wiki.project = project

        # Post processing, optional deferred handling
        def onclose(tlcomp, srchcomp, wiki, byuser, log):
            log and tlcomp.log(byuser, log, wiki=wiki)
            srchcomp.indexwiki([wiki], replace=True)

        doclose(h.hitchfn(onclose, tlcomp, srchcomp, wiki, byuser, log))
        return None
Beispiel #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)
Beispiel #9
0
    def commit(self, config, byuser, tz='UTC', attachments=[]):
        """If the identified structure is Review, commit the data to DB"""
        from zeta.config.environment import attcomp, projcomp, revcomp

        data = self.dataset
        attrs = [
            'reviewid', 'rcmtid', 'projectname', 'projectid', 'position',
            'nature', 'action', 'approved', 'tags', 'favorite', 'comment'
        ]

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

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

        r = kwargs.pop('reviewid', None)
        rcmt = kwargs.pop('rcmtid', None)
        r = revcomp.get_review(r)

        nature = kwargs.pop('nature', None)
        action = kwargs.pop('action', None)
        approved = kwargs.pop('approved', None)
        position = kwargs.pop('position', None)
        comment = kwargs.pop('comment', None)

        if r and comment and position:
            revcomp.create_reviewcomment(
                r, (None, position, comment, byuser, nature, None),
                byuser=byuser)
        elif rcmt:
            revcomp.process_reviewcomment(rcmt,
                                          reviewnature=nature,
                                          reviewaction=action,
                                          approve=approved,
                                          byuser=byuser)
        if r:
            # Favorite
            fav = kwargs.pop('favorite', None)
            fav == True and revcomp.addfavorites(r, [byuser], byuser=byuser)
            fav == False and revcomp.delfavorites(r, [byuser], byuser=byuser)

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

        # Attachments
        if r:
            for fname, fcont in attachments:
                att = attcomp.create_attach(fname,
                                            FileC(fcont),
                                            uploader=byuser)
                revcomp.add_attach(r, att, byuser=byuser)
Beispiel #10
0
def url_formodel(name, obj):
    """Compute the href for model object"""
    from zeta.config.environment import \
            userscomp, attcomp, tagcomp, liccomp, projcomp, wikicomp, \
            tckcomp, revcomp, vcscomp

    a_tmpl = name + ' <a href="%s" title="%s">%s</a>'
    cntlr = BaseController()

    if name == 'user':
        u = userscomp.get_user(obj)
        a = a_tmpl % (cntlr.url_user(u.username), u.username, u.username)

    elif name == 'tag':
        t = tagcomp.get_tag(obj)
        a = a_tmpl % (cntlr.url_tag(t.tagname), t.tagname, t.tagname)

    elif name == 'attach':
        att = attcomp.get_attach(obj)
        a = a_tmpl % (cntlr.url_attach(att.id), att.filename, att.filename)

    elif name == 'license':
        l = liccomp.get_license(obj)
        a = a_tmpl % (cntlr.url_forlicense(l.id), l.summary, l.licensename)

    elif name == 'project':
        p = projcomp.get_project(obj)
        a = a_tmpl % (cntlr.url_forproject(
            p.projectname), p.summary, p.projectname)

    elif name == 'ticket':
        a = a_tmpl % (cntlr.url_ticket(obj.project.projectname,
                                       obj.id), obj.summary, obj.id)

    elif name == 'review':
        a = a_tmpl % (cntlr.url_revwid(obj.project.projectname, obj.id),
                      obj.resource_url, obj.resource_url)

    elif name == 'vcs':
        a = a_tmpl % (cntlr.url_vcsbrowse(obj.project.projectname,
                                          obj.id), obj.name, obj.name)

    elif name == 'wiki':
        a = a_tmpl % (obj.wikiurl, obj.summary, obj.wikiurl)

    elif name == 'staticwiki':
        a = a_tmpl % (obj.path, obj.path, obj.path)

    else:
        raise ZetaError('Unkown model name in timeline reference')

    return a
Beispiel #11
0
    def indexproject( self, projects=[], clear=False, replace=False,
                      flush=True ) :
        """Index all the projects passed as argument, or index all the
        projects in the database if 'projects' is empty.
        If clear == True,
            then do the reverse, (i.e) clear the list of projects from index
        If replace == True,
            then replace the list of projects with new data"""
        from zeta.config.environment import projcomp

        config = self.compmgr.config
        if config['zeta.xapiansearch'] :
            do_onetime( config )
            projects = projects or projcomp.get_project()
            if clear :
                [ self.clear( 'id:project_%s' % p.id, flush=flush )
                  for p in projects ]
            else :
                [ self.index( projcomp.documentof(p), replace, flush=flush )
                  for p in projects ]
        return
Beispiel #12
0
    def create_ticket( self, projectname, summary, type, severity, owner,
                       description=u'', components=None, milestones=None,
                       versions=None, blocking=None, blockedby=None,
                       parent=None
                     ) :
        """Create a ticket for the project `projectname`"""
        from zeta.config.environment import tckcomp, projcomp

        project  = projcomp.get_project( projectname )

        try :
            if project :

                tckdet = [ None, summary, description, type, severity ]
                tck    = tckcomp.create_ticket(
                                    project, tckdet, owner=owner, byuser=owner
                         )
                tckcomp.config_ticket(
                      tck,
                      components= components and [ int(id) for id in components if id ],
                      milestones= milestones and [ int(id) for id in milestones if id ],
                      versions  = versions and [ int(id) for id in versions if id ],
                      blocking  = blocking and [ int(id) for id in blocking if id ],
                      blockedby = blockedby and [ int(id) for id in blockedby if id ] ,
                      parent    = parent and int(parent),
                      byuser    = owner,
                      append    = False,
                )
                rc, d, failmsg = True, { 'id' : tck.id }, ''

            else :
                rc, d, failmsg = False, {}, ('Invalid project, %s'%projectname)

        except :
            rc, d, failmsg = ( False, {},
                               ("Type : %s, Value : %s" % sys.exc_info()[:2])
                             )

        return (rc, d, failmsg)
Beispiel #13
0
    def createticket(self, environ, projectname):
        """Create ticket
        URLS :
            /p/{projectname}/t/createticket?form=request&formname=createtck
            /p/{projectname}/t/createticket?form=submit&formname=createtck
        """
        from zeta.config.environment import vfcomp, projcomp, tckcomp

        c.rclose = h.ZResp()

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

        vfcomp.process(request,
                       c,
                       defer=True,
                       errhandler=h.hitchfn(errhandler),
                       formnames=['createtck'],
                       user=c.authuser)

        # Setup context for page generation
        c.project = c.project or projcomp.get_project(projectname)
        c.projectname = c.project.projectname
        c.projsummary = c.project.summary

        # HTML page generation
        if c.errmsg:
            html = self.returnerrmsg(environ)

        elif c.form == 'submit':
            h.flash(MESSAGE_FLASH + 'Created ticket ...')
            # Ticket creation, redirect after submit
            c.title = '-Skip-'
            h.redirect_url(h.url_ticketcreate)

        else:
            # Setup context for page generation
            c.seltickets = self._seltickets()
            c.tck_typenames = tckcomp.tcktypenames
            c.tck_statusnames = tckcomp.tckstatusnames
            c.tck_severitynames = tckcomp.tckseveritynames

            c.pcomponents, c.pmilestones, c.pversions, c.projusers = \
                              tckcomp.projdetails( c.project )
            c.projusers = list(set(c.projusers + [c.project.admin.username]))
            c.pmilestones = [m[:2] for m in c.pmilestones if not any(m[2:])]
            c.mstnnames = sorted([m[0] for m in c.pmilestones])

            c.pcompnames = sorted([comp[0] for comp in c.pcomponents])
            c.vernames = sorted([ver[0] for ver in c.pversions])
            c.pcomponents = [(tup[1], tup[0]) for tup in c.pcomponents]
            c.pmilestones = [(tup[1], tup[0]) for tup in c.pmilestones]
            c.pversions = [(tup[1], tup[0]) for tup in c.pversions]
            c.title = 'CreateTicket'
            c.tckeditable = h.authorized(h.HasPermname('TICKET_CREATE'))
            html = render('/derived/projects/ticketcreate.html')
            h.flash.pop_messages(
            )  # Clear flashmessage if any ! after page generation

        c.rclose.append(html)
        return c.rclose
Beispiel #14
0
 def sr_projecturl(self, id):
     from zeta.config.environment import projcomp
     project = projcomp.get_project(id)
     return self.url_forproject(project.projectname)
Beispiel #15
0
    def commit(self, config, byuser, tz='UTC', attachments=[]):
        """If the identified structure is Ticket, commit the data to DB"""
        from zeta.config.environment import attcomp, projcomp, tckcomp

        data = self.dataset
        attrs = [
            'ticket', 'projectname', 'projectid', 'type', 'severity',
            'summary', 'status', 'duedate', 'promptuser', 'components',
            'milestones', 'versions', 'blocking', 'blockedby', 'parent',
            'tags', 'favorite', 'vote', 'description', 'comment'
        ]
        kwargs = dict([(k, data.get(k, None)) for k in attrs])
        ticket = kwargs.pop('ticket', None)
        t = ticket and tckcomp.get_ticket(ticket)
        if t:
            kwargs.pop('projectname', '')
            kwargs.pop('projectid', '')
            ts = tckcomp.get_ticket_status(t.tsh_id)

            # Favorite
            fav = kwargs.pop('favorite', None)
            fav == True and tckcomp.addfavorites(t, [byuser], byuser=byuser)
            fav == False and tckcomp.delfavorites(t, [byuser], byuser=byuser)

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

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

            # Comment
            comment = kwargs.pop('comment', None)
            comment and tckcomp.create_ticket_comment(t,
                                                      (None, comment, byuser),
                                                      byuser=byuser)

            # Summary and Description
            summary = kwargs.pop('summary', None)
            descr = kwargs.pop('description', None)
            if (summary != None) or (descr != None):
                tckdet = [t.id, summary, descr, t.type, t.severity]
                tckcomp.create_ticket(None,
                                      tckdet,
                                      t.promptuser,
                                      update=True,
                                      byuser=byuser)

            # Ticket status, duedate
            status = kwargs.pop('status', None)
            duedate = kwargs.pop('duedate', None)
            duedate = duedate and h.duedate2dt(duedate, tz) or None
            if ( status == ts.status.tck_statusname and (duedate != None) )\
               or \
               ( (status == None) and (duedate != None) ) :
                # Just change the  duedate for current tsh
                tstatdet = [ts.id, ts.status, duedate]
                tckcomp.create_ticket_status(t,
                                             tstatdet,
                                             byuser,
                                             update=True,
                                             byuser=byuser)
            elif status:  # New status
                tstatdet = [None, status, duedate]
                tckcomp.create_ticket_status(t,
                                             tstatdet,
                                             byuser,
                                             byuser=byuser)

            # Rest of the configuration
            kwargs['byuser'] = byuser
            tckcomp.config_ticket(t, **kwargs)

        else:
            kwargs.pop('comment', '')
            kwargs.pop('ticket', '')
            kwargs.pop('status', '')
            kwargs.pop('duedate', '')

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

            ttype = kwargs.pop('type', None)
            severity = kwargs.pop('severity', None)
            summary = kwargs.pop('summary', None)
            t = None

            if p and ttype and severity and summary:
                descr = kwargs.pop('description', None)
                puser = kwargs.pop('prompuser', None)
                tckdet = (None, summary, descr, ttype, severity)
                t = tckcomp.create_ticket(p,
                                          tckdet,
                                          promptuser=puser,
                                          owner=byuser,
                                          byuser=byuser)

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

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

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

                # Rest of the Configuration for ticket
                kwargs['byuser'] = byuser
                tckcomp.config_ticket(t, **kwargs)

        # Attachments
        if t:
            for fname, fcont in attachments:
                att = attcomp.create_attach(fname,
                                            FileC(fcont),
                                            uploader=byuser)
                tckcomp.add_attach(t, att, byuser=byuser)
Beispiel #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)
Beispiel #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"
Beispiel #18
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