Skip to content

Commit

Permalink
custom admin sorts, bumped Django to 3.2, bumped version to dev5
Browse files Browse the repository at this point in the history
  • Loading branch information
matijakolaric committed Apr 12, 2021
1 parent f9d142e commit a3a33cc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 21 deletions.
62 changes: 47 additions & 15 deletions music_publisher/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ArtistInWorkInline(admin.TabularInline):
autocomplete_fields = ('artist', 'work')
model = ArtistInWork
extra = 0
ordering = ('artist__last_name', 'artist__first_name')
verbose_name_plural = \
'Artists performing Works (not mentioned in "recordings" section)'

Expand Down Expand Up @@ -77,7 +78,7 @@ class RecordingInline(admin.StackedInline):
verbose_name_plural = \
'Recordings (with recording artists and record labels)'
model = Recording
ordering = ('recording_title', 'version_title')
ordering = ('recording_title', 'version_title', 'id')
extra = 0


Expand All @@ -86,6 +87,8 @@ class ArtistAdmin(MusicPublisherAdmin):
"""Admin interface for :class:`.models.Artist`.
"""

ordering = ('last_name', 'first_name', 'isni', '-id')

list_display = (
'last_or_band', 'first_name', 'isni', 'recording_count', 'work_count')
search_fields = ('last_name', 'isni',)
Expand Down Expand Up @@ -167,6 +170,8 @@ class LabelAdmin(MusicPublisherAdmin):
('Notes', {'fields': ('notes',), }),
)

ordering = ('name', '-id')

def get_queryset(self, request):
"""Optimized queryset for changelist view.
"""
Expand Down Expand Up @@ -237,6 +242,7 @@ class LibraryAdmin(MusicPublisherAdmin):
"""
actions = None
search_fields = ('name',)
ordering = ('name', '-id')

list_display = ('name', 'libraryrelease_count', 'work_count')
readonly_fields = ('libraryrelease_count', 'work_count')
Expand Down Expand Up @@ -293,6 +299,7 @@ class TrackInline(admin.TabularInline):
:class:`LibraryReleaseAdmin` and :class:`CommercialReleaseAdmin`.
"""
model = Track
ordering = ('release', 'cut_number',)
autocomplete_fields = ('release', 'recording')
extra = 0

Expand All @@ -302,6 +309,7 @@ class ReleaseAdmin(MusicPublisherAdmin):
"""Admin interface for :class:`.models.Release`.
"""

ordering = ('release_title', 'cd_identifier', '-id')
actions = None
list_display = (
'__str__',
Expand Down Expand Up @@ -342,6 +350,7 @@ class LibraryReleaseAdmin(MusicPublisherAdmin):
"""Admin interface for :class:`.models.LibraryRelease`.
"""

ordering = ('release_title', 'cd_identifier', '-id')
form = LibraryReleaseForm
inlines = [TrackInline]
autocomplete_fields = ('release_label', 'library')
Expand Down Expand Up @@ -454,6 +463,7 @@ class CommercialReleaseAdmin(MusicPublisherAdmin):
"""Admin interface for :class:`.models.CommercialRelease`.
"""

ordering = ('release_title', 'cd_identifier', '-id')
inlines = [TrackInline]
autocomplete_fields = ('release_label',)

Expand Down Expand Up @@ -538,6 +548,7 @@ class WriterAdmin(MusicPublisherAdmin):
"""Interface for :class:`.models.Writer`.
"""

ordering = ('last_name', 'first_name', 'ipi_name', '-id')
list_display = ('last_name', 'first_name', 'ipi_name', 'pr_society',
'_can_be_controlled', 'generally_controlled',
'work_count')
Expand Down Expand Up @@ -662,6 +673,7 @@ class AlternateTitleInline(admin.TabularInline):
verbose_name_plural = \
'Alternative titles (not mentioned in "recordings" section)'
fields = ('title', 'suffix', 'complete_alt_title')
ordering = ('suffix', 'title',)

def complete_alt_title(self, obj):
"""Return the complete title, see
Expand All @@ -681,6 +693,8 @@ class WriterInWorkInline(admin.TabularInline):
fields = (
'writer', 'capacity', 'relative_share', 'controlled', 'saan',
'publisher_fee')
ordering = (
'-controlled', 'writer__last_name', 'writer__first_name', '-id')


class WorkAcknowledgementInline(admin.TabularInline):
Expand All @@ -693,6 +707,7 @@ class WorkAcknowledgementInline(admin.TabularInline):
model = WorkAcknowledgement
extra = 0
fields = ('date', 'society_code', 'remote_work_id', 'status')
ordering = ('-date', '-id')


class WorkForm(forms.ModelForm):
Expand Down Expand Up @@ -737,6 +752,7 @@ class WorkAdmin(MusicPublisherAdmin):
:class:`WorkAcknowledgementInline`,
"""

ordering = ('-id',)
form = WorkForm

inlines = (
Expand Down Expand Up @@ -1140,16 +1156,17 @@ def write(self, value):
w = wiw.get('writer') or {}
row['Writer {} Last'.format(i + 1)] = w.get('last_name', '')
row['Writer {} First'.format(i + 1)] = w.get('first_name', '')
row['Writer {} IPI'.format(i + 1)] = w.get('ipi_name_number', '')
row['Writer {} IPI'.format(i + 1)] = w.get(
'ipi_name_number', '')
role = wiw.get('writer_role', {})
if role:
row['Writer {} Role'.format(i + 1)] = '{} - {}'.format(
role['code'], role['name'])
for aff in w.get('affiliations', []):
code = aff['affiliation_type']['code']
cmo = aff['organization']
row['Writer {} {}O'.format(i + 1, code)] = '{} - {}'.format(
cmo['code'], cmo['name'])
row['Writer {} {}O'.format(i + 1, code)] = \
'{} - {}'.format(cmo['code'], cmo['name'])
ops = wiw.get('original_publishers')

row['Writer {} Manuscript Share'.format(i + 1)] = Decimal(
Expand Down Expand Up @@ -1208,22 +1225,33 @@ def write(self, value):
row['Writer {} Controlled'.format(i + 1)] = controlled
for i, rec in enumerate(work['recordings']):
row['Recording {} ID'.format(i + 1)] = rec['code']
row['Recording {} Recording Title'.format(i + 1)] = rec['recording_title']
row['Recording {} Version Title'.format(i + 1)] = rec['version_title']
row['Recording {} Release Date'.format(i + 1)] = rec['release_date']
row['Recording {} Recording Title'.format(i + 1)] = \
rec['recording_title']
row['Recording {} Version Title'.format(i + 1)] = \
rec['version_title']
row['Recording {} Release Date'.format(i + 1)] = \
rec['release_date']
row['Recording {} Duration'.format(i + 1)] = rec['duration']
row['Recording {} ISRC'.format(i + 1)] = rec['isrc']
row['Recording {} Record Label'.format(i + 1)] = (rec['record_label'] or {}).get('name')
row['Recording {} Record Label'.format(i + 1)] = \
(rec['record_label'] or {}).get('name')
artist = rec.get('recording_artist') or {}
row['Recording {} Artist Last'.format(i + 1)] = artist.get('last_name', '')
row['Recording {} Artist Last'.format(i + 1)] = artist.get('last_name', '')
row['Recording {} Artist First'.format(i + 1)] = artist.get('first_name', '')
row['Recording {} Artist ISNI'.format(i + 1)] = artist.get('isni', '')
row['Recording {} Artist Last'.format(i + 1)] = \
artist.get('last_name', '')
row['Recording {} Artist Last'.format(i + 1)] = \
artist.get('last_name', '')
row['Recording {} Artist First'.format(i + 1)] = \
artist.get('first_name', '')
row['Recording {} Artist ISNI'.format(i + 1)] = \
artist.get('isni', '')
for i, aiw in enumerate(work['performing_artists']):
artist = aiw.get('artist')
row['Artist {} Last'.format(i + 1)] = artist.get('last_name', '')
row['Artist {} First'.format(i + 1)] = artist.get('first_name', '')
row['Artist {} ISNI'.format(i + 1)] = artist.get('isni', '')
row['Artist {} Last'.format(i + 1)] = \
artist.get('last_name', '')
row['Artist {} First'.format(i + 1)] = \
artist.get('first_name', '')
row['Artist {} ISNI'.format(i + 1)] = \
artist.get('isni', '')
for i, xrf in enumerate(work['cross_references']):
code = xrf['organization']['code']
name = xrf['organization']['name']
Expand Down Expand Up @@ -1284,6 +1312,7 @@ class RecordingAdmin(MusicPublisherAdmin):
list_display = (
'recording_id', 'title', 'isrc', 'work_link', 'artist_link',
'label_link')
ordering = ('-id',)

class HasISRCListFilter(admin.SimpleListFilter):
"""Custom list filter on the presence of ISRC.
Expand Down Expand Up @@ -1397,6 +1426,7 @@ class CWRExportAdmin(admin.ModelAdmin):
"""

actions = None
ordering = ('-id',)

def work_count(self, obj):
"""Return the work count from the database field, or count them.
Expand Down Expand Up @@ -1621,6 +1651,7 @@ def print_report(self, obj):
"""Mark report as HTML-safe."""
return mark_safe(obj.report)
print_report.short_description = 'Report'
ordering = ('-id',)


@admin.register(ACKImport)
Expand Down Expand Up @@ -1861,6 +1892,7 @@ class DataImportAdmin(AdminWithReport):

list_display = ('filename', 'date')
fields = readonly_fields = ('filename', 'date', 'print_report')
ordering = ('-id',)

def add_view(self, request, form_url='', extra_context=None):
if 'download_template' in request.GET:
Expand Down
47 changes: 44 additions & 3 deletions music_publisher/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,23 @@
text-transform: uppercase;
}
td, th, li, dt, dd, input, .form-row, textarea, select {
font-size: 14px;
line-height: 16px;
font-size: 15px;
line-height: 18px;
}
.form-row, .module.aligned input:not([type=checkbox]):not([type=submit]), textarea, select {
min-width: 20em;
box-sizing: border-box;
}
.fieldBox {
min-width: 20em;
box-sizing: border-box;
padding: 3px 0;
}
.related-widget-wrapper {
width: 20em;
}
.inline-group .aligned label {
width: 10em !important;
}
select:disabled {
background-color: var(--darkened-bg);
Expand Down Expand Up @@ -69,12 +84,38 @@
#branding h2 a {
font-size: 18px;
}
.inline-group .tabular tr.has_original td {

div.inline-group .tabular tr.has_original td {
padding: 8px !important;
}
div.inline-group .module.aligned h2 {
padding: 8px 0 0 8px;
background-color: var(--breadcrumbs-bg);
color: var(--breadcrumbs-fg);
font-size: 13px;
}

.field-original_publisher_pr_share input[type=number],
.field-writer_pr_share input[type=number] {
border: 1px solid var(--link-fg);
}

.field-original_publisher_pr_share label,
.field-writer_pr_share label {
color: var(--link-fg);
}

.module caption, .inline-group h2, .module h2 {
font-size: 18px;
}

.select2-selection__clear {
font-size: 20px;
color: var(--primary);
}
.form-row {
font-size: 15px !important;
}
#user-tools {
font-size: 15px;
}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django>=3.2rc1,<3.3
Django>=3.2,<3.3
dj_database_url==0.5.0
psycopg2-binary==2.8.6
waitress==2.0.0
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='django-music-publisher',
version='21.7.dev4',
version='21.7.dev5',
author='Matija Kolarić',
author_email='matijakolaric@users.noreply.github.com',
license='MIT License',
Expand All @@ -25,7 +25,7 @@
},
packages=setuptools.find_packages(exclude=['dmp_project', 'docs']),
install_requires=(
'Django>=3.2rc1,<3.3',
'Django>=3.2,<3.3',
'requests>=2.24.0',
),
include_package_data=True,
Expand Down

0 comments on commit a3a33cc

Please sign in to comment.