Skip to content

Commit d36775b

Browse files
committed
reduced verbosity of code with variables
1 parent 05cf49a commit d36775b

File tree

2 files changed

+26
-68
lines changed

2 files changed

+26
-68
lines changed

legal_tools/management/commands/publish.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ def write_legal_tools(self):
360360
for group in legal_codes.keys():
361361
tools = set()
362362
LOG.debug(f"{hostname}:{output_dir}")
363-
LOG.info(f"Writing {group} deed HTML, legal code HTML, and RDF/XML")
363+
LOG.info(
364+
f"Writing {group} deed HTML, legal code HTML, and RDF/XML"
365+
)
364366
legal_code_arguments = []
365367
deed_arguments = []
366368
rdf_arguments = []

legal_tools/rdf_generator.py

+23-67
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def generate_rdf_file(
3131
# Retrieving license data from the database based on the arguments.
3232
if generate_all_licenses is True:
3333
retrieved_tools = Tool.objects.all()
34-
3534
else:
3635
if jurisdiction:
3736
retrieved_tool = Tool.objects.filter(
@@ -65,19 +64,13 @@ def generate_rdf_file(
6564
license_uri = URIRef(convert_https_to_http(tool_obj.base_url))
6665

6766
g.set((license_uri, RDF.type, CC.License))
67+
6868
g.add((license_uri, DCTERMS.identifier, Literal(f"{tool_obj.unit}")))
69-
g.add(
70-
(license_uri, DCTERMS.hasVersion, Literal(f"{tool_obj.version}"))
71-
)
69+
version = Literal(f"{tool_obj.version}")
70+
g.add((license_uri, DCTERMS.hasVersion, version))
7271
g.add((license_uri, OWL.sameAs, URIRef(tool_obj.base_url)))
73-
74-
g.add(
75-
(
76-
license_uri,
77-
DCTERMS.creator,
78-
URIRef(convert_https_to_http(tool_obj.creator_url)),
79-
)
80-
)
72+
creator = URIRef(convert_https_to_http(tool_obj.creator_url))
73+
g.add((license_uri, DCTERMS.creator, creator))
8174

8275
# adding cc:licenseClass
8376
if tool_obj.category == "publicdomain":
@@ -86,50 +79,32 @@ def generate_rdf_file(
8679
f"{tool_obj.creator_url}/choose/{tool_obj.unit}/"
8780
)
8881
)
89-
9082
elif tool_obj.unit in ["sampling", "sampling+"]:
9183
license_class_uriref = URIRef(
9284
convert_https_to_http(
9385
f"{tool_obj.creator_url}/{tool_obj.category}/sampling/"
9486
)
9587
)
96-
9788
else:
9889
license_class_uriref = URIRef(
9990
convert_https_to_http(
10091
f"{tool_obj.creator_url}/{tool_obj.category}/"
10192
)
10293
)
103-
10494
g.add((license_uri, CC.licenseClass, license_class_uriref))
10595

106-
# g.add(
107-
# (
108-
# license_uri,
109-
# DCT.description,
110-
# Literal(" NEED SUGGESTIONS ON WHAT TO PUT HERE."),
111-
# )
112-
# )
113-
11496
if tool_obj.jurisdiction_code:
11597
logo_prefix = (
11698
f"{FOAF_LOGO_URL}{tool_obj.unit}"
11799
f"/{tool_obj.version}/{tool_obj.jurisdiction_code}"
118100
)
119-
120-
g.add(
121-
(
122-
license_uri,
123-
CC.jurisdiction,
124-
URIRef(
125-
convert_https_to_http(
126-
f"{tool_obj.creator_url}/international/"
127-
f"{tool_obj.jurisdiction_code}"
128-
)
129-
),
101+
jurisdiction_uri = URIRef(
102+
convert_https_to_http(
103+
f"{tool_obj.creator_url}/international/"
104+
f"{tool_obj.jurisdiction_code}"
130105
)
131106
)
132-
107+
g.add((license_uri, CC.jurisdiction, jurisdiction_uri))
133108
else:
134109
logo_prefix = f"{FOAF_LOGO_URL}{tool_obj.unit}/{tool_obj.version}"
135110

@@ -151,53 +126,34 @@ def generate_rdf_file(
151126
g.add((license_uri, DCTERMS.title, (tool_title_data)))
152127

153128
legal_code_url = legal_code_object.legal_code_url
154-
g.add(
155-
(
156-
license_uri,
157-
CC.legalcode,
158-
URIRef(
159-
convert_https_to_http(
160-
f"{tool_obj.creator_url}{legal_code_url}"
161-
)
162-
),
129+
cc_legal_code = URIRef(
130+
convert_https_to_http(
131+
f"{tool_obj.creator_url}{legal_code_url}"
163132
)
164133
)
134+
g.add((license_uri, CC.legalcode, cc_legal_code))
135+
165136
# added DCTERMS.language for every legal_code_url
166137
if not generate_all_licenses:
167138
g.add(
168139
(CC[legal_code_url], DCTERMS.language, Literal(tool_lang))
169140
)
170141

171142
if tool_obj.deprecated_on:
172-
g.add(
173-
(
174-
license_uri,
175-
CC.deprecatedOn,
176-
Literal(tool_obj.deprecated_on, datatype=XSD.date),
177-
)
178-
)
143+
deprecated_on = Literal(tool_obj.deprecated_on, datatype=XSD.date)
144+
g.add((license_uri, CC.deprecatedOn, deprecated_on))
179145

180146
if tool_obj.is_replaced_by:
181-
g.add(
182-
(
183-
license_uri,
184-
DCTERMS.isReplacedBy,
185-
URIRef(
186-
convert_https_to_http(tool_obj.is_replaced_by.base_url)
187-
),
188-
)
147+
replaced_by = URIRef(
148+
convert_https_to_http(tool_obj.is_replaced_by.base_url)
189149
)
150+
g.add((license_uri, DCTERMS.isReplacedBy, replaced_by))
190151

191152
if tool_obj.is_based_on:
192-
g.add(
193-
(
194-
license_uri,
195-
DCTERMS.source,
196-
URIRef(
197-
convert_https_to_http(tool_obj.is_based_on.base_url)
198-
),
199-
)
153+
based_on = URIRef(
154+
convert_https_to_http(tool_obj.is_based_on.base_url)
200155
)
156+
g.add((license_uri, DCTERMS.source, based_on))
201157

202158
# Adding properties
203159
# Permits

0 commit comments

Comments
 (0)