示例#1
0
    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
示例#2
0
 def update(self, 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
     """
     manager = factory.consumer_manager()
     manager.get_consumer(consumer_id)
     try:
         p = self.get_profile(consumer_id, content_type)
         p['profile'] = profile
     except MissingResource:
         p = UnitProfile(consumer_id, content_type, profile)
     collection = UnitProfile.get_collection()
     collection.save(p, safe=True)
     return p