Skip to content

Commit

Permalink
CWR 3.1 DRAFT
Browse files Browse the repository at this point in the history
  • Loading branch information
matijakolaric committed Dec 28, 2020
1 parent 1ed89eb commit b9c89f1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
25 changes: 24 additions & 1 deletion music_publisher/cwr_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
'{{ record_count|rjust:8 }}{% endautoescape %}'),
'OPT': Template(''),
'OWT': Template(''),
'XRF': Template('')
'XRF': Template(''),
'MAN': Template('')
}

TEMPLATES_22 = TEMPLATES_21.copy()
Expand Down Expand Up @@ -360,4 +361,26 @@
'{% load cwr_filters %}{% autoescape off %}'
'TRL00001{{ transaction_count|rjust:8 }}'
'{{ record_count|rjust:8 }}{% endautoescape %}'),
'MAN': Template('')
}

TEMPLATES_31 = TEMPLATES_30.copy()
TEMPLATES_31.update({
'HDR': Template(
'{% load cwr_filters %}{% autoescape off %}'
'HDRPB{{ publisher_code|ljust:4 }}'
'{{ publisher_name|ljust:45 }}' + ' ' * 11 +
'{{ creation_date|date:"Ymd" }}'
'{{ creation_date|date:"His" }}{{ creation_date|date:"Ymd" }}' +
' ' * 15 + '3.1000' + ' ' * 60 +
'{{ filename|ljust:27 }}\r\n{% endautoescape %}'),
'GRH': Template(
'{% load cwr_filters %}{% autoescape off %}'
'GRH{{ transaction_type|ljust:3 }}0000103.100000000000'
'\r\n{% endautoescape %}'),
'MAN': Template(
'{% load cwr_filters %}{% autoescape off %}'
'MAN{{ transaction_sequence|rjust:8 }}'
'{{ record_sequence|rjust:8 }}{{ code|ljust:9 }}'
'{{ share|cwrshare }}{{ share|cwrshare }}'
'{{ share|cwrshare }}\r\n{% endautoescape %}')})
35 changes: 25 additions & 10 deletions music_publisher/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
ArtistBase, IPIBase, LabelBase, LibraryBase, PersonBase, ReleaseBase,
TitleBase, WriterBase,
)
from .cwr_templates import TEMPLATES_21, TEMPLATES_22, TEMPLATES_30
from .cwr_templates import (
TEMPLATES_21, TEMPLATES_22, TEMPLATES_30, TEMPLATES_31)
from .validators import CWRFieldValidator

SOCIETY_DICT = OrderedDict(settings.SOCIETIES)
Expand Down Expand Up @@ -1143,7 +1144,8 @@ class Meta:
('NW2', 'CWR 2.2: New work registrations'),
('RE2', 'CWR 2.2: Revisions of registered works'),
('WRK', 'CWR 3.0: Work registration'),
('ISR', 'CWR 3.0: ISWC request (EDI)')
('ISR', 'CWR 3.0: ISWC request (EDI)'),
('WR1', 'CWR 3.1 DRAFT: Work registration'),
))
cwr = models.TextField(blank=True, editable=False)
year = models.CharField(
Expand All @@ -1157,6 +1159,8 @@ def version(self):
"""Return CWR version."""
if self.nwr_rev in ['WRK', 'ISR']:
return '30'
elif self.nwr_rev == 'WR1':
return '31'
elif self.nwr_rev in ['NW2', 'RE2']:
return '22'
return '21'
Expand All @@ -1168,32 +1172,37 @@ def filename(self):
Returns:
str: CWR file name
"""
if self.version == '30':
return self.filename30
return self.filename21
if self.version in ['30', '31']:
return self.filename3
return self.filename2

@property
def filename30(self):
"""Return proper CWR 3.0 filename.
def filename3(self):
"""Return proper CWR 3.x filename.
Format is: CWYYnnnnSUB_REP_VM - m - r.EXT
Returns:
str: CWR file name
"""
if self.version == '30':
minor_version = '0-0'
else:
minor_version = '1-0'
if self.nwr_rev == 'ISR':
ext = 'ISR'
else:
ext = 'SUB'
return 'CW{}{:04}{}_0000_V3-0-0.{}'.format(
return 'CW{}{:04}{}_0000_V3-{}.{}'.format(
self.year,
self.num_in_year,
settings.PUBLISHER_CODE,
minor_version,
ext)

@property
def filename21(self):
"""Return proper CWR 2.1 filename.
def filename2(self):
"""Return proper CWR 2.x filename.
Returns:
str: CWR file name
Expand All @@ -1219,6 +1228,8 @@ def get_record(self, key, record):
"""
if self.version == '30':
template = TEMPLATES_30.get(key)
elif self.version == '31':
template = TEMPLATES_31.get(key)
else:
if self.version == '22':
tdict = TEMPLATES_22
Expand Down Expand Up @@ -1387,6 +1398,8 @@ def yield_registration_lines(self, works):
yield self.get_transaction_record('SWR', w)
if w['share']:
yield self.get_transaction_record('SWT', w)
if w['share']:
yield self.get_transaction_record('MAN', w)
w['publisher_sequence'] = 1
yield self.get_transaction_record('PWR', w)
if (self.version == '30' and other_publisher_share and w and
Expand Down Expand Up @@ -1426,6 +1439,8 @@ def yield_registration_lines(self, works):
yield self.get_transaction_record('OWR', w)
if w['share']:
yield self.get_transaction_record('OWT', w)
if w['share']:
yield self.get_transaction_record('MAN', w)
if self.version == '30' and other_publisher_share:
w['publisher_sequence'] = 2
yield self.get_transaction_record('PWR', w)
Expand Down
6 changes: 6 additions & 0 deletions music_publisher/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,12 @@ def test_work(self):
cwr.works.add(work)
cwr.create_cwr()

# test CWR 3.1 WRK
cwr = music_publisher.models.CWRExport(nwr_rev='WR1')
cwr.save()
cwr.works.add(work)
cwr.create_cwr()


ACK_CONTENT_21 = """HDRSO000000021BMI 01.102018060715153220180607
GRHACK0000102.100020180607
Expand Down

0 comments on commit b9c89f1

Please sign in to comment.