예제 #1
0
        d.addCallback(_transformResult)
        return d
    
    def findAllUsers(self):
        return self.store.runQuery(q.all_users)

    def getUserWithStats(self, username):
        return self.store.runQuery(q.user_stats, username)

    def getUsersWithStats(self):
        return self.store.runQuery(q.all_users_stats)

    def addUser(self, properties):
        return self.store.runOperation(q.add_user, properties)

util.backwardsCompatImplements(UsersDatabase)

class SectionsDatabase(object):

    util.implements(idb.ISectionsDatabase)

    def __init__(self, db):
        self.store = db

    def getAllSections(self):
        return self.store.runQuery(q.all_sections)
    
    def simpleGetAllSections(self):
        return self.store.runQuery(q.simple_all_sections)
    
    def getSectionInfo(self, sid):
예제 #2
0
            database_dsn = database_dsn + host_dsn
        self.__pool = adbapi.ConnectionPool(db_adapter,
                                            dsn=database_dsn,
                                            cp_min=3, cp_max=10)

    def runQuery(self, query, *args):
        d = self.__pool.runInteraction(self._mapQuery, query, args)
        return d

    def _mapQuery(self, curs, query, *args):
        curs.execute(query, *args)
        dx = u.maybeDeferred(curs.fetchall)
        def mapper(result, xcurs):
            columns = [d[0] for d in xcurs.description]
            return [dict(zip(columns, r)) for r in result]  
        def _error(error):
            print error      
        dx.addCallback(mapper, curs)
        dx.addErrback(_error)
        return dx

    def runOperation(self, query, *args):
        d = self.__pool.runOperation(query, args[0])
        return d

    def runInteraction(self, fun, queries=(), args=()):
        d = self.__pool.runInteraction(fun, queries, args)
        return d

util.backwardsCompatImplements(Store)
예제 #3
0
        self.args.append(start)
        return Topic(self.args, ctnt=TopicContent)
    
    def quick_reply(self, ctx, title, content):
        if not iusers.IA(ctx).get('uid'):
            raise WebException("You must login first")
        properties = dict(thread_id=self.args[0],
                          owner_id=iusers.IA(ctx)['uid'],
                          creation=datetime.now(),
                          modification=datetime.now(),
                          title=title,
                          body=content
                         )
        d = idb.ITopicsDatabase(idb.IS(ctx)).addPost(properties)
        return d
util.backwardsCompatImplements(Topic)

class TopicContent(BaseContent):

    docFactory = loaders.xmlfile(getTemplate('topic_content.html'),
            ignoreDocType=True)

    def __init__(self, args, data=None):
        super(TopicContent, self).__init__(args, data)
        if len(args) <= 1:
            self.offset = '1'
            self.start = 1
        else:
            self.offset = str(args[1])
            self.start = args[1]
        self.LIMIT = '10'
예제 #4
0
    def render_foot(self, ctx, data):
        return ctx.tag
    
    def render_empty(self, ctx, data):
        return ctx.tag
    
    def render_form(self, ctx, data):
        return webform.renderForms(bindingNames=["insert"])[ctx.tag]

class ASections(main.MasterPage):

    util.implements(IASections)

    content = ASectionsContent

    def data_head(self, ctx, data):
        return [{'ttitle':'Admin Sections -- Weever'}]    
    
    def edit(self, ctx, id, oldstate):
        pass
    def insert(self, ctx, title, description):
        properties = dict(title=title, description=description)
        d = iusers.IA(ctx).sections.addSection(properties)
        return d
    def delete(self, ctx, id):
        d = iusers.IA(ctx).sections.delSection(dict(sid=id))
        return d

util.backwardsCompatImplements(ASections)

예제 #5
0
            d = iusers.IA(ctx).users.findUser(username)
            d.addCallback(login, ctx)
            return d
        def errback(failure, ctx, username):
            error = 'Username: %s already existing' % username
            raise annotate.ValidateError({ 'username' : error }, 'Error: ' + error)  

        def login(creds, ctx):
            avatar = iusers.IA(ctx)
            # if using new guard
            # s = inevow.ISession(ctx)
            # creds = credentials.UsernamePassword(avatar['ulogin'], avatar['upassword'])
            # s.setComponent(creds, ignoreClass=True)

            #s = inevow.ISession(ctx)
            #res = index.Main()
            avatar.creds = creds
            #res.remember(avatar, iusers.IA)
            #s.setResourceForPortal(res, s.guard.resource.portal, res.logout)
            #
        uri = iweb.ILastURL(inevow.ISession(ctx), None)
        if uri:
            inevow.ISession(ctx).unsetComponent(iweb.ILastURL)
        inevow.IRequest(ctx).setComponent(iformless.IRedirectAfterPost,uri or '')
        d = iusers.IA(ctx).users.addUser(properties)
        d.addErrback(errback, ctx, username)
        d.addCallback(success, ctx, username)
        return d
util.backwardsCompatImplements(Register)