Ejemplo n.º 1
0
 def xmlrpc_publish(self, author, title, category, content):
     newid = IBlog(self.store).getNextId()
     newPost = Post(store=self.store,
                    id=newid,
                    author=unicode(author),
                    title=unicode(title),
                    category=unicode(category),
                    content=unicode(content))
     IBlog(self.store).addNewPost(newPost)
     return 'Successfully added post number %s' % newid
Ejemplo n.º 2
0
 def xmlrpc_edit(self, id, author, title, category, content):
     post = IBlog(self.store).getOne(id)
     post.author = author
     post.title = title
     post.category = category
     post.content = content
     post.setModified()
     return 'Successfully modified post number %s' % id
Ejemplo n.º 3
0
 def childFactory(self, ctx, segment):
     id = segment.isdigit() and segment or '-1'
     if int(id) >= 0:
         return IBlog(IStore(ctx)).getOne(int(id))
     elif segment == 'rpc2':
         return BlogRPC(IStore(ctx))
     elif segment == 'atom.xml':
         return Atom()
Ejemplo n.º 4
0
 def insert(self, ctx, id, title, author, category, content):
     newPost = Post(store=IStore(ctx),
                    id=int(id),
                    author=unicode(author),
                    title=unicode(title),
                    category=unicode(category),
                    content=unicode(content))
     IBlog(IStore(ctx)).addNewPost(newPost)
     inevow.IRequest(ctx).setComponent(iformless.IRedirectAfterPost, '/thx')
Ejemplo n.º 5
0
 def data_getEntries(self, ctx, data):
     num = ctx.arg('num', '60')
     return IBlog(IStore(ctx)).getPosts(int(num))
Ejemplo n.º 6
0
 def xmlrpc_entries(self, count):
     return [(entry.id, entry.author, entry.category, entry.title, entry.content) \
             for entry in IBlog(self.store).getPosts(count)]
Ejemplo n.º 7
0
 def data_get_posts(self, ctx, data):
     return IBlog(IStore(ctx)).getPosts(15)
Ejemplo n.º 8
0
 def data_getFirstPost(self, ctx, data):
     for post in IBlog(IStore(ctx)).getPosts(1):
         return post
Ejemplo n.º 9
0
 def render_forms(self, ctx, data):
     d = iformless.IFormDefaults(ctx).getAllDefaults('insert')
     d['author'] = 'Anonymous'
     d['id'] = IBlog(IStore(ctx)).getNextId()
     return webform.renderForms()
Ejemplo n.º 10
0
    def eomReceived(self):
        post = {}
        isContent = False
        ctnt_buff = []
        recipients = self.lines[0]
        addrs = []

        for recipient in recipients:
            if '@' not in recipient.orig.addrstr:
                # Avoid answering to bounches
                if not recipient.orig.addrstr == '<>':
                    addrs.append(recipient.orig.addrstr[:-1]+'@'+recipient.orig.domain+'>')
            else:
                # Avoid answering to bounches
                if not recipient.orig.addrstr == '<#@[]>':
                    addrs.append(recipient.orig.addrstr)
            
        for line in self.lines[1:]:
            if not isContent:
                try:
                    field, value = line.split(':', 1)
                except ValueError:
                    continue
                if field.lower() != 'content':
                    post[field.lower()] = value.strip()
                else: 
                    isContent = True
                    ctnt_buff.append(value.strip())
            else:
                ctnt_buff.append(line.strip())
        post['content'] = '\n'.join(ctnt_buff)
        
        for header in 'content author category title'.split():
            if header not in post:
                self.lines = []
                return defer.fail(None) 
        if 'id' in post:
            oldpost = IBlog(self.store).getOne(int(post['id']))
            oldpost.author = str(post['author'])
            oldpost.title = str(post['title'])
            oldpost.category = str(post['category'])
            oldpost.content = str(post['content'])
            oldpost.setModified()
            action = 'modified'
            id = post['id']
        else:
            newid = IBlog(self.store).getNextId()
            newPost = Post(store=self.store,
                           id=newid,
                           author=str(post['author']),
                           title=str(post['title']),
                           category=str(post['category']),
                           content=str(post['content']))
            IBlog(self.store).addNewPost(newPost)
            action = 'added'
            id = newid
        self.lines = []
        msg = """From: <%s>
Subject: Successfull Post

Post number %s successfully %s
""" % (FROM, id, action)
        return self.sendNotify(addrs, msg)
Ejemplo n.º 11
0
    def eomReceived(self):
        post = {}
        isContent = False
        ctnt_buff = []
        recipients = self.lines[0]
        addrs = []

        for recipient in recipients:
            if '@' not in recipient.orig.addrstr:
                # Avoid answering to bounches
                if not recipient.orig.addrstr == '<>':
                    addrs.append(recipient.orig.addrstr[:-1] + '@' +
                                 recipient.orig.domain + '>')
            else:
                # Avoid answering to bounches
                if not recipient.orig.addrstr == '<#@[]>':
                    addrs.append(recipient.orig.addrstr)

        for line in self.lines[1:]:
            if not isContent:
                try:
                    field, value = line.split(':', 1)
                except ValueError:
                    continue
                if field.lower() != 'content':
                    post[field.lower()] = value.strip()
                else:
                    isContent = True
                    ctnt_buff.append(value.strip())
            else:
                ctnt_buff.append(line.strip())
        post['content'] = '\n'.join(ctnt_buff)

        for header in 'content author category title'.split():
            if not post.has_key(header):
                self.lines = []
                return defer.fail(None)
        if post.has_key('id'):
            oldpost = IBlog(self.store).getOne(int(post['id']))
            oldpost.author = unicode(post['author'])
            oldpost.title = unicode(post['title'])
            oldpost.category = unicode(post['category'])
            oldpost.content = unicode(post['content'])
            oldpost.setModified()
            action = 'modified'
            id = post['id']
        else:
            newid = IBlog(self.store).getNextId()
            newPost = Post(store=self.store,
                           id=newid,
                           author=unicode(post['author']),
                           title=unicode(post['title']),
                           category=unicode(post['category']),
                           content=unicode(post['content']))
            IBlog(self.store).addNewPost(newPost)
            action = 'added'
            id = newid
        self.lines = []
        msg = """From: <%s>
Subject: Successfull Post

Post number %s successfully %s
""" % (FROM, id, action)
        return self.sendNotify(addrs, msg)