Skip to content

Commit

Permalink
Simplify _req method slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrickstaley committed Sep 14, 2021
1 parent c0c3c88 commit 73d3cbf
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions genanki/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ def _req(self):

req = []
for template_ord, template in enumerate(self.templates):
field_values = {field: sentinel for field in field_names}
required_fields = []
for field_ord, field in enumerate(field_names):
fvcopy = copy(field_values)
fvcopy[field] = ''
field_values = {field: sentinel for field in field_names}
field_values[field] = ''

rendered = pystache.render(template['qfmt'], fvcopy)
rendered = pystache.render(template['qfmt'], field_values)

if sentinel not in rendered:
# when this field is missing, there is no meaningful content (no field values) in the question, so this field
Expand All @@ -70,12 +69,11 @@ def _req(self):
continue

# there are no required fields, so an "all" is not appropriate, switch to checking for "any"
field_values = {field: '' for field in field_names}
for field_ord, field in enumerate(field_names):
fvcopy = copy(field_values)
fvcopy[field] = sentinel
field_values = {field: '' for field in field_names}
field_values[field] = sentinel

rendered = pystache.render(template['qfmt'], fvcopy)
rendered = pystache.render(template['qfmt'], field_values)

if sentinel in rendered:
# when this field is present, there is meaningful content in the question
Expand Down

0 comments on commit 73d3cbf

Please sign in to comment.