def getCategories(self, blogid, username, password): """See IMetaWeblogAPI. """ weblog = IUIDManager(self.context).getByUID(blogid) weblog = IWeblog(weblog) topics = weblog.getTopics() # 2005-12-13 tomster: # this is kind of ugly: according to the RFC we should return an array # of structs, but according to http://typo.leetsoft.com/trac/ticket/256 # (at least) MarsEdit and ecto expect an array of strings containing the # category id. # Nigel: To accommodate ecto and other blogging clients we are going to # do this test to decide what format the topics should be returned in useragent = self.request['HTTP_USER_AGENT'] if "ecto" in useragent or "Mars" in useragent: #self.plone_log("MetaWeblogAPI", "Using ecto/MarsEdit hack") categories = [topic.getId() for topic in topics] else: categories = [] for topic in topics: categories.append( {'description' : topic.getId(), 'htmlUrl' : topic.absolute_url(), 'rssUrl' : '%s/rss.xml' % topic.absolute_url(), }) return categories
def getRecentPosts(self, blogid, username, password, num): """See IMetaWeblogAPI. """ weblog = IUIDManager(self.context).getByUID(blogid) weblog = IWeblog(weblog) entries = weblog.getEntries(maximum=num) return [self.entryStruct(entry) for entry in entries]
def deletePost(self, postid, username, password, publish): """See IMetaWeblogAPI. """ entry = IUIDManager(self.context).getByUID(postid) entry = IWeblogEntry(entry) weblog = entry.getParentWeblog() weblog.deleteEntry(entry.getId()) return True
def editPost(self, postid, username, password, struct, publish): """See IMetaWeblogAPI. """ struct = CaselessDict(struct) entry = IUIDManager(self.context).getByUID(postid) entry = IWeblogEntry(entry) body = struct.get('description') excerpt, text = self.extractExcerptFromBody(body) title = struct.get('title') topics = struct.get('categories') entry.edit(title, excerpt, text, topics) if publish: IWorkflowedWeblogEntry(entry).publish() return True
def newPost(self, blogid, username, password, struct, publish): """See IMetaWeblogAPI. """ struct = CaselessDict(struct) weblog = IUIDManager(self.context).getByUID(blogid) weblog = IWeblog(weblog) # preparing the ingredients: body = struct.get('description') # if the body contains an excerpt, we extract it: excerpt, text = self.extractExcerptFromBody(body) title = struct.get('title') topics = struct.get('categories') entry = weblog.addEntry(title=title, excerpt=excerpt, text=text, topics=topics,) if publish: IWorkflowedWeblogEntry(entry).publish() return IUIDManager(entry).getUID()
def newMediaObject(self, blogid, username, password, struct): """See IMetaWeblogAPI """ # These first three are required to be present by the spec. name = struct['name'] mimetype = struct['type'] bits = struct['bits'] # We support the presence of a 'title' element, just in case the client # sends it. title = struct.get('title', '') weblog = IUIDManager(self.context).getByUID(blogid) weblog = IWeblog(weblog) obj = weblog.addFile(bits.data, mimetype, name, title) # XXX This next line should almost certainly adapt to IAbsoluteURL, # rather than assume that the returned object has an absolute_url # method! if getattr(obj, 'absolute_url', None): url = obj.absolute_url() else: url = obj.context.absolute_url() return {'url': url}