Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staff emails field #388

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions resources/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from ..models.utils import generate_id
from munigeo.models import Municipality
from rest_framework.authtoken.admin import Token
from respa_admin.forms import RespaMultiEmailField

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -144,12 +145,23 @@ def hard_delete_resources(modeladmin, request, queryset):
hard_delete_resources.short_description = _('Hard delete selected resources')


class ResourceAdminForm(forms.ModelForm):
resource_staff_emails = RespaMultiEmailField(
required=False,
label=_('E-mail addresses for client correspondence')
)
class Meta:
model = Resource
fields = '__all__'

class ResourceAdmin(PopulateCreatedAndModifiedMixin, CommonExcludeMixin,
TranslationAdmin, HttpsFriendlyGeoAdmin):
default_lon = 2478871 # Central Railway Station in EPSG:3857
default_lat = 8501259
default_zoom = 12

form = ResourceAdminForm

list_display = ('name', 'unit', '_public', 'reservable', 'soft_deleted')
list_filter = ('unit', '_public', 'reservable', 'soft_deleted')
list_select_related = ('unit',)
Expand Down
3 changes: 3 additions & 0 deletions resources/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ def get_db_prep_value(self, value, connection, prepared):
if isinstance(value, list):
return '\n'.join(value)
return value

def from_db_value(self, value, *args, **kwargs):
return self.to_python(value)
3 changes: 3 additions & 0 deletions respa_admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ def to_python(self, value):
if isinstance(value, list):
return value
return [val.strip() for val in value.splitlines() if val]

def prepare_value(self, value):
return self.to_python(value)


class ResourceForm(forms.ModelForm):
Expand Down
Loading