Merge pull request #72 from Schlabonski/material-beautify

beautify material and inlines
v1-0-stable
Christian Merten 9 years ago committed by GitHub
commit cafd0d2bde

@ -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()

@ -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,29 +22,33 @@ 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):
"""Edit view of a MaterialPart"""
list_display = ('name', 'description', 'quantity_real', 'buy_date', 'lifetime', 'not_too_old', 'photo')
list_display = ('name', 'description', 'quantity_real',
'ownership_overview', 'buy_date',
'lifetime', 'not_too_old', 'admin_thumbnail')
inlines = [OwnershipInline]
list_filter = (NotTooOldFilter,)
class Media:
css = {'all': ('admin/css/tabular_hide_original.css',)}
admin.site.register(MaterialPart, MaterialAdmin)

@ -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 19:07+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,74 +18,82 @@ 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:49
msgid "Owners"
msgstr "Verantwortliche"
#: models.py:59
msgid "Not too old?"
msgstr "Nicht zu alt?"
#: material/models.py:46
#: models.py:62
msgid "material part"
msgstr "Materialteil"
#: material/models.py:47
#: models.py:63
msgid "material parts"
msgstr "Materialteile"
#: material/models.py:53
#: models.py:69
msgid "owner"
msgstr "Besitzer"
#: material/models.py:54
#: models.py:70
msgid "count"
msgstr "Anzahl"
#: material/models.py:61
#: models.py:77
msgid "ownership"
msgstr "Besitzer"
#: material/models.py:62
#: models.py:78
msgid "ownerships"
msgstr "Verantwortliche"

@ -32,6 +32,22 @@ class MaterialPart(models.Model):
quantity_real.admin_order_field = 'quantity'
quantity_real.short_description = _('Quantity')
def admin_thumbnail(self):
if self.photo:
return '<a href="{0}"><img src="{0}" height="40"></a>'.format(self.photo.url)
else:
return '<i>kein Bild</i>'
admin_thumbnail.short_description = _('Thumbnail')
admin_thumbnail.allow_tags = True
def ownership_overview(self):
summary = ''
for owner in self.ownership_set.all():
summary += '<p>{}: {}</p>'.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,

@ -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)

Loading…
Cancel
Save