예제 #1
0
class MediaAdmin(ModelAdmin):
    roles_accepted = ('admin', 'editor', 'author')
    column_list = ('title', 'full_path', 'published')
    form_columns = ['title', 'slug', 'path', 'channel', 'content_format',
                    'summary', 'comments_enabled', 'published']

    form_overrides = {
        'path': form.FileUploadField
    }

    form_args = {
        'summary': {'widget': TextEditor()},
        'slug': {'widget': PrepopulatedText(master='title')},
    }

    form_widget_args = {
        'channel': {'data-placeholder': _l('media/')}
    }
예제 #2
0
    form_columns = ('name', 'email', 'roles', 'active', 'newpassword',
                    'confirmed_at', 'last_login_at', 'current_login_at',
                    'last_login_ip', 'current_login_ip', 'login_count',
                    'tagline', 'gravatar_email', 'use_avatar_from',
                    'avatar_file_path', 'avatar_url', 'bio', 'links', 'values')

    form_extra_fields = {"newpassword": StringField(widget=PasswordInput())}

    def on_model_change(self, form, model, is_created):
        if model.newpassword:
            setpwd = model.newpassword
            del model.newpassword
            model.set_password(setpwd, save=True)


class RoleAdmin(ModelAdmin):
    roles_accepted = ('admin', )
    column_list = ('name', 'description', 'values')


class ConnectionAdmin(ModelAdmin):
    roles_accepted = ('admin', )


admin.register(User, UserAdmin, category=_l("Accounts"), name=_l("User"))
admin.register(Role, RoleAdmin, category=_l("Accounts"), name=_l("Roles"))
admin.register(Connection,
               ConnectionAdmin,
               category=_l("Accounts"),
               name=_l("Connection"))
예제 #3
0
def configure_admin(app, admin):  # noqa

    custom_index = app.config.get('ADMIN_INDEX_VIEW')
    if custom_index:
        admin.index_view = import_string(custom_index)()
        if isinstance(admin._views[0], BaseIndexView):
            del admin._views[0]
        admin._views.insert(0, admin.index_view)

    admin_config = app.config.get('ADMIN', {
        'name': 'Flaskpress Admin',
        'url': '/admin'
    })

    for k, v in list(admin_config.items()):
        setattr(admin, k, v)

    for entry in app.config.get('FILE_ADMIN', []):
        try:
            admin.add_view(
                FileAdmin(
                    entry['path'],
                    entry['url'],
                    name=_l(entry['name']),
                    category=_l(entry['category']),
                    endpoint=entry['endpoint'],
                    roles_accepted=entry.get('roles_accepted'),
                    editable_extensions=entry.get('editable_extensions')))
        except Exception as e:
            app.logger.info(e)

    for k, theme in app.theme_manager.themes.items():
        try:

            if k == app.config.get('DEFAULT_THEME'):
                suffix = "(Site theme)"
            elif k == app.config.get('ADMIN_THEME'):
                suffix = "(Admin theme)"
            else:
                suffix = "Theme"

            admin.add_view(
                FileAdmin(theme.static_path,
                          "/_themes/{0}/".format(theme.identifier),
                          name="{0}: {1} static files".format(
                              suffix, theme.identifier),
                          category=_l("Files"),
                          endpoint="{0}_static_files".format(theme.identifier),
                          roles_accepted=('admin', "editor"),
                          editable_extensions=app.config.get(
                              'DEFAULT_EDITABLE_EXTENSIONS')))
            admin.add_view(
                FileAdmin(
                    theme.templates_path,
                    "/theme_template_files/{0}/".format(theme.identifier),
                    name="{0}: {1} template files".format(
                        suffix, theme.identifier),
                    category=_l("Files"),
                    endpoint="{0}_template_files".format(theme.identifier),
                    roles_accepted=('admin', "editor"),
                    editable_extensions=app.config.get(
                        'DEFAULT_EDITABLE_EXTENSIONS')))
        except Exception as e:
            app.logger.warning('Error registering %s folder to file admin %s' %
                               (theme.identifier, e))

    admin.add_view(InspectorView(category=_l("Settings"),
                                 name=_l("Inspector")))

    extra_views = app.config.get('ADMIN_EXTRA_VIEWS', [])
    for view in extra_views:
        admin.add_view(
            import_string(view['module'])(category=_l(view.get('category')),
                                          name=_l(view.get('name'))))

    admin.register(Link, LinkAdmin, category=_l("Content"), name=_l("Link"))
    admin.register(Config,
                   ConfigAdmin,
                   category=_l("Settings"),
                   name=_l("Config"))
    admin.register(SubContentPurpose,
                   SubContentPurposeAdmin,
                   category=_l("Settings"),
                   name=_l("Sub content purposes"))
    admin.register(ChannelType,
                   ChannelTypeAdmin,
                   category=_l("Settings"),
                   name=_l("Channel type"))
    admin.register(ContentTemplateType,
                   ContentTemplateTypeAdmin,
                   category=_l("Settings"),
                   name=_l("Template type"))
    admin.register(Channel,
                   ChannelAdmin,
                   category=_l("Content"),
                   name=_l("Channel"))

    # avoid registering twice
    if admin.app is None:
        admin.init_app(app)

    return admin
예제 #4
0
# coding : utf -8

from flaskpress import admin
from flaskpress.core.admin.models import BaseContentAdmin
from flaskpress.core.widgets import TextEditor, PrepopulatedText
from flaskpress.modules.posts.models import Post
from flaskpress.utils.translation import _l


class PostAdmin(BaseContentAdmin):

    column_searchable_list = ('title', 'body', 'summary')

    form_columns = ['title', 'slug', 'channel', 'related_channels', 'summary',
                    'content_format', 'body', 'authors',
                    'comments_enabled', 'published', 'add_image', 'contents',
                    'show_on_channel', 'available_at', 'available_until',
                    'tags', 'values', 'template_type', 'license']

    form_args = {
        'body': {'widget': TextEditor()},
        'slug': {'widget': PrepopulatedText(master='title')}
    }


admin.register(Post, PostAdmin, category=_l("Content"), name=_l("Post"))
예제 #5
0
# coding : utf -8


from flaskpress import admin
from flaskpress.core.admin.models import ModelAdmin
from flaskpress.core.widgets import TextEditor
from .models import Comment
from flaskpress.utils.translation import _l


class CommentAdmin(ModelAdmin):
    roles_accepted = ('admin', 'editor', 'moderator')
    column_list = ('path', 'author_name', 'author_email',
                   'created_at', 'published')
    form_columns = ['path', 'author_email', 'author_name',
                    'content_format', 'body', 'replies',
                    'created_at', 'created_by', 'published']
    form_args = {
        'body': {'widget': TextEditor()}
    }


admin.register(Comment, CommentAdmin, category=_l('Content'),
               name=_l("Comments"))
예제 #6
0
            'channel',
            Channel,
            fields=['title', 'slug', 'long_slug'],
            filters={"long_slug__startswith": "media/image"}
        )
    }


class MediaGalleryAdmin(BaseContentAdmin):
    roles_accepted = ('admin', 'editor', 'author')
    column_searchable_list = ('title', 'body', 'summary')

    form_columns = ['title', 'slug', 'channel', 'related_channels', 'summary',
                    'content_format', 'body',
                    'comments_enabled', 'published', 'add_image', 'contents',
                    'show_on_channel', 'available_at', 'available_until',
                    'tags', 'values', 'template_type']

    form_args = {
        'body': {'widget': TextEditor()},
        'slug': {'widget': PrepopulatedText(master='title')}
    }


admin.register(File, FileAdmin, category=_l('Media'), name=_l("File"))
admin.register(Video, VideoAdmin, category=_l('Media'), name=_l("Video"))
admin.register(Audio, AudioAdmin, category=_l('Media'), name=_l("Audio"))
admin.register(Image, ImageAdmin, category=_l('Media'), name=_l("Image"))
admin.register(MediaGallery, MediaGalleryAdmin,
               category=_l('Content'), name=_l("Media Gallery"))