'A context manager for temporarily setting a store\'s branch value on the current thread.'

@contextmanager
def branch_setting(self, branch_setting, course_id=None):

    previous_thread_branch_setting = getattr(self.thread_cache, 'branch_setting', None)
    try:
        self.thread_cache.branch_setting = branch_setting
        (yield)
    finally:
        self.thread_cache.branch_setting = previous_thread_branch_setting
