Skip to content
Snippets Groups Projects
Commit 7d6ad783 authored by Thomas Uher's avatar Thomas Uher
Browse files

safety

parent 54a780a8
No related branches found
No related tags found
No related merge requests found
...@@ -85,6 +85,14 @@ class TaxonTree(models.Model): ...@@ -85,6 +85,14 @@ class TaxonTree(models.Model):
objects = TaxonTreeManager() objects = TaxonTreeManager()
def save(self, *args, **kwargs):
if self.is_root_taxon == False and not self.parent:
raise ValueError('non-root taxa require a parent')
super().save(*args, **kwargs)
def __str__(self): def __str__(self):
return self.taxon_latname return self.taxon_latname
......
####################################################################################################################
#
# IMPORT Algaebase.org
#
####################################################################################################################
from taxonomy.sources.TaxonSourceManager import (TaxonSourceManager, SourceTreeTaxon,
SourceSynonymTaxon, VernacularName, TreeCache)
from taxonomy.sources.algaebase.models import AlgaebaseTaxonTree, AlgaebaseTaxonSynonym, AlgaebaseTaxonLocale
import psycopg2, psycopg2.extras, os, csv
from html.parser import HTMLParser
# the CoL2019 uses language names like "English" -> use langcodes
import langcodes
DEBUG = False
# db interface for algaebase 2020 postgres db
algaebaseCon = psycopg2.connect(dbname="algaebase2019", user="localcosmos", password="localcosmos",
host="localhost", port="5432")
algaebaseCursor = algaebaseCon.cursor(cursor_factory = psycopg2.extras.DictCursor)
class AlgaebaseSourceTreeTaxon(SourceTreeTaxon):
TreeModel = AlgaebaseTaxonTree
def _get_source_object(self):
raise NotImplementedError('SourceTaxon subclasses need a _get_source_object method')
def _get_vernacular_names(self):
raise NotImplementedError('SourceTaxon subclasses need a _get_vernacular_names method')
def _get_synonyms(self):
raise NotImplementedError('SourceTaxon subclasses need a _get_synonyms method')
class AlgaebaseSourceSynonymTaxon(SourceSynonymTaxon):
pass
class AlgaebaseTreeCache(TreeCache):
SourceTreeTaxonClass = AlgaebaseSourceTreeTaxon
TaxonTreeModel = AlgaebaseTaxonTree
class AlgaebaseManager(TaxonSourceManager):
SourceTreeTaxonClass = AlgaebaseSourceTreeTaxon
SourceSynonymTaxonClass = AlgaebaseSourceSynonymTaxon
TaxonTreeModel = AlgaebaseTaxonTree
TaxonSynonymModel = AlgaebaseTaxonSynonym
TaxonLocaleModel = AlgaebaseTaxonLocale
TreeCacheClass = AlgaebaseTreeCache
def _get_root_source_taxa(self):
raise NotImplementedError('Tree Managers need a _get_root_source_taxa method')
def _get_children(self, source_taxon):
raise NotImplementedError('Tree Managers need a _get_children method')
'''
this function has to travel right and up until the next parent taxon which has not been climbed down
yet has been found
returns a source_taxon or None
EXAMPLE:
- source_taxon is a taxon without children
- the next sibling of source taxon might have children -> check all siblings first
- if no siblings have children, travel up
'''
def _get_next_sibling(self, source_taxon):
raise NotImplementedError('Tree Managers need a _get_next_sibling method')
# travel one up
def _get_parent(self, source_taxon):
raise NotImplementedError('Tree Managers need a _get_parent method')
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AlgaebaseConfig(AppConfig):
name = 'algaebase'
from django.db import models
from taxonomy.models import TaxonTree, TaxonSynonym, TaxonNamesView, TaxonLocale
class AlgaebaseTaxonTree(TaxonTree):
pass
class AlgaebaseTaxonSynonym(TaxonSynonym):
taxon = models.ForeignKey(AlgaebaseTaxonTree, on_delete=models.CASCADE, to_field='name_uuid')
class Meta:
unique_together = ('taxon', 'taxon_latname', 'taxon_author')
class AlgaebaseTaxonLocale(TaxonLocale):
taxon = models.ForeignKey(algaebaseTaxonTree, on_delete=models.CASCADE, to_field='name_uuid')
class Meta:
index_together = [
['taxon', 'language'],
]
'''
VIEWS
'''
class AlgaebaseTaxonNamesView(TaxonNamesView):
pass
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment