Skip to content

Commit

Permalink
Better comments and cleanup of Pricing get_data and unformat_data
Browse files Browse the repository at this point in the history
  • Loading branch information
benvand committed Apr 18, 2017
1 parent 1ed993c commit 666e986
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions dmcontent/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,16 @@ def get_question(self, field_name):
return self

def unformat_data(self, data):
return self.get_data(data)
"""Get values from api data whose keys are in self.fields; this indicates they are related to this question."""
return {key: data[key] for key in data if key in self.fields.values()}

def get_data(self, form_data):
return {
key: form_data[key] if form_data[key] else None
for key in self.fields.values()
if key in form_data
}
"""
Return a subset of form_data containing only those key: value pairs whose key appears in the self.fields of
this question (therefore only those pairs relevant to this question).
Filter 0/ False values here and replace with None as they are handled with the optional flag.
"""
return {key: form_data[key] or None for key in self.fields.values() if key in form_data}

@property
def form_fields(self):
Expand Down

0 comments on commit 666e986

Please sign in to comment.