Ejemplo n.º 1
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'))
Ejemplo n.º 2
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'))
Ejemplo n.º 3
0
    def post(self):

        _ = self.get_argument
        _type = _('type')
        field = _('field')
        key = _('key')
        label = _('label')
        key = key or label

        validator = Validator()
        validator.add(
            'valid_key', lambda key: extend_service.count(key, _type) == 0)
        (validator
            .check(key, 'min', text('extend.key_missing'), 1)
            .check(key, 'valid_key', text('extend.key_exists'))
            .check(label, 'min', text('extend.label_missing'), 1)
         )

        if validator.errors:
            self.flash(validator.errors, 'error')
            self.render('admin/extend/field/add.html')

        if field == 'image':
            attributes = {
                'type': reqp.get('attributes[type]'),
                'size': {
                    'height': reqp.get('attributes[size][height]', type=int),
                    'width': reqp.get('attributes[size][width]', type=int),
                }
            }
        elif field == 'file':
            attributes = {
                'type': reqp.get('attributes[type]'),
            }
        else:
            attributes = {}

        extend_service.create_extend(_type, key, label, field, attributes)
        return self.redirect(self.reverse_url('field_page'))
Ejemplo n.º 4
0
    def post(self):

        _ = self.get_argument
        _type = _('type')
        field = _('field')
        key = _('key')
        label = _('label')
        key = key or label

        validator = Validator()
        validator.add('valid_key',
                      lambda key: extend_service.count(key, _type) == 0)
        (validator.check(key, 'min', text('extend.key_missing'), 1).check(
            key, 'valid_key',
            text('extend.key_exists')).check(label, 'min',
                                             text('extend.label_missing'), 1))

        if validator.errors:
            self.flash(validator.errors, 'error')
            self.render('admin/extend/field/add.html')

        if field == 'image':
            attributes = {
                'type': reqp.get('attributes[type]'),
                'size': {
                    'height': reqp.get('attributes[size][height]', type=int),
                    'width': reqp.get('attributes[size][width]', type=int),
                }
            }
        elif field == 'file':
            attributes = {
                'type': reqp.get('attributes[type]'),
            }
        else:
            attributes = {}

        extend_service.create_extend(_type, key, label, field, attributes)
        return self.redirect(self.reverse_url('field_page'))