def update(consumer_id, content_type, profile): """ Update a unit profile. Created if not already exists. :param consumer_id: uniquely identifies the consumer. :type consumer_id: str :param content_type: The profile (content) type ID. :type content_type: str :param profile: The unit profile :type profile: object """ try: profiler, config = plugin_api.get_profiler_by_type(content_type) except plugin_exceptions.PluginNotFound: # Not all profile types have a type specific profiler, so let's use the baseclass # Profiler profiler, config = (Profiler(), {}) consumer = factory.consumer_manager().get_consumer(consumer_id) # Allow the profiler a chance to update the profile before we save it profile = profiler.update_profile(consumer, content_type, profile, config) try: p = ProfileManager.get_profile(consumer_id, content_type) p['profile'] = profile # We store the profile's hash anytime the profile gets altered p['profile_hash'] = UnitProfile.calculate_hash(profile) except MissingResource: p = UnitProfile(consumer_id, content_type, profile) collection = UnitProfile.get_collection() collection.save(p, safe=True) return p
def _profiler(typeid): """ Find the profiler. Returns the Profiler base class when not matched. :param typeid: The content type ID. :type typeid: str :return: (profiler, cfg) :rtype: tuple """ try: plugin, cfg = plugin_api.get_profiler_by_type(typeid) except plugin_exceptions.PluginNotFound: plugin = Profiler() cfg = {} return plugin, cfg