Skip to content

Commit

Permalink
Code complexity reduced to D
Browse files Browse the repository at this point in the history
  • Loading branch information
matijakolaric committed Jul 25, 2022
1 parent 9eb5e29 commit d92562d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
10 changes: 5 additions & 5 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ Full metadata backup can be download using REST API endpoint.
22.9 Rubicon
-------------------------------

``Account #`` field was added to the writer model. This field can be used for linking
``Account #`` field was added to the ``Writer`` model. This field can be used for linking
data from outgoing royalty statements with accounting.

Many of the improvements in this release are under the bonnet. The code has been
reviewed and partly cleaned up. Code style is now validated with Black.

Introduction chapter of this documentation was extended with graphs, and split
into two separate documents.
into two separate documents. Several external articles were linked to
improve clarity.

Many of the improvements in this release are under the bonnet. The code has been
reviewed and partly cleaned up. Code style is now validated with Black.


Future open-source features
Expand Down
43 changes: 13 additions & 30 deletions music_publisher/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_fieldsets(self, request, obj=None):
(
'Audio',
{
'fields': (('audio_file',)),
'fields': (('audio_file',),),
},
),
)
Expand Down Expand Up @@ -596,6 +596,7 @@ def track_count(self, obj):
track_count.short_description = 'Recordings'
track_count.admin_order_field = 'tracks__count'

# noinspection PyUnusedLocal
def create_json(self, request, qs):
"""Batch action that downloads a JSON file containing library releases.
Expand Down Expand Up @@ -722,27 +723,6 @@ def track_count(self, obj):
track_count.short_description = 'Recordings'
track_count.admin_order_field = 'tracks__count'

# def create_json(self, request, qs):
# """Batch action that downloads a JSON file containing library releases.
#
# Returns:
# JsonResponse: JSON file with selected works
# """
#
# j = Playlist.objects.get_dict(qs)
#
# response = JsonResponse(j, json_dumps_params={'indent': 4})
# name = '{}-libraryreleases-{}'.format(
# settings.PUBLISHER_CODE, datetime.now().toordinal())
# cd = 'attachment; filename="{}.json"'.format(name)
# response['Content-Disposition'] = cd
# return response
#
# create_json.short_description = \
# 'Export selected library releases (JSON).'
#
# actions = ['create_json']


@admin.register(CommercialRelease)
class CommercialReleaseAdmin(MusicPublisherAdmin):
Expand Down Expand Up @@ -820,6 +800,7 @@ def track_count(self, obj):
track_count.short_description = 'Recordings'
track_count.admin_order_field = 'tracks__count'

# noinspection PyUnusedLocal
def create_json(self, request, qs):
"""Batch action that downloads a JSON file containing commercial
releases.
Expand Down Expand Up @@ -1209,19 +1190,19 @@ def lookups(self, request, model_admin):
"""Simple Yes/No filter"""
return WorkAcknowledgement.TRANSACTION_STATUS_CHOICES

def queryset(self, request, queryset):
def queryset(self, request, qs):
"""Filter on ACK status."""
if self.value():
if hasattr(queryset, 'society_code'):
queryset = queryset.filter(
if hasattr(qs, 'society_code'):
qs = qs.filter(
workacknowledgement__status=self.value(),
workacknowledgement__society_code=queryset.society_code,
workacknowledgement__society_code=qs.society_code,
).distinct()
else:
queryset = queryset.filter(
qs = qs.filter(
workacknowledgement__status=self.value()
).distinct()
return queryset
return qs

class HasISWCListFilter(admin.SimpleListFilter):
"""Custom list filter on the presence of ISWC."""
Expand Down Expand Up @@ -1320,7 +1301,7 @@ def save_model(self, request, obj, form, *args, **kwargs):

def save_formset(self, request, form, formset, change):
"""Set last_change for the work if any of the inline forms has
changed. """
changed."""
save_instance = False
for form in formset:
if form.changed_data:
Expand All @@ -1343,6 +1324,7 @@ def create_cwr(self, request, qs):

create_cwr.short_description = 'Create CWR from selected works.'

# noinspection PyUnusedLocal
def create_json(self, request, qs):
"""Batch action that downloads a JSON file containing selected works.
Expand Down Expand Up @@ -1601,6 +1583,7 @@ def write(self, value):
row['Reference {} ID'.format(i + 1)] = xrf['identifier']
yield writer.writerow(row)

# noinspection PyUnusedLocal
def create_csv(self, request, qs):
"""Batch action that downloads a CSV file containing selected works.
Expand Down Expand Up @@ -1942,7 +1925,7 @@ def get_fields(self, request, obj=None):
'download_link',
)
else:
return ('nwr_rev', 'description', 'works')
return 'nwr_rev', 'description', 'works'

def has_add_permission(self, request):
"""Return false if CWR delivery code is not present."""
Expand Down

0 comments on commit d92562d

Please sign in to comment.