def update(self, ident, title, content, labels): id = ident self._expireCache(id) BlogModel.update(id, title, content, labels) p = BlogModel.getPostById(id) return '%s' % p.id
def viewEntry(self, path_info, formvars): post_id = path_info.split("/")[-1] if amiweb.request()['QUERY_STRING']: post_id = amiweb.request()['QUERY_STRING'].split('=')[-1] post = BlogModel.getPostById(post_id) edit_mode = False if Site.Users.isLoggedIn(): edit_mode = True kw = {} if post: blog = BlogModel.getBlogById(post.blog_id) page = CMSModel.Pages.getPageById(blog.host_page) content = '<div id="Blog_%s" post_id="%s">%s</div>' %\ (post.getIdent(), post.id, renderPost(post, edit_mode, True)) kw['content'] = content kw['title'] = post.title kw['host_page'] = blog.host_page kw['id'] = "blogpost_%s" % post_id kw['hidden'] = page.hidden kw['premission_type'] = page.premission_type else: kw['title'] = 'Not found' kw['content'] = 'Not found' kw['host_page'] = 1 kw['id'] = None kw['hidden'] = False kw['premission_type'] = 'Everyone' kw['edit_mode'] = edit_mode page_obj = Site.PageDeco(kw) return page_obj.servePage()
def labelAdd(self, ident, name): blog = BlogModel.getBlogByIdent(ident) if not blog: blog = BlogModel.addBlog(ident) try: return BlogLabelModel.add(blog.id, name).toJSON() except IntegrityError: raise amiweb.AppError('A label is already found with the same name.')
def viewArchive(self, path_info, formvars): blogid_year = path_info.split('/')[-1] sp = blogid_year.split('-') blog_id = sp[0] year = int(sp[1]) kw = {} blog = BlogModel.getBlogById(blog_id) posts = blog.getPostsByYear(year) title = 'Post archive for year %s' % year ns = { 'posts': posts, 'amiformat': getFormatManager().noPluginFormat, 'title': title, 'GENERIC_POST_LINK': GENERIC_POST_LINK } kw['content'] = render('site_plugins/blog/view/viewPosts.tmpl', ns) kw['title'] = title kw['host_page'] = blog.host_page kw['id'] = "blogarchive_%s" % blogid_year kw['hidden'] = False kw['edit_mode'] = False kw['premission_type'] = 'Everyone' page_obj = Site.PageDeco(kw) return page_obj.servePage()
def getPostHTMLData(self, id, is_permanent): if is_permanent == 'True': is_permanent = True else: is_permanent = False post = BlogModel.getPostById(id) return renderPost(post, True, is_permanent)
def getArchiveList(self, ident, cls): blog = BlogModel.getBlogByIdent(ident) if blog: link = '<a href="%s">%s</a>' % (GENERIC_ARCHIVE_LINK % (blog.id, '%s'), '%s') years = ['<li>Posts in %s</li>' % (link % (y, y)) for y in blog.getArchiveYears()] return '<ul class="%s">\n%s\n</ul>' % (cls, '\n'.join(years)) else: return None
def getLabelList(self, ident, cls): blog = BlogModel.getBlogByIdent(ident) if blog: link = '<a href="%s">%s</a>' % (GENERIC_LABEL_LINK, '%s') labels = ['<li>%s</li>' % (link % (l.id, l.name)) for l in blog.getLabels()] return '<ul class="%s">\n%s\n</ul>' % (cls, '\n'.join(labels)) else: return None
def renderContent(self, ident, edit_mode): posts = BlogModel.getAllPosts(ident, 15) ns = { 'ident': ident, 'posts': posts, 'edit_mode': edit_mode, 'renderPost': renderPost } return render("site_plugins/blog/view/items.tmpl", ns)
def _expireCache(self, post_id): post = BlogModel.getPostById(post_id) blog = post.getBlog() AmiCache.expireCache(post.getHostPage()) AmiCache.expireCache('blogpost_%s' % post_id) for l in post.getLabels(): AmiCache.expireCache('bloglabel_%s' % l.id) for y in blog.getArchiveYears(): AmiCache.expireCache('blogarchive_%s-%s' % (blog.id, y))
def viewEdit(self, id): post = BlogModel.getPostById(id) ns = {'template': self.template, 'ident': id, 'title': post.title, 'content': post.content, 'hasLabel': post.hasLabel, 'action': 'update', 'submit_value': 'Save changes', 'labels': BlogLabelModel.getAllByIdent(post.getIdent()) } return render("site_plugins/blog/view/manage_post.tmpl", ns)
def viewLabelPosts(self, path_info, formvars): label_id = path_info.split('/')[-1] kw = {} label = BlogLabelModel.getById(label_id) posts = label.getPosts() blog = BlogModel.getBlogById(label.blog_id) title = '%s posts posted under label "%s"' % (len(posts), label.name) ns = { 'posts': posts, 'amiformat': getFormatManager().noPluginFormat, 'title': title, 'GENERIC_POST_LINK': GENERIC_POST_LINK } kw['content'] = render('site_plugins/blog/view/viewPosts.tmpl', ns) kw['title'] = title kw['host_page'] = blog.host_page kw['id'] = "bloglabel_%s" % label_id kw['hidden'] = False kw['edit_mode'] = False kw['premission_type'] = 'Everyone' page_obj = Site.PageDeco(kw) return page_obj.servePage()
def flipPublish(self, id): self._expireCache(id) return str(BlogModel.flipPublish(id))
def delete(self, id): self._expireCache(id) BlogModel.delete(id) return 'ok'
def add(self, ident, title, content, labels): AmiCache.expireCurrentPage() BlogModel.add(ident, title, content, labels) return ident