Changeset 1612 for trunk/pylucid/PyLucid/models/Plugin.py
- Timestamp:
- 05/31/08 22:01:20 (22 months ago)
- Files:
-
- 1 modified
-
trunk/pylucid/PyLucid/models/Plugin.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/models/Plugin.py
r1609 r1612 19 19 from pprint import pformat 20 20 21 from django.conf import settings 22 21 23 from django.db import models, transaction, connection 22 24 from django.core.cache import cache … … 32 34 preference_cache = {} 33 35 36 PLUGIN_MODEL_LABEL = "PyLucidPlugins" 37 PLUGIN_MODEL_APP = "PyLucid.system.PyLucidPlugins" 38 39 40 def get_plugin_models(package_name, plugin_name, debug=False): 41 """ 42 returns a list of all existing plugin models. 43 If no models exist, returns None! 44 45 Seperated function, because must be accessible from manager- and plugin 46 class, too. 47 """ 48 plugin_module = get_plugin_module(package_name, plugin_name, debug) 49 if not hasattr(plugin_module, "PLUGIN_MODELS"): 50 # Plugin has no models 51 return None 52 53 if not PLUGIN_MODEL_APP in settings.INSTALLED_APPS: 54 from django.core.exceptions import ImproperlyConfigured 55 raise ImproperlyConfigured( 56 "Error '%s' not in settings.INSTALLED_APPS!" % PLUGIN_MODEL_APP 57 ) 58 59 plugin_models = plugin_module.PLUGIN_MODELS 60 61 # Check app_label for every plugin model 62 for model in plugin_models: 63 app_label = model._meta.app_label 64 assert app_label == PLUGIN_MODEL_LABEL, ( 65 "Plugin models must defined in class Meta: app_label = '%s'" 66 ) % PLUGIN_MODEL_LABEL 67 68 return plugin_models 69 70 71 72 73 34 74 class PluginManager(models.Manager): 35 75 """ … … 51 91 plugin = self.get(plugin_name = plugin_name) 52 92 return plugin.get_preferences() 93 94 def get_plugin_models(self, package_name, plugin_name, debug=False): 95 """ returns a list of all existing plugin models or None """ 96 return get_plugin_models(package_name, plugin_name, debug) 97 53 98 54 99 … … 152 197 return get_plugin_version(self.package_name, self.plugin_name, debug) 153 198 199 def get_plugin_models(self, debug=False): 200 """ returns a list of all existing plugin models or None """ 201 return get_plugin_models(self.package_name, self.plugin_name, debug) 202 154 203 #___________________________________________________________________________ 155 204 # SAVE … … 173 222 174 223 def get_delete_sql(self, plugin_models): 175 # from django.conf import settings 224 """ 225 Returns a list of sql statements for deleting the plugin model tabels. 226 For this, we used the fake django app "PyLucidPlugins" and attach 227 all models to this add temporarly. 228 """ 229 from django.core.management import sql 176 230 from django.core.management.color import no_style 177 231 style = no_style() 178 from django.core.management import sql179 232 180 233 models.loading.register_models("PyLucidPlugins", *plugin_models) 181 234 182 # get all delete statements for the given App183 235 app = models.get_app("PyLucidPlugins") 236 184 237 statements = sql.sql_delete(app, style) 185 238 186 print sql.table_list() 187 188 #cleanup 239 # cleanup 189 240 app_models = models.loading.cache.app_models 190 241 del(app_models["PyLucidPlugins"]) 191 # settings.INSTALLED_APPS = old_inst_apps192 242 193 243 return statements 194 244 195 def get_delete_tables(self): 196 plugin_module = get_plugin_module( 197 self.package_name, 198 self.plugin_name, 199 debug=True, 200 ) 201 if not hasattr(plugin_module, "PLUGIN_MODELS"): 245 def _delete_tables(self): 246 """ 247 Delete all plugin model tabels. 248 """ 249 plugin_models = self.get_plugin_models() 250 if not plugin_models: 202 251 # Plugin has no models 203 252 return 204 253 205 plugin_models = plugin_module.PLUGIN_MODELS206 207 254 statements = self.get_delete_sql(plugin_models) 208 255 209 256 cursor = connection.cursor() 210 257 for statement in statements: 211 print repr(statement)258 #print repr(statement) 212 259 cursor.execute(statement) 213 260 … … 215 262 @transaction.commit_on_success 216 263 def delete(self): 217 self. get_delete_tables()264 self._delete_tables() 218 265 219 266 super(Plugin, self).delete()