Beispiel #1
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
Beispiel #2
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="quokka.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"}
        )
    }
Beispiel #3
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
 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)
Beispiel #5
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)
Beispiel #6
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))
Beispiel #7
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))
Beispiel #8
0
class ImageAdmin(MediaAdmin):
    roles_accepted = ('admin', 'editor', 'author')
    column_list = ('title', 'path', 'thumb', 'published')
    form_columns = ['title', 'slug', 'path', 'channel', 'content_format',
                    'comments_enabled', 'summary', 'published']

    def _list_thumbnail(self, context, model, name):
        if not model.path:
            return ''

        return Markup(
            '<img src="%s" width="100">' % url_for(
                'media',
                filename=form.thumbgen_filename(model.path)
            )
        )

    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="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"}
        )
    }
Beispiel #9
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
Beispiel #10
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
Beispiel #11
0
class BaseContentAdmin(ContentActions, PublishActions, ModelAdmin):
    """
    All attributes added here for example
    more info in admin source
    github.com/mrjoes/flask-admin/blob/master/flask_admin/model/base.py
    or Flask-admin documentation
    """

    roles_accepted = ('admin', 'editor', 'author')
    can_create = True
    can_edit = True
    can_delete = True

    # list_template = 'admin/model/list.html'
    # edit_template = 'admin/custom/edit.html'
    # create_template = 'admin/custom/create.html'

    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_type_formatters = {}
    # column_labels = {}
    # column_descriptions = {}
    # column_sortable_list = [] / ('name', ('user', 'user.username'))
    # column_default_sort = 'pk'
    # column_choices = {'column': ('value', 'display')}
    # column_display_pk = True

    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_excluded_columns = []
    # form = None
    # form_overrides = None

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

    form_args = {
        # 'body': {'widget': TextEditor()},
        '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 = {}
    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",
        )
    }

    # action_disallowed_list
    # page_size = 20
    # form_ajax_refs = {
    #     'main_image': {"fields": ('title',)}
    # }

    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)
Beispiel #12
0
class ContentFormat(object):
    content_format = db.StringField(choices=TEXT_FORMATS,
                                    default=get_setting_value(
                                        'DEFAULT_TEXT_FORMAT', 'html'))
 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
Beispiel #14
0
 def __init__(self, *args, **kwargs):
     template_mode = get_setting_value('ADMIN_TEMPLATE_MODE', None)
     if template_mode is not None:
         kwargs['template_mode'] = template_mode
     super(QuokkaAdmin, self).__init__(*args, **kwargs)
Beispiel #15
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