(form)
Save a previously unsaved form
Save a previously unsaved form
Save a previously unsaved form
def save_new_form(form):
        """
        Save a previously unsaved form
        """
        if form.is_saved():
            raise XFormSaveError('form already saved')
        logging.debug('Saving new form: %s', form)

        operations = form.get_tracked_models_to_create(XFormOperationSQL)
        for operation in operations:
            if operation.is_saved():
                raise XFormSaveError(
                    'XFormOperationSQL {} has already been saved'.format(operation.id)
                )
            operation.form_id = form.form_id

        try:
            with form.attachment_writer() as attachment_writer, \
                    transaction.atomic(using=form.db, savepoint=False):
                transaction.on_commit(attachment_writer.commit, using=form.db)
                form.save()
                attachment_writer.write()
                for operation in operations:
                    operation.save()
        except InternalError as e:
            raise XFormSaveError(e)

        form.clear_tracked_models()
def save_new_form ( form ) : if form . is_saved ( ) : raise XFormSaveError ( 'form already saved' ) logging . debug ( 'Saving new form: %s' , form ) operations = form . get_tracked_models_to_create ( XFormOperationSQL ) for operation in operations : if operation . is_saved ( ) : raise XFormSaveError ( 'XFormOperationSQL {} has already been saved' . format ( operation . id ) ) operation . form_id = form . form_id try : with form . attachment_writer ( ) as attachment_writer , transaction . atomic ( using = form . db , savepoint = False ) : transaction . on_commit ( attachment_writer . commit , using = form . db ) form . save ( ) attachment_writer . write ( ) for operation in operations : operation . save ( ) except InternalError as e : raise XFormSaveError ( e ) form . clear_tracked_models ( )