Source code for geonode.monitoring.fields

#########################################################################
#
# Copyright (C) 2020 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################


from django.db import models

from geonode.monitoring.forms import MultiEmailField as MultiEmailFormField


[docs] class MultiEmailField(models.Field):
[docs] description = "A multi e-mail field stored as a multi-lines text"
[docs] def formfield(self, **kwargs): # This is a fairly standard way to set up some defaults # while letting the caller override them. defaults = {"form_class": MultiEmailFormField} defaults.update(kwargs) return super().formfield(**defaults)
[docs] def from_db_value(self, value, expression, connection, context): if value is None: return [] return value.splitlines()
[docs] def get_db_prep_value(self, value, connection, prepared=False): if isinstance(value, str): return value elif isinstance(value, list): return "\n".join(value)
[docs] def to_python(self, value): if not value: return [] if isinstance(value, list): return value return value.splitlines()
[docs] def get_internal_type(self): return "TextField"