class CommentAdmin(ModelAdmin): roles_accepted = ('admin', 'editor', 'moderator') column_list = ('path', 'author_name', 'author_email', 'created_at', 'published', 'viewed_by_moderator') form_columns = [ 'path', 'author_email', 'author_name', 'content_format', 'body', 'replies', 'created_at', 'created_by', 'published', 'viewed_by_moderator' ] form_args = { 'body': { 'widget': TextEditor() }, 'viewed_by_moderator': { 'widget': widgets.HiddenInput() } } column_filters = [ ViewedByModeratorFilter( column=Comment.viewed_by_moderator, name='viewed by moderator', ) ] def get_one(self, _id): rtn = super(CommentAdmin, self).get_one(_id) if not rtn.viewed_by_moderator: rtn.viewed_by_moderator = True rtn.save() return rtn
class LinkAdmin(BaseContentAdmin): roles_accepted = ('admin', 'editor', 'writer', 'moderator') column_list = ('title', 'channel', 'slug', 'published') form_columns = ('title', 'slug', 'channel', 'link', 'content_format', 'summary', 'add_image', 'contents', 'values', 'available_at', 'available_until', 'published') form_args = {'summary': {'widget': TextEditor()}}
class CommentAdmin(ModelAdmin): roles_accepted = ('admin', 'editor') 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()}}
class LinkAdmin(BaseContentAdmin): roles_accepted = ('admin', 'editor', 'writer', 'moderator', 'author') column_list = ('title', 'channel', 'slug', 'force_redirect', 'published') form_columns = ('title', 'slug', 'channel', 'related_channels', 'link', 'show_on_channel', 'force_redirect', 'increment_visits', 'visits', 'content_format', 'summary', 'add_image', 'contents', 'values', 'tags', 'available_at', 'available_until', 'published') form_args = {'summary': {'widget': TextEditor()}}
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')} }
class PostAdmin(BaseContentAdmin): def scaffold_list_columns(self, *args, **kwargs): column_list = list( super(PostAdmin, self).scaffold_list_columns(*args, **kwargs)) column_list += ['image_file'] return column_list column_list = ( 'title', 'channel', 'published', 'image_file', ) 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', 'image_file' ] form_args = { 'body': { 'widget': TextEditor() }, 'summary': { 'widget': TextEditor() }, 'slug': { 'widget': PrepopulatedText(master='title') } } column_formatters = {'image_file': _list_thumbnail_cloudinary}
class ChannelAdmin(ModelAdmin): roles_accepted = ('admin', 'editor') column_list = ('title', 'long_slug', 'is_homepage', 'channel_type', 'created_at', 'available_at', 'published', 'view_on_site') column_filters = [ 'published', 'is_homepage', 'include_in_rss', 'show_in_menu', 'indexable' ] column_searchable_list = ('title', 'description') form_columns = [ 'title', 'slug', 'content_format', 'description', 'parent', 'is_homepage', 'roles', 'include_in_rss', 'indexable', 'show_in_menu', 'order', 'per_page', 'tags', 'sort_by', 'published', 'canonical_url', 'values', 'channel_type', 'inherit_parent', 'content_filters', 'available_at', 'available_until', 'render_content', 'redirect_url' ] column_formatters = { 'view_on_site': ModelAdmin.formatters.get('view_on_site'), 'created_at': ModelAdmin.formatters.get('datetime'), 'available_at': ModelAdmin.formatters.get('datetime') } form_subdocuments = {} form_widget_args = { 'title': { 'style': 'width: 400px' }, 'slug': { 'style': 'width: 400px' }, } form_args = { 'description': { 'widget': TextEditor() }, 'slug': { 'widget': PrepopulatedText(master='title') } } form_ajax_refs = { 'render_content': AjaxModelLoader('render_content', Content, fields=['title', 'slug']), 'parent': { 'fields': ['title', 'slug', 'long_slug'] }, }
class CourseAdmin(BaseContentAdmin): column_searchable_list = ('title', 'description', 'summary') form_args = { "description": {"widget": TextEditor()}, "slug": {"widget": PrepopulatedText(master='title')} } form_columns = ['title', 'slug', 'channel', 'related_channels', 'summary', 'description', 'published', 'unity_value', 'pre_requisites', 'duration', 'classes', 'variants', 'contents', 'show_on_channel', 'available_at', 'available_until', 'tags', 'values', 'template_type'] form_subdocuments = { 'classes': { 'form_subdocuments': { None: { 'form_columns': ( 'title', 'slug', 'description', 'start_date', 'end_date', 'weekdays', 'status', 'published' ) } } }, 'contents': { 'form_subdocuments': { None: { 'form_columns': ('content', 'caption', 'purpose', 'order'), 'form_ajax_refs': { 'content': { 'fields': ['title', 'long_slug', 'summary'] } } } } }, }
class MediaAdmin(ModelAdmin): roles_accepted = ('admin', 'editor', 'author') column_list = ('title', '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/')} }
class FileAdmin(MediaAdmin): form_args = { 'path': { 'label': 'File', 'base_path': lazy_media_path(), 'namegen': dated_path, 'permission': 0o777 }, 'summary': {'widget': TextEditor()}, 'slug': {'widget': PrepopulatedText(master='title')}, } form_ajax_refs = { 'channel': AjaxModelLoader( 'channel', Channel, fields=['title', 'slug', 'long_slug'], filters={"long_slug__startswith": "media/files"} ) }
class ProcessorAdmin(ModelAdmin): roles_accepted = ('admin', 'developer') column_list = ('identifier', 'title', 'module', 'published') form_args = { "description": { "widget": TextEditor() }, "identifier": { "widget": PrepopulatedText(master='title') } } form_columns = ('title', 'identifier', 'description', 'module', 'requires', 'image', 'link', 'config', 'pipeline', 'published') form_ajax_refs = {'image': {'fields': ['title', 'long_slug', 'summary']}} form_widget_args = { 'config': { 'cols': 40, 'rows': 10, 'style': 'width:500px;' } }
class ChannelAdmin(ContentActions, PublishActions, ModelAdmin): roles_accepted = ('admin', 'editor', 'author') column_list = ('title', 'long_slug', 'is_homepage', 'channel_type', 'created_at', 'available_at', 'published', 'view_on_site') column_filters = ['published', 'is_homepage', 'include_in_rss', 'show_in_menu', 'indexable'] column_searchable_list = ('title', 'description') form_columns = ['title', 'slug', 'content_format', 'description', 'parent', 'is_homepage', 'roles', 'include_in_rss', 'indexable', 'show_in_menu', 'order', 'per_page', 'tags', 'sort_by', 'published', 'canonical_url', 'values', 'channel_type', 'inherit_parent', 'content_filters', 'available_at', 'available_until', 'render_content', 'redirect_url'] column_formatters = { 'view_on_site': ModelAdmin.formatters.get('view_on_site'), 'created_at': ModelAdmin.formatters.get('datetime'), 'available_at': ModelAdmin.formatters.get('datetime') } form_subdocuments = {} form_widget_args = { 'title': {'style': 'width: 400px'}, 'slug': {'style': 'width: 400px'}, } form_args = { 'description': {'widget': TextEditor()}, 'slug': {'widget': PrepopulatedText(master='title')} } form_ajax_refs = { 'render_content': AjaxModelLoader('render_content', Content, fields=['title', 'slug']), 'parent': {'fields': ['title', 'slug', 'long_slug']}, } @action( 'set_homepage', _l('Set as homepage'), _l('Set as homepage?') ) def action_set_homepage(self, ids): if len(ids) > 1: flash( _("You can select only one item for this action"), 'error' ) return instance = self.get_instance(ids[0]) if instance.is_homepage: flash( _("Already homepage"), 'error' ) return current_homepage = self.model.objects.filter(is_homepage=True) try: current_homepage.update(is_homepage=False) instance.is_homepage = True instance.save() except Exception as e: current_homepage.update(is_homepage=True) flash(_('Error setting channel as homepage %s', e), 'error') else: flash(_('Channel set as homepage'))