Esempio n. 1
0
    def _apply_case_update(self, case_update, xformdoc):
        sql_migration_in_progress = couch_sql_migration_in_progress(
            xformdoc.domain)
        if case_update.has_referrals() and not sql_migration_in_progress:
            logging.error(
                'Form {} touching case {} in domain {} is still using referrals'
                .format(xformdoc.form_id, case_update.id,
                        getattr(xformdoc, 'domain', None)))
            raise UsesReferrals(_('Sorry, referrals are no longer supported!'))

        if case_update.version and case_update.version != V2 and not sql_migration_in_progress:
            raise VersionNotSupported

        if not case_update.user_id and xformdoc.user_id:
            # hack for migration from V1 case blocks
            case_update.user_id = xformdoc.user_id

        if xformdoc.is_deprecated:
            return

        for action in case_update.actions:
            self._apply_action(case_update, action, xformdoc)

        # override any explicit properties from the update
        if case_update.user_id:
            self.case.modified_by = case_update.user_id

        modified_on = case_update.guess_modified_on()
        if self.case.modified_on is None or modified_on > self.case.modified_on:
            self.case.modified_on = modified_on

        # edge case if form updates case before it's been created (or creation form archived)
        if not self.case.opened_on:
            self.case.opened_on = modified_on
        if not self.case.opened_by:
            self.case.opened_by = case_update.user_id
        if not self.case.owner_id:
            self.case.owner_id = case_update.user_id
Esempio n. 2
0
    def _apply_case_update(self, case_update, xformdoc):
        if case_update.has_referrals():
            logging.error('Form {} touching case {} in domain {} is still using referrals'.format(
                xformdoc.form_id, case_update.id, getattr(xformdoc, 'domain', None))
            )
            raise UsesReferrals(_('Sorry, referrals are no longer supported!'))

        if case_update.version and case_update.version != V2:
            raise VersionNotSupported

        if xformdoc.is_deprecated:
            return

        for action in case_update.actions:
            self._apply_action(case_update, action, xformdoc)

        # override any explicit properties from the update
        if case_update.user_id:
            self.case.modified_by = case_update.user_id

        modified_on = case_update.guess_modified_on()
        if self.case.modified_on is None or modified_on > self.case.modified_on:
            self.case.modified_on = modified_on