def new(self, profile_dict): """ @profile_dict need to contain the keys: 'plugin_type', 'plugin_name', 'admin_settings', """ store = self.getStore() newone = PluginProfiles() try: # below, before _import_dict, are checked profile_type, and plugin_name # both of them can't be updated, are chosen at creation time, if not unicode(profile_dict['plugin_type']) in valid_plugin_types: raise InvalidInputFormat("plugin_type not recognized") if not PluginManager.plugin_exists(profile_dict['plugin_name']): raise InvalidInputFormat("plugin_name not recognized between available plugins") newone._import_dict(profile_dict) # the name can be updated, but need to be checked to be UNIQUE if store.find(PluginProfiles, PluginProfiles.profile_name == newone.profile_name).count() >= 1: raise ProfileNameConflict plugin_info = PluginManager.get_plugin(profile_dict['plugin_name']) # initialize the three plugin_* fields, inherit by Plugin code newone.plugin_name = unicode(plugin_info['plugin_name']) newone.plugin_type = unicode(plugin_info['plugin_type']) newone.plugin_description = unicode(plugin_info['plugin_description']) newone.admin_fields = dict(plugin_info['admin_fields']) # Admin-only plugins are listed here, and they have not receiver_fields if newone.plugin_type in [ u'fileprocess' ]: newone.receiver_fields = [] else: newone.receiver_fields = plugin_info['receiver_fields'] except KeyError, e: raise InvalidInputFormat("Profile creation failed (missing %s)" % e)