Source code for journals.converters

__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"


from django.db.utils import ProgrammingError


[docs]class JournalDOILabelConverter: def __init__(self): try: from journals.models import Journal self.regex = "|".join([j.doi_label for j in Journal.objects.all()]) except ProgrammingError: self.regex = "SciPost"
[docs] def to_python(self, value): from journals.models import Journal try: return Journal.objects.get(doi_label=value).doi_label except Journal.DoesNotExist: return ValueError return value
[docs] def to_url(self, value): return value
[docs]class IssueDOILabelConverter: """ Converter for journal issue DOI labels. """ def __init__(self): try: from journals.models import Journal self.regex = "|".join([j.doi_label for j in Journal.objects.all()]) except ProgrammingError: self.regex = "SciPost" self.regex = "(" + self.regex + ")" + r"\.[0-9]+(\.[0-9]+)?"
[docs] def to_python(self, value): from journals.models import Publication try: return Publication.objects.get(doi_label=value).doi_label except Publication.DoesNotExist: return ValueError return value
[docs] def to_url(self, value): return value
[docs]class PublicationDOILabelConverter: """ Converter for publication DOI labels. """ def __init__(self): try: from journals.models import Journal self.regex = "|".join([j.doi_label for j in Journal.objects.all()]) except ProgrammingError: self.regex = "SciPost" self.regex = "(" + self.regex + ")" + r"\.[0-9]+(\.[0-9]+(\.[0-9]+)?)?"
[docs] def to_python(self, value): from journals.models import Publication try: return Publication.objects.get(doi_label=value).doi_label except Publication.DoesNotExist: return ValueError return value
[docs] def to_url(self, value): return value