From d608620b697ea8093886b8b867334b890093d8cb Mon Sep 17 00:00:00 2001 From: erichhasl Date: Wed, 5 Jul 2017 18:58:40 +0200 Subject: [PATCH 1/3] add thumbnail in material list view --- jdav_web/material/admin.py | 3 +- .../material/locale/de/LC_MESSAGES/django.po | 42 ++++++++++--------- jdav_web/material/models.py | 8 ++++ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/jdav_web/material/admin.py b/jdav_web/material/admin.py index 0753758..8f5ae52 100644 --- a/jdav_web/material/admin.py +++ b/jdav_web/material/admin.py @@ -42,7 +42,8 @@ class NotTooOldFilter(SimpleListFilter): class MaterialAdmin(admin.ModelAdmin): """Edit view of a MaterialPart""" - list_display = ('name', 'description', 'quantity_real', 'buy_date', 'lifetime', 'not_too_old', 'photo') + list_display = ('name', 'description', 'quantity_real', 'buy_date', + 'lifetime', 'not_too_old', 'admin_thumbnail') inlines = [OwnershipInline] list_filter = (NotTooOldFilter,) diff --git a/jdav_web/material/locale/de/LC_MESSAGES/django.po b/jdav_web/material/locale/de/LC_MESSAGES/django.po index 5291c10..9e82458 100644 --- a/jdav_web/material/locale/de/LC_MESSAGES/django.po +++ b/jdav_web/material/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-07-05 10:06+0000\n" +"POT-Creation-Date: 2017-07-05 18:57+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,74 +18,78 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: material/admin.py:25 +#: admin.py:25 msgid "Age" msgstr "Alter" -#: material/admin.py:30 +#: admin.py:30 msgid "Not too old" msgstr "Nicht zu alt" -#: material/admin.py:31 +#: admin.py:31 msgid "Too old" msgstr "Zu alt" -#: material/apps.py:7 +#: apps.py:7 msgid "material" msgstr "Material" -#: material/models.py:17 +#: models.py:17 msgid "name" msgstr "Name" -#: material/models.py:18 +#: models.py:18 msgid "description" msgstr "Beschreibung" -#: material/models.py:19 +#: models.py:19 msgid "quantity" msgstr "Anzahl" -#: material/models.py:20 +#: models.py:20 msgid "purchase date" msgstr "Kaufdatum" -#: material/models.py:21 +#: models.py:21 msgid "lifetime (years)" msgstr "Lebenszeit (Jahre)" -#: material/models.py:22 +#: models.py:22 msgid "photo" msgstr "Bild" -#: material/models.py:33 +#: models.py:33 msgid "Quantity" msgstr "Anzahl" -#: material/models.py:43 +#: models.py:40 +msgid "Thumbnail" +msgstr "Bild" + +#: models.py:51 msgid "Not too old?" msgstr "Nicht zu alt?" -#: material/models.py:46 +#: models.py:54 msgid "material part" msgstr "Materialteil" -#: material/models.py:47 +#: models.py:55 msgid "material parts" msgstr "Materialteile" -#: material/models.py:53 +#: models.py:61 msgid "owner" msgstr "Besitzer" -#: material/models.py:54 +#: models.py:62 msgid "count" msgstr "Anzahl" -#: material/models.py:61 +#: models.py:69 msgid "ownership" msgstr "Besitzer" -#: material/models.py:62 +#: models.py:70 msgid "ownerships" msgstr "Verantwortliche" diff --git a/jdav_web/material/models.py b/jdav_web/material/models.py index e9ba04f..f5cea7b 100644 --- a/jdav_web/material/models.py +++ b/jdav_web/material/models.py @@ -32,6 +32,14 @@ class MaterialPart(models.Model): quantity_real.admin_order_field = 'quantity' quantity_real.short_description = _('Quantity') + def admin_thumbnail(self): + if self.photo: + return ''.format(self.photo.url) + else: + return 'kein Bild' + admin_thumbnail.short_description = _('Thumbnail') + admin_thumbnail.allow_tags = True + def not_too_old(self): """Returns wether the part should be replaced cause of age""" buy_time = timezone.make_aware(datetime.combine(self.buy_date, From 9a9b4fd08e0998e694a742c114b211877418ebd5 Mon Sep 17 00:00:00 2001 From: erichhasl Date: Wed, 5 Jul 2017 19:11:37 +0200 Subject: [PATCH 2/3] add ownership overview in list view --- jdav_web/material/admin.py | 3 ++- .../material/locale/de/LC_MESSAGES/django.po | 20 +++++++++++-------- jdav_web/material/models.py | 8 ++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/jdav_web/material/admin.py b/jdav_web/material/admin.py index 8f5ae52..c6228b4 100644 --- a/jdav_web/material/admin.py +++ b/jdav_web/material/admin.py @@ -42,7 +42,8 @@ class NotTooOldFilter(SimpleListFilter): class MaterialAdmin(admin.ModelAdmin): """Edit view of a MaterialPart""" - list_display = ('name', 'description', 'quantity_real', 'buy_date', + list_display = ('name', 'description', 'quantity_real', + 'ownership_overview', 'buy_date', 'lifetime', 'not_too_old', 'admin_thumbnail') inlines = [OwnershipInline] list_filter = (NotTooOldFilter,) diff --git a/jdav_web/material/locale/de/LC_MESSAGES/django.po b/jdav_web/material/locale/de/LC_MESSAGES/django.po index 9e82458..211e548 100644 --- a/jdav_web/material/locale/de/LC_MESSAGES/django.po +++ b/jdav_web/material/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-07-05 18:57+0200\n" +"POT-Creation-Date: 2017-07-05 19:07+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -66,30 +66,34 @@ msgstr "Anzahl" msgid "Thumbnail" msgstr "Bild" -#: models.py:51 +#: models.py:49 +msgid "Owners" +msgstr "Verantwortliche" + +#: models.py:59 msgid "Not too old?" msgstr "Nicht zu alt?" -#: models.py:54 +#: models.py:62 msgid "material part" msgstr "Materialteil" -#: models.py:55 +#: models.py:63 msgid "material parts" msgstr "Materialteile" -#: models.py:61 +#: models.py:69 msgid "owner" msgstr "Besitzer" -#: models.py:62 +#: models.py:70 msgid "count" msgstr "Anzahl" -#: models.py:69 +#: models.py:77 msgid "ownership" msgstr "Besitzer" -#: models.py:70 +#: models.py:78 msgid "ownerships" msgstr "Verantwortliche" diff --git a/jdav_web/material/models.py b/jdav_web/material/models.py index f5cea7b..62ed8d3 100644 --- a/jdav_web/material/models.py +++ b/jdav_web/material/models.py @@ -40,6 +40,14 @@ class MaterialPart(models.Model): admin_thumbnail.short_description = _('Thumbnail') admin_thumbnail.allow_tags = True + def ownership_overview(self): + summary = '' + for owner in self.ownership_set.all(): + summary += '

{}: {}

'.format(str(owner.owner), owner.count) + return summary + ownership_overview.allow_tags = True + ownership_overview.short_description = _('Owners') + def not_too_old(self): """Returns wether the part should be replaced cause of age""" buy_time = timezone.make_aware(datetime.combine(self.buy_date, From eed8f993161cf3549ca11e47383e751b371dd118 Mon Sep 17 00:00:00 2001 From: erichhasl Date: Wed, 5 Jul 2017 19:34:49 +0200 Subject: [PATCH 3/3] replace stackedinlines with tabularinlines --- jdav_web/mailer/admin.py | 5 ++++- jdav_web/material/admin.py | 30 ++++++++++++++++-------------- jdav_web/members/admin.py | 10 ++++++++-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/jdav_web/mailer/admin.py b/jdav_web/mailer/admin.py index 78b5076..d84a9a2 100644 --- a/jdav_web/mailer/admin.py +++ b/jdav_web/mailer/admin.py @@ -10,7 +10,7 @@ from .models import Message, Attachment, MessageForm from .mailutils import NOT_SENT, PARTLY_SENT -class AttachmentInline(admin.StackedInline): +class AttachmentInline(admin.TabularInline): model = Attachment extra = 0 @@ -52,6 +52,9 @@ class MessageAdmin(admin.ModelAdmin): submit_message(obj, request) return super(MessageAdmin, self).response_add(request, obj) + class Media: + css = {'all': ('admin/css/tabular_hide_original.css',)} + def submit_message(msg, request): success = msg.submit() diff --git a/jdav_web/material/admin.py b/jdav_web/material/admin.py index c6228b4..31198a1 100644 --- a/jdav_web/material/admin.py +++ b/jdav_web/material/admin.py @@ -9,7 +9,7 @@ from easy_select2 import apply_select2 # Register your models here. -class OwnershipInline(admin.StackedInline): +class OwnershipInline(admin.TabularInline): """ This shows the ownership selection directly in the MaterialPart edit view @@ -22,21 +22,20 @@ class OwnershipInline(admin.StackedInline): class NotTooOldFilter(SimpleListFilter): - title = _('Age') - parameter_name = 'age' + title = _('Age') + parameter_name = 'age' - def lookups(self, request, model_admin): - return ( - ('too_old', _('Not too old')), - ('not_too_old', _('Too old')), - ) - - def queryset(self, request, queryset): - if self.value() == 'too_old': - return queryset.filter(pk__in=[x.pk for x in queryset.all() if x.not_too_old()]) - if self.value() == 'not_too_old': - return queryset.filter(pk__in=[x.pk for x in queryset.all() if not x.not_too_old()]) + def lookups(self, request, model_admin): + return ( + ('too_old', _('Not too old')), + ('not_too_old', _('Too old')), + ) + def queryset(self, request, queryset): + if self.value() == 'too_old': + return queryset.filter(pk__in=[x.pk for x in queryset.all() if x.not_too_old()]) + if self.value() == 'not_too_old': + return queryset.filter(pk__in=[x.pk for x in queryset.all() if not x.not_too_old()]) class MaterialAdmin(admin.ModelAdmin): @@ -48,5 +47,8 @@ class MaterialAdmin(admin.ModelAdmin): inlines = [OwnershipInline] list_filter = (NotTooOldFilter,) + class Media: + css = {'all': ('admin/css/tabular_hide_original.css',)} + admin.site.register(MaterialPart, MaterialAdmin) diff --git a/jdav_web/members/admin.py b/jdav_web/members/admin.py index 22a32ad..bd78be1 100644 --- a/jdav_web/members/admin.py +++ b/jdav_web/members/admin.py @@ -71,7 +71,7 @@ class MemberListAdminForm(forms.ModelForm): #self.fields['add_member'].queryset = Member.objects.filter(prename__startswith='F') -class MemberOnListInline(admin.StackedInline): +class MemberOnListInline(admin.TabularInline): model = MemberOnList extra = 0 formfield_overrides = { @@ -92,6 +92,9 @@ class MemberListAdmin(admin.ModelAdmin): ForeignKey: {'widget': apply_select2(forms.Select)} } + class Media: + css = {'all': ('admin/css/tabular_hide_original.css',)} + def __init__(self, *args, **kwargs): super(MemberListAdmin, self).__init__(*args, **kwargs) @@ -311,7 +314,7 @@ class KlettertreffAttendeeInlineForm(forms.ModelForm): self.fields['member'].queryset = Member.objects.filter(group__name='J1') """ -class KlettertreffAttendeeInline(admin.StackedInline): +class KlettertreffAttendeeInline(admin.TabularInline): model = KlettertreffAttendee form = KlettertreffAttendeeInlineForm extra = 0 @@ -351,6 +354,9 @@ class KlettertreffAdmin(admin.ModelAdmin): ForeignKey: {'widget': apply_select2(forms.Select)} } + class Media: + css = {'all': ('admin/css/tabular_hide_original.css',)} + admin.site.register(Member, MemberAdmin) admin.site.register(Group, GroupAdmin)