Commits

jgsogo  committed 053c75c Draft

concepto linneo

  • Participants
  • Parent commits 15e73d8

Comments (0)

Files changed (7)

 Django-Taxonomy
 ===============
 
-!! Proof of concept
+.. DANGER::
+   !! Proof of concept
 
 `Django-Taxonomy
 <https://bitbucket.org/jgsogo/django-taxonomy/>`_ provides a highly customizable hierarchical classification for

File linneo/__init__.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+
+from taxonomy.utils import inject_app_defaults
+inject_app_defaults('taxonomy.contrib.category_tree')

File linneo/fixtures/initial_data.json

+[
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 1,
+        "fields": {
+            "rank": "0",
+            "name": "Dominio",
+            "slug": "dominio",
+            "in_rank_order": "0"
+        }
+    },
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 2,
+        "fields": {
+            "rank": "0",
+            "name": "Reino",
+            "slug": "reino",
+            "in_rank_order": "1"
+        }
+    },
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 3,
+        "fields": {
+            "rank": "1",
+            "name": "Filo/division",
+            "slug": "filo-division",
+            "in_rank_order": "1"
+        }
+    },
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 4,
+        "fields": {
+            "rank": "2",
+            "name": "Clase",
+            "slug": "clase",
+            "in_rank_order": "1"
+        }
+    },
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 5,
+        "fields": {
+            "rank": "4",
+            "name": "Orden",
+            "slug": "orden",
+            "in_rank_order": "4"
+        }
+    },
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 6,
+        "fields": {
+            "rank": "7",
+            "name": "Familia",
+            "slug": "familia",
+            "in_rank_order": "3"
+        }
+    },
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 7,
+        "fields": {
+            "rank": "9",
+            "name": "Género",
+            "slug": "genero",
+            "in_rank_order": "0"
+        }
+    },
+    {
+        "model": "taxonomy.taxonrank",
+        "pk": 8,
+        "fields": {
+            "rank": "10",
+            "name": "Especie",
+            "slug": "especie",
+            "in_rank_order": "0"
+        }
+    }
+]

File linneo/managers.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+from taxonomy.managers import TaxonManager
+
+
+class DominioManager(TaxonManager):
+    def get_query_set(self):
+        return super(DominioManager, self).get_query_set().filter()

File linneo/mixins.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+from django.db import models
+
+class TaxonRankMixin(models.Model):
+    name = models.CharField(max_length=100)
+    slug = models.SlugField()
+
+    in_rank_order = models.IntegerField(default=0)
+
+    class Meta:
+        abstract = True
+
+
+class TaxonMixin(models.Model):
+    name = models.CharField(max_length=255)
+
+    class Meta:
+        abstract = True
+
+    def save(self, *args, **kwargs):
+        """ Only 'domains' can be orphans, everything else must be included in a supracategory """
+        if self.rank != '':
+            raise
+
+        """ Parent also must be in the same rank (parent.in_rank_order > self.in_rank_order) or in a higher rank """
+        super(TaxonMixin, self).save(*args, **kwargs)

File linneo/models.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+from django.db import models
+
+from taxonomy.models import Taxon
+
+
+class Dominio(Taxon):
+
+    class Meta:
+        proxy = True
+
+class Reino(Taxon):
+
+    class Meta:
+        proxy = True
+

File linneo/settings.py

+#!/usr/bin/env python
+# encoding: utf-8
+
+TAXONOMY_BASETAXONRANK_MIXIN = 'taxonomy.contrib.linneo.mixins.TaxonRankMixin'
+TAXONOMY_BASETAXON_MIXIN = 'taxonomy.contrib.linneo.mixins.TaxonMixin'