wcs/wcs/carddata.py

72 lines
2.4 KiB
Python

# w.c.s. - web application for online forms
# Copyright (C) 2005-2019 Entr'ouvert
#
# 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 2 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 quixote import get_publisher
from wcs.formdata import FormData
from .qommon import _
class CardData(FormData):
def get_formdef(self):
if self._formdef:
return self._formdef
from .carddef import CardDef
id = self._names.split('-', 1)[1]
try:
self._formdef = CardDef.get_by_urlname(id)
except KeyError:
self._formdef = None
return self._formdef
formdef = property(get_formdef)
def get_data_source_structured_item(self, digest_key='default'):
if self.digests is None:
if digest_key == 'default':
summary = _('Digest (default) not defined')
else:
summary = _('Digest (custom view "%s") not defined') % digest_key.replace('custom-view:', '')
get_publisher().record_error(summary, formdata=self)
item = {
'id': self.id,
'text': (self.digests or {}).get(digest_key) or '',
}
for field in self.formdef.get_all_fields():
if not field.varname:
continue
value = self.data and self.data.get(field.id)
if isinstance(value, str):
item[field.varname] = value
return item
def get_display_label(self, digest_key='default'):
return (self.digests or {}).get(digest_key) or self.get_display_name()
def get_author_qualification(self):
return None
def get_file_base_url(self):
return '%sdownload' % self.get_api_url()
def just_created(self):
super().just_created()
if self.submission_agent_id:
self.evolution[0].who = self.submission_agent_id