Commits

jgsogo committed 98c0829 Draft

estructura para añadir ejemplos de implementaciones

  • Participants
  • Parent commits 9c7201b

Comments (0)

Files changed (5)

taxonomy/admin.py

 
 from mptt.admin import MPTTModelAdmin
 
-from categories.models import Category
+from taxonomy.models import Taxon
 
-class CategoryAdmin(MPTTModelAdmin):
-    list_display = ('title', 'breadcrumb')
-    prepopulated_fields = {'slug': ('title',)}
+class TaxonAdmin(MPTTModelAdmin):
+    list_display = ('name', 'breadcrumb')
+    #prepopulated_fields = {'slug': ('title',)}
     mptt_level_indent = 20
 
-    def queryset(self, request):
-        """Limit the list of categories according to user"""
-        return self.model._default_manager.choices(request.user)
-
-admin.site.register(Category, CategoryAdmin)
+admin.site.register(Taxon, TaxonAdmin)

taxonomy/models/taxon.py

 from django.utils.translation import ugettext_lazy as _
 from mptt.models import MPTTModel, TreeForeignKey
 
-from taxonomy.settings import BASETAXON_MIXIN, TAXONRANK_SEPARATOR, TAXONOMY_SITES_POLICY
+from taxonomy.settings import BASETAXON_MIXIN, TAXONRANK_SEPARATOR, TAXONOMY_SITES_POLICY, TAXONOMY_RANKED
 from taxonomy.utils import load_class, get_basemodel_mixin
 from taxonomy.models.taxonrank import TaxonRank
 
     #slug = models.SlugField()
 
     parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
-    rank = models.ForeignKey(TaxonRank)
+    if TAXONOMY_RANKED:
+        rank = models.ForeignKey(TaxonRank)
 
-    class MPTTMeta:
-        order_insertion_by = ['rank']
+    #class MPTTMeta:
+    #    order_insertion_by = ['rank']
 
     class Meta:
         app_label = 'taxonomy'
 
     def get_name(self):
         return self.pk
+    name = property(get_name)
 
     def _recurse_for_parents(self, obj):
         p_list = []

taxonomy/settings.py

 BASETAXON_MIXIN = getattr(settings, 'TAXONOMY_BASETAXON_MIXIN', None)
 BASETAXONRANK_MIXIN = getattr(settings, 'TAXONOMY_BASETAXONRANK_MIXIN', None)
 TAXONRANK_SEPARATOR = getattr(settings, 'TAXONOMY_TAXONRANK_SEPARATOR', None)
-TAXONOMY_SITES_POLICY = getattr(settings, 'TAXONOMY_SITES_POLICY', True) # Use choices 'FK' (default) or 'M2M'
+TAXONOMY_SITES_POLICY = getattr(settings, 'TAXONOMY_SITES_POLICY', None)
+TAXONOMY_RANKED = getattr(settings, 'TAXONOMY_RANKED', True)

taxonomy/utils/__init__.py

 
 from enum import enum
 from importer import load_class, get_basemodel_mixin
-from site_policy import FKSitePolicy, M2MSitePolicy, get_site_policy_model_mixin
+from site_policy import FKSitePolicy, M2MSitePolicy, get_site_policy_model_mixin
+from inject_app_defaults import inject_app_defaults

taxonomy/utils/inject_app_defaults.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+# \sa http://blog.yawd.eu/2011/how-to-keep-your-django-project-settings-organized/
+
+
+def inject_app_defaults(application):
+    """Inject an application's default settings"""
+    try:
+        __import__('%s.settings' % application)
+        import sys
+
+        # Import our defaults, project defaults, and project settings
+        _app_settings = sys.modules['%s.settings' % application]
+        _def_settings = sys.modules['django.conf.global_settings']
+        _settings = sys.modules['django.conf'].settings
+
+        # Add the values from the application.settings module
+        for _k in dir(_app_settings):
+            if _k.isupper():
+                # Add the value to the default settings module
+                setattr(_def_settings, _k, getattr(_app_settings, _k))
+
+                # Add the value to the settings, if not already present
+                if not hasattr(_settings, _k):
+                    setattr(_settings, _k, getattr(_app_settings, _k))
+    except ImportError:
+        # Silently skip failing settings modules
+        pass