Extract common functionality to xblock-utils

@dragonfi `publish_event_from_dict` is fine by me.