Пример #1
0
class ImageAdmin(MediaAdmin):
    roles_accepted = ('admin', 'editor', 'author')
    column_list = ('title', 'full_path', 'thumb', 'published')
    form_columns = ['title', 'slug', 'path', 'channel', 'content_format',
                    'comments_enabled', 'summary', 'published']

    column_formatters = {
        'thumb': _list_thumbnail
    }

    form_extra_fields = {
        'path': ImageUploadField(
            'Image',
            base_path=lazy_media_path(),
            thumbnail_size=get_setting_value('MEDIA_IMAGE_THUMB_SIZE',
                                             default=(200, 200, True)),
            endpoint="flaskpress.core.media",
            namegen=dated_path,
            permission=0o777,
            allowed_extensions="MEDIA_IMAGE_ALLOWED_EXTENSIONS",
        )
    }

    form_ajax_refs = {
        'channel': AjaxModelLoader(
            'channel',
            Channel,
            fields=['title', 'slug', 'long_slug'],
            filters={"long_slug__startswith": "media/image"}
        )
    }
Пример #2
0
 def shortener(self):
     if not self.__shortener:
         shortener_config = get_setting_value('SHORTENER_SETTINGS',
                                              {}).copy()
         shortener_name = shortener_config.pop('name')
         self.__shortener = Shortener(shortener_name, **shortener_config)
     return self.__shortener
Пример #3
0
 def register(self, model, view=None, *args, **kwargs):
     _view = view or ModelAdmin
     admin_view_exclude = get_setting_value('ADMIN_VIEW_EXCLUDE', [])
     identifier = '.'.join((model.__module__, model.__name__))
     if (identifier not in admin_view_exclude) and (identifier
                                                    not in self.registered):
         self.add_view(_view(model, *args, **kwargs))
         self.registered.append(identifier)
Пример #4
0
    def populate_shorter_url(self):
        if not self.published or not get_setting_value('SHORTENER_ENABLED'):
            return

        url = self.get_http_url()
        if not self.shortened_url or url != self.shortened_url.original:
            shortener = ShorterURL()
            self.shortened_url = ShortenedURL(original=url,
                                              short=shortener.short(url))
Пример #5
0
 def get_list_columns(self):
     column_list = super(BaseContentAdmin, self).get_list_columns()
     if get_setting_value('SHORTENER_ENABLED'):
         column_list += [('short_url', 'Short URL')]
     return column_list
Пример #6
0
class BaseContentAdmin(ContentActions, PublishActions, ModelAdmin):
    roles_accepted = ('admin', 'editor', 'author')
    can_create = True
    can_edit = True
    can_delete = True

    column_list = ('title', 'slug', 'channel', 'published', 'created_at',
                   'available_at', 'view_on_site')

    column_formatters = {
        'view_on_site': ModelAdmin.formatters.get('view_on_site'),
        'created_at': ModelAdmin.formatters.get('datetime'),
        'available_at': ModelAdmin.formatters.get('datetime'),
        'short_url': ModelAdmin.formatters.get('link')
    }

    column_filters = [
        'published', 'title', 'summary', 'created_at', 'available_at'
    ]
    column_searchable_list = ('title', 'summary')

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

    form_widget_args = {
        'summary': {
            'style': 'width: 400px; height: 100px;'
        },
        'title': {
            'style': 'width: 400px'
        },
        'slug': {
            'style': 'width: 400px'
        },
    }

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

    form_subdocuments = {
        'contents': {
            'form_subdocuments': {
                None: {
                    'form_columns':
                    ('content', 'caption', 'purpose', 'order', 'thumb'),
                    'form_ajax_refs': {
                        'content': {
                            'fields': ['title', 'long_slug', 'summary']
                        }
                    },
                    'form_extra_fields': {
                        'thumb': ThumbField('thumb', endpoint="media")
                    }
                }
            }
        },
    }

    form_extra_fields = {
        'add_image':
        ContentImageField(
            'Add new image',
            base_path=lazy_media_path(),
            thumbnail_size=get_setting_value('MEDIA_IMAGE_THUMB_SIZE',
                                             default=(100, 100, True)),
            endpoint="media",
            namegen=dated_path,
            permission=0o777,
            allowed_extensions="MEDIA_IMAGE_ALLOWED_EXTENSIONS",
        )
    }

    def get_list_columns(self):
        column_list = super(BaseContentAdmin, self).get_list_columns()
        if get_setting_value('SHORTENER_ENABLED'):
            column_list += [('short_url', 'Short URL')]
        return column_list

    def after_model_change(self, form, model, is_created):
        if not hasattr(form, 'add_image'):
            return

        form.add_image.save_contents(model)
Пример #7
0
 def get_canonical_url(self):
     return "/{0}.{1}".format(
         self.path, get_setting_value(
             'CONTENT_EXTENSION',
             'html')) if not self.path.startswith("/") else self.path
Пример #8
0
class ContentFormat(object):
    content_format = db.StringField(choices=TEXT_FORMATS,
                                    default=get_setting_value(
                                        'DEFAULT_TEXT_FORMAT', 'html'))