def geocode(self, commit=False, force=False):
if self.need_geocoding() or force:<EOL><INDENT>result = get_cached(getattr(self, self.geocoded_by), provider='<STR_LIT>')<EOL>if result.status == '<STR_LIT:OK>':<EOL><INDENT>for attribute, components in self.required_address_components.items():<EOL><INDENT>for component in components:<EOL><INDENT>if not getattr(self, attribute) or force:<EOL><INDENT>attr_val = getattr(result, component, None)<EOL>if attr_val:<EOL><INDENT>setattr(self, attribute, attr_val)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if commit:<EOL><INDENT>self.save()<EOL><DEDENT><DEDENT>
Do a backend geocoding if needed