<commit_before>from __future__ import unicode_literals
from builtins import object
from django import http
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from crispy_forms import layout
from django import forms
from django_cradmin.apps.cradmin_temporaryfileuploadstore.crispylayouts import BulkFileUploadSubmit
from django_cradmin.apps.cradmin_temporaryfileuploadstore.models import TemporaryFileCollection
from django_cradmin.apps.cradmin_temporaryfileuploadstore.widgets import BulkFileUploadWidget
from django_cradmin.templatetags.cradmin_icon_tags import cradmin_icon

from django_cradmin.viewhelpers import objecttable
from django_cradmin.viewhelpers import create
from django_cradmin.viewhelpers import update
from django_cradmin.viewhelpers import delete
from django_cradmin.viewhelpers import formbase
from django_cradmin import crapp
from django_cradmin.apps.cradmin_imagearchive.models import ArchiveImage
from django_cradmin.widgets import filewidgets


class NameColumn(objecttable.MultiActionColumn):
    modelfield = 'name'

    def get_buttons(self, obj):
        return [
            objecttable.Button(
                label=_('Edit'),
                url=self.reverse_appurl('edit', args=[obj.id])),
            objecttable.Button(
                label=_('Delete'),
                url=self.reverse_appurl('delete', args=[obj.id]),
                buttonclass="btn btn-danger btn-sm"),
        ]


class NameSelectColumn(objecttable.UseThisActionColumn):
    modelfield = 'name'

    def get_buttons(self, obj):
        return [
            objecttable.UseThisButton(
                view=self.view,
                label=_('Use this'),
                obj=obj)
        ]


class DescriptionColumn(objecttable.TruncatecharsPlainTextColumn):
    modelfield = 'description'
    maxlength = 80
    allcells_css_classes = ['hidden-xs']


class ImageColumn(objecttable.ImagePreviewColumn):
    modelfield = 'image'
    preview_width = 100
    preview_height = 70
    column_width = '100px'

    def get_header(self):
        return _('Preview')


class ArchiveImagesQuerySetForRoleMixin(object):
    """
    Used by listing, update and delete view to ensure
    that only images that the current role has access to
    is available.
    """
    def get_queryset_for_role(self, role):
        return ArchiveImage.objects.filter_owned_by_role(role)


class ArchiveImagesListView(ArchiveImagesQuerySetForRoleMixin, objecttable.ObjectTableView):
    model = ArchiveImage
    columns = [
        ImageColumn,
        NameColumn,
        DescriptionColumn,
    ]
    searchfields = ['name', 'description', 'file_extension']

    def get_buttons(self):
        app = self.request.cradmin_app
        return [
            objecttable.Button(_('Add image'),
                               url=app.reverse_appurl('create'),
                               buttonclass='btn btn-primary'),
            objecttable.Button(_('Bulk upload'),
                               url=app.reverse_appurl('bulkadd'),
                               buttonclass='btn btn-default'),
        ]


class ArchiveImagesSingleSelectView(ArchiveImagesQuerySetForRoleMixin, objecttable.ObjectTableView):
    model = ArchiveImage
    columns = [
        ImageColumn,
        NameSelectColumn,
        'description'
    ]
    searchfields = ['name', 'description', 'file_extension']
    hide_menu = True
    # paginate_by = 10

    def make_foreignkey_preview_for(self, obj):<commit_msg>imagearchive: Hide headers in the listing.<commit_after>from __future__ import unicode_literals
from builtins import object
from django import http
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from crispy_forms import layout
from django import forms
from django_cradmin.apps.cradmin_temporaryfileuploadstore.crispylayouts import BulkFileUploadSubmit
from django_cradmin.apps.cradmin_temporaryfileuploadstore.models import TemporaryFileCollection
from django_cradmin.apps.cradmin_temporaryfileuploadstore.widgets import BulkFileUploadWidget
from django_cradmin.templatetags.cradmin_icon_tags import cradmin_icon

from django_cradmin.viewhelpers import objecttable
from django_cradmin.viewhelpers import create
from django_cradmin.viewhelpers import update
from django_cradmin.viewhelpers import delete
from django_cradmin.viewhelpers import formbase
from django_cradmin import crapp
from django_cradmin.apps.cradmin_imagearchive.models import ArchiveImage
from django_cradmin.widgets import filewidgets


class NameColumn(objecttable.MultiActionColumn):
    modelfield = 'name'

    def get_buttons(self, obj):
        return [
            objecttable.Button(
                label=_('Edit'),
                url=self.reverse_appurl('edit', args=[obj.id])),
            objecttable.Button(
                label=_('Delete'),
                url=self.reverse_appurl('delete', args=[obj.id]),
                buttonclass="btn btn-danger btn-sm"),
        ]


class NameSelectColumn(objecttable.UseThisActionColumn):
    modelfield = 'name'

    def get_buttons(self, obj):
        return [
            objecttable.UseThisButton(
                view=self.view,
                label=_('Use this'),
                obj=obj)
        ]


class DescriptionColumn(objecttable.TruncatecharsPlainTextColumn):
    modelfield = 'description'
    maxlength = 80
    allcells_css_classes = ['hidden-xs']


class ImageColumn(objecttable.ImagePreviewColumn):
    modelfield = 'image'
    preview_width = 100
    preview_height = 70
    column_width = '100px'

    def get_header(self):
        return _('Preview')


class ArchiveImagesQuerySetForRoleMixin(object):
    """
    Used by listing, update and delete view to ensure
    that only images that the current role has access to
    is available.
    """
    def get_queryset_for_role(self, role):
        return ArchiveImage.objects.filter_owned_by_role(role)


class ArchiveImagesListView(ArchiveImagesQuerySetForRoleMixin, objecttable.ObjectTableView):
    model = ArchiveImage
    columns = [
        ImageColumn,
        NameColumn,
        DescriptionColumn,
    ]
    searchfields = ['name', 'description', 'file_extension']
    hide_column_headers = True

    def get_buttons(self):
        app = self.request.cradmin_app
        return [
            objecttable.Button(_('Add image'),
                               url=app.reverse_appurl('create'),
                               buttonclass='btn btn-primary'),
            objecttable.Button(_('Bulk upload'),
                               url=app.reverse_appurl('bulkadd'),
                               buttonclass='btn btn-default'),
        ]


class ArchiveImagesSingleSelectView(ArchiveImagesQuerySetForRoleMixin, objecttable.ObjectTableView):
    model = ArchiveImage
    columns = [
        ImageColumn,
        NameSelectColumn,
        'description'
    ]
    searchfields = ['name', 'description', 'file_extension']
    hide_menu = True
    # paginate_by = 10

    def make_foreignkey_preview_for(self, obj):
{'fraction_non_alphanumeric': 0.0758903335217637, 'fraction_numerical': 0.0033917467495760316, 'mean_word_length': 3.0766129032258065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1083859', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1916, 'n_words': 420}