Exemplo n.º 1
0
class BaseFormat(object):
    identifier = None
    edit_form = BaseEditForm
    form_rules = [
        rules.FieldSet(('title', 'summary')),
        rules.Field('content'),
        rules.FieldSet(('category', 'authors', 'tags')),
        rules.FieldSet(('date', )),
        rules.FieldSet(('slug', )),
        rules.Field('published')
    ]

    def get_edit_form(self, obj):
        return self.edit_form(get_form_data(), **obj)

    def get_identifier(self):
        return self.identifier or self.__class__.__name__

    def get_form_rules(self):
        if self.form_rules is not None:
            self.form_rules.append(
                rules.Field('csrf_token',
                            render_field='quokka_macros.render_hidden_field'))
        return self.form_rules

    def before_save(self, form, model, is_created):
        """optional"""

    def after_save(self, form, model, is_created):
        """optional"""

    def extra_js(self):
        return []
Exemplo n.º 2
0
class AdminBlocksView(AdminContentView):
    """Only blocks"""
    base_query = {'content_type': 'block'}
    create_defaults = {'comments': False}
    column_list = ('title', 'date', 'modified', 'language', 'published')
    column_sortable_list = ('title', 'date', 'modified', 'language',
                            'published')
    quokka_form_create_rules = [
        rules.FieldSet(('title', 'summary')),
        rules.FieldSet(('content_format', )), rules.csrf_token
    ]
    quokka_form_edit_rules = [
        rules.FieldSet(('title', 'summary')),
        rules.Field('content'),
        # rules.FieldSet(('category', 'authors', 'tags')),
        rules.FieldSet(('date', )),
        rules.FieldSet(('slug', )),
        rules.Field('published'),
        rules.Field('comments'),
        rules.Field('block_items'),
        rules.Field('custom_vars'),
        rules.csrf_token
    ]

    def get_existent_record(self, form, model):
        return current_app.db.get(
            'index', {
                'slug': model['slug'],
                'category': model['category'],
                'content_type': 'block'
            })

    def before_save(self, form, model, is_created):
        if 'block_items' in model:
            model['block_items'].sort(key=lambda x: x['order'])
            for i, item in enumerate(model['block_items']):

                item.pop('csrf_token', None)
                item['order'] = i

                for ref in ['author', 'category', 'tag', 'url']:
                    if item['item'].startswith(f"{ref}::"):
                        item[f"{ref}_id"] = item['item'].split('::')[-1]
                    else:
                        item[f"{ref}_id"] = None

                content_types = ('article::', 'page::', 'block::')
                if item['item'].startswith(content_types):
                    full_slug = item['item'].split('::')[-1]
                    slug = full_slug.split('/')[-1]
                    category = full_slug.rpartition('/')[0]
                    args = {'slug': slug}
                    if category:
                        args['category'] = category

                    content = current_app.db.get('index', args)
                    if content:
                        item['index_id'] = content['_id']
                else:
                    item['index_id'] = None
Exemplo n.º 3
0
class BaseFormat(object):
    identifier = None
    edit_form = BaseEditForm
    form_edit_rules = [
        rules.FieldSet(('title', 'summary')),
        rules.Field('content'),
        rules.FieldSet(('category', 'authors', 'tags')),
        rules.FieldSet(('date', )),
        rules.FieldSet(('slug', )),
        rules.Field('published'),
        rules.Field('comments'),
        rules.Field('custom_vars'), rules.csrf_token
    ]

    def get_edit_form(self, obj):
        return self.edit_form(get_form_data(), **obj)

    def get_edit_template(self, obj):
        return 'admin/quokka/edit.html'

    def get_identifier(self):
        return self.identifier or self.__class__.__name__

    def get_form_edit_rules(self, obj):
        return self.form_edit_rules

    def before_save(self, form, model, is_created):
        """optional"""

    def after_save(self, form, model, is_created):
        """optional"""

    def extra_js(self):
        return []

    def render_content(self, obj):

        if not isinstance(obj, dict):
            content = obj.data
        else:
            content = obj

        if 'content' not in content:
            content = app.db.get_with_content(_id=content['_id'])

        return content['content']

    def render(self, obj):
        # TODO: PRE-RENDER
        rv = self.render_content(obj)
        # TODO: POST-RENDER
        return rv
Exemplo n.º 4
0
class AdminPagesView(AdminContentView):
    """Only pages"""
    base_query = {'content_type': 'page'}
    create_defaults = {'comments': False}
    quokka_form_create_rules = [
        rules.FieldSet(('title', 'summary')),
        rules.FieldSet(('content_format', )), rules.csrf_token
    ]
    quokka_form_edit_rules = [
        rules.FieldSet(('title', 'summary')),
        rules.Field('content'),
        # rules.FieldSet(('category', 'authors', 'tags')),
        rules.FieldSet(('date', )),
        rules.FieldSet(('slug', )),
        rules.Field('published'),
        rules.Field('comments'),
        rules.csrf_token
    ]
Exemplo n.º 5
0
class MarkdownFormat(BaseFormat):
    edit_form = MarkdownEditForm
    form_rules = [
        rules.FieldSet(('title', 'summary')),
        rules.Field('content'),
        rules.FieldSet(('category', 'authors', 'tags')),
        rules.FieldSet(('date', 'language')),
        rules.FieldSet(('slug', 'content_type', 'content_format')),
        rules.Field('published')
    ]

    def before_save(self, form, model, is_created):
        print('before save')

    def after_save(self, form, model, is_created):
        print('after save')

    def extra_js(self):
        return []
Exemplo n.º 6
0
 def get_form_rules(self):
     if self.form_rules is not None:
         self.form_rules.append(
             rules.Field('csrf_token',
                         render_field='quokka_macros.render_hidden_field'))
     return self.form_rules