Commits

jgsogo committed e8e9616 Draft

proxy models for linneo major ranks

Comments (0)

Files changed (5)

linneo/fixtures/initial_data.json

             "rank": "0",
             "name": "Domain",
             "slug": "domain",
-            "in_rank_order": "0"
+            "in_rank_order": "0",
+            "compulsory" : "true"
         }
     },
     {
             "rank": "0",
             "name": "Kingdom",
             "slug": "kingdom",
-            "in_rank_order": "1"
+            "in_rank_order": "1",
+            "compulsory" : "true"
         }
     },
     {
             "rank": "1",
             "name": "Phylum/Division",
             "slug": "phylum-division",
-            "in_rank_order": "1"
+            "in_rank_order": "1",
+            "compulsory" : "true"
         }
     },
     {
             "rank": "3",
             "name": "Class",
             "slug": "class",
-            "in_rank_order": "1"
+            "in_rank_order": "1",
+            "compulsory" : "true"
         }
     },
     {
             "rank": "7",
             "name": "Order",
             "slug": "order",
-            "in_rank_order": "6"
+            "in_rank_order": "6",
+            "compulsory" : "true"
         }
     },
     {
             "rank": "9",
             "name": "Family",
             "slug": "family",
-            "in_rank_order": "8"
+            "in_rank_order": "8",
+            "compulsory" : "true"
         }
     },
     {
             "rank": "11",
             "name": "Genus",
             "slug": "genus",
-            "in_rank_order": "0"
+            "in_rank_order": "0",
+            "compulsory" : "true"
         }
     },
     {
             "rank": "12",
             "name": "Species",
             "slug": "species",
-            "in_rank_order": "1"
+            "in_rank_order": "1",
+            "compulsory" : "true"
         }
     },
     {

linneo/managers.py

 # encoding: utf-8
 
 from taxonomy.managers import TaxonManager
+from taxonomy.models import TaxonRank
 
+class MajorTaxonomicRankManager(TaxonManager):
+    def __init__(self, rank, slug):
+        super(MajorTaxonomicRankManager, self).__init__()
+        self.__rank__rank = rank
+        self.__slug = slug
+        self.__rank = None
 
-class DominioManager(TaxonManager):
+    def _get_rank(self):
+        try:
+            self.__rank = TaxonRank.objects.get(rank=self.__rank__rank, slug=self.__slug)
+        except TaxonRank.ObjectDoesNotExist:
+            raise ValueError("Couldn't find a taxon rank named %s (rank=%s)." %\
+                             (self.__rank__rank, self.__slug))
+        except TaxonRank.MultipleObjectsReturned:
+            raise ValueError("There are more than one taxon rank named %s (rank=%s)." %\
+                             (self.__rank__rank, self.__slug))
+
     def get_query_set(self):
-        return super(DominioManager, self).get_query_set().filter()
+        if not self.__rank:
+            self._get_rank()
+        return super(MajorTaxonomicRankManager, self).get_query_set().filter(rank=self.__rank)
     slug = models.SlugField()
 
     in_rank_order = models.IntegerField(default=0)
+    compulsory = models.BooleanField(default=False)
 
     class Meta:
         abstract = True
 from django.db import models
 
 from taxonomy.models import Taxon
+from linneo.managers import MajorTaxonomicRankManager
 
-
-class Dominio(Taxon):
-
+class DomainTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(0, "domain")
     class Meta:
         proxy = True
 
-class Reino(Taxon):
-
+class KingdomTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(0, "kingdom")
     class Meta:
         proxy = True
 
+class PhylumTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(1, "phylum-division")
+    class Meta:
+        proxy = True
+
+class ClassTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(3, "class")
+    class Meta:
+        proxy = True
+
+class OrderTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(7, "order")
+    class Meta:
+        proxy = True
+
+class FamilyTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(9, "family")
+    class Meta:
+        proxy = True
+
+class GenusTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(11, "genus")
+    class Meta:
+        proxy = True
+
+class SpeciesTaxon(Taxon):
+    objects = MajorTaxonomicRankManager(12, "species")
+    class Meta:
+        proxy = True
+

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'
+TAXONOMY_BASETAXONRANK_MIXIN = 'linneo.mixins.TaxonRankMixin'
+TAXONOMY_BASETAXON_MIXIN = 'linneo.mixins.TaxonMixin'