def get(self, page_id): page_id = int(page_id) pages = Backend('Page').dropdown(show_empty_option=True) page = Backend('Page').find(page_id) fields = extend_service.get_fields_by_type('page', page_id) self.render('admin/page/edit.html', statuses=PAGE_STATUSES, pages=pages, page=page, fields=fields)
def get(self): if request.method == 'GET': pages = Backend('Page').dropdown(show_empty_option=True) fields = extend_service.get_fields_by_type('page') self.render('admin/page/add.html', statuses=PAGE_STATUSES, pages=pages, fields=fields)
def process(self): type = self.type item_id = self.node.pid data = None for extend in Backend('Extend').find_by_type(type): process = getattr(self, 'process_' + extend.field, None) # if process: data = process(extend) if data: meta = Backend('meta').find(type, item_id, extend.eid) if meta: meta.data = data Backend('meta').save(meta) else: meta = Meta(item_id, type, extend.eid, data) Backend('meta').create(meta)
def url(self): segments = [self.slug] parent = self.parent Store = Backend('page') while parent: page = Store.find(parent) if page: segments.insert(0, page.slug) parent = page.parent else: break return '/' + '/'.join(segments)
class CommentThing(object): comment_repo = Backend('Comment') get = lambda self, cid: self.comment_repo.find(cid) def get_by_post_id(self, post_id): return self.comment_repo.find_by_post_id(post_id) def page(self, status, page=1, perpage=10): total = self.comment_repo.count() pages = self.comment_repo.paginate(page, perpage, status) pagination = Paginator(pages, total, page, perpage, '/admin/comment') return pagination def add_comment(self, name, email, content, status, post): comment = Comment(post.pid, name, email, content, status) if self.is_spam(comment): comment.status = 'spam' cid = self.comment_repo.create(comment) comment.cid = cid return comment @classmethod def is_spam(self, comment): for word in site.comment_moderation_keys(): if word.strip() and re.match(word, comment.content, re.I): return True domain = comment.email.split('@')[1] if self.comment_repo.spam_count(domain): return True return False def update_comment(self, comment_id, name, email, content, status): comment = self.get(comment_id) if not comment: return None comment.status = status comment.name = name comment.content = content comment.email = email self.comment_repo.save(comment) return comment def delete(self, comment_id): comment = self.comment_repo.find(comment_id) if not comment: return None return self.comment_repo.delete(comment.cid)
def post(self): _ = self.get_argument parent = _('parent') name = _('name') title = _('title') name = name or title slug = _('slug') content = _('content') status = _('status') pid = int(_('pid')) show_in_menu = int(_('show_in_menu')) show_in_menu = 1 if show_in_menu else 0 redirect_ = _('redirect') validator = Validator() validator.add('duplicate', lambda key: page_service.is_exist_slug(key) == False) (validator.check(title, 'min', text('page.title_missing'), 3).check(slug, 'min', text('page.slug_missing'), 3).check(slug, 'duplicate', text('page.slug_duplicate')).check( slug, 'regex', text('page.slug_invalid'), r'^[0-9_A-Za-z-]+$') #.check(redirect, 'url', text('page.redirect_missing')) ) if validator.errors: self.flash(validator.errors, 'error') pages = Backend('Page').dropdown(show_empty_option=True) fields = extend_service.get_fields_by_type('page') self.render('admin/page/add.html', statuses=PAGE_STATUSES, pages=pages, fields=fields) page = page_service.add_page(parent, name, title, slug, content, status, redirect_, show_in_menu) extend_service.prcoess_field(self, page, 'page') self.redirect(self.reverse_url('page_page'))
def __init__(self): self.page_repo = Backend('Page')
def cached_user(uid): return Backend('User').find(uid)
def _config(self): return Backend('Pair').find('system').json_value()
def __init__(self): self.repo = Backend(User.__name__)
def __init__(self): self.category_repo = Backend(Category.__name__) self.post_repo = Backend('Post')
def __init__(self): self.extend_repo = Backend('Extend') self.meta_repo = Backend('Meta')
def menus(): return Backend('Page').menu(True)
def comments(self): return Backend('Comment').find_by_post_id(self.pid)
def category_count(self): return Backend('Post').category_count(self.cid)
def __init__(self): self.page_repo = Backend(Page.__name__)
def __init__(self, post_repo=None, category_repo=None): self.post_repo = post_repo or Backend('Post') self.category_repo = category_repo or Backend('Category')
def custom_field(self, key): extend = Backend('extend').field('post', key) return extend.value(self.pid, type='post')
def categories(): return Backend('Category').categories()