(self)
Set the 'version' property on each form as follows to the current app version if the form is new
        or has changed since the last build. Otherwise set it to the version from the last build.
Set the 'version' property on each form as follows to the current app version if the form is new
        or has changed since the last build. Otherwise set it to the version from the last build.
Set the version property on each form as follows to the current app version if the form is new or has changed since the last build . Otherwise set it to the version from the last build .
def set_form_versions(self):
        """
        Set the 'version' property on each form as follows to the current app version if the form is new
        or has changed since the last build. Otherwise set it to the version from the last build.
        """
        def _hash(val):
            return hashlib.md5(val).hexdigest()

        latest_build = self._get_version_comparison_build()
        if not latest_build:
            return
        force_new_version = self.build_profiles != latest_build.build_profiles
        for form_stuff in self.get_forms(bare=False):
            filename = 'files/%s' % self.get_form_filename(**form_stuff)
            form = form_stuff["form"]
            if not force_new_version:
                try:
                    previous_form = latest_build.get_form(form.unique_id)
                    # take the previous version's compiled form as-is
                    # (generation code may have changed since last build)
                    previous_source = latest_build.fetch_attachment(filename)
                except (ResourceNotFound, FormNotFoundException):
                    form.version = None
                else:
                    previous_hash = _hash(previous_source)

                    # hack - temporarily set my version to the previous version
                    # so that that's not treated as the diff
                    previous_form_version = previous_form.get_version()
                    form.version = previous_form_version
                    my_hash = _hash(self.fetch_xform(form))
                    if previous_hash != my_hash:
                        form.version = None
            else:
                form.version = None
def set_form_versions ( self ) : def _hash ( val ) : return hashlib . md5 ( val ) . hexdigest ( ) latest_build = self . _get_version_comparison_build ( ) if not latest_build : return force_new_version = self . build_profiles != latest_build . build_profiles for form_stuff in self . get_forms ( bare = False ) : filename = 'files/%s' % self . get_form_filename ( * * form_stuff ) form = form_stuff [ "form" ] if not force_new_version : try : previous_form = latest_build . get_form ( form . unique_id ) # take the previous version's compiled form as-is # (generation code may have changed since last build) previous_source = latest_build . fetch_attachment ( filename ) except ( ResourceNotFound , FormNotFoundException ) : form . version = None else : previous_hash = _hash ( previous_source ) # hack - temporarily set my version to the previous version # so that that's not treated as the diff previous_form_version = previous_form . get_version ( ) form . version = previous_form_version my_hash = _hash ( self . fetch_xform ( form ) ) if previous_hash != my_hash : form . version = None else : form . version = None