예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
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)
예제 #6
0
    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'))
예제 #7
0
 def __init__(self):
     self.page_repo = Backend('Page')
예제 #8
0
def cached_user(uid):
    return Backend('User').find(uid)
예제 #9
0
 def _config(self):
     return Backend('Pair').find('system').json_value()
예제 #10
0
 def __init__(self):
     self.repo = Backend(User.__name__)
예제 #11
0
 def __init__(self):
     self.category_repo = Backend(Category.__name__)
     self.post_repo = Backend('Post')
예제 #12
0
 def __init__(self):
     self.extend_repo = Backend('Extend')
     self.meta_repo = Backend('Meta')
예제 #13
0
def menus():
    return Backend('Page').menu(True)
예제 #14
0
 def comments(self):
     return Backend('Comment').find_by_post_id(self.pid)
예제 #15
0
 def category_count(self):
     return Backend('Post').category_count(self.cid)
예제 #16
0
 def __init__(self):
     self.page_repo = Backend(Page.__name__)
예제 #17
0
 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')
예제 #18
0
 def custom_field(self, key):
     extend = Backend('extend').field('post', key)
     return extend.value(self.pid, type='post')
예제 #19
0
def categories():
    return Backend('Category').categories()