add substitution variables for formdata
This commit is contained in:
parent
927e26e78f
commit
32584ce182
|
@ -23,6 +23,7 @@ from quixote import get_request, get_publisher
|
|||
|
||||
from qommon.storage import StorableObject
|
||||
import qommon.misc
|
||||
from qommon.substitution import Substitutions
|
||||
|
||||
from anonylink import AnonymityLink
|
||||
|
||||
|
@ -201,6 +202,61 @@ class FormData(StorableObject):
|
|||
def get_as_dict(self):
|
||||
return get_dict_with_varnames(self.formdef.fields, self.data)
|
||||
|
||||
def get_substitution_variables(self):
|
||||
d = {
|
||||
'form_receipt_date': qommon.strftime.strftime(qommon.misc.date_format(), self.receipt_time),
|
||||
'form_receipt_time': qommon.strftime.strftime('%H:%M', self.receipt_time),
|
||||
'form_number': str(self.id),
|
||||
'form_url': self.get_url(),
|
||||
'form_status_url': '%sstatus' % self.get_url(),
|
||||
'form_details': self.formdef.get_detailed_email_form(self, self.get_url()),
|
||||
}
|
||||
|
||||
user = self.get_user()
|
||||
if user:
|
||||
for k, v in user.get_substitution_variables().items():
|
||||
d['form_'+k] = v
|
||||
|
||||
data = get_dict_with_varnames(self.formdef.fields, self.data)
|
||||
for k, v in data.items():
|
||||
d['form_'+k] = v
|
||||
|
||||
for k, v in self.get_as_dict().items():
|
||||
d['form_'+k] = v
|
||||
|
||||
if self.evolution and self.evolution[-1].comment:
|
||||
d['form_comment'] = self.evolution[-1].comment
|
||||
else:
|
||||
d['form_comment'] = ''
|
||||
|
||||
d['form_status'] = self.get_status_label()
|
||||
|
||||
d['form_previous_status'] = ''
|
||||
if self.evolution:
|
||||
for evolution in reversed(self.evolution):
|
||||
if evolution.status and evolution.status != self.status:
|
||||
d['form_previous_status'] = self.get_status_label(evolution.status)
|
||||
break
|
||||
|
||||
return d
|
||||
|
||||
def get_substitution_variables_list(cls):
|
||||
variables = []
|
||||
# we can't advertise fields, as this is a metaclass that will be used
|
||||
# in FormDef.data_class() to create a real class
|
||||
for field in []: # cls.formdef.fields:
|
||||
# we only advertise fields with a varname, as they can be
|
||||
# considered stable
|
||||
if field.varname:
|
||||
variables.append((
|
||||
_('Form'), 'form_var_'+field.varname,
|
||||
_('Form Field: %s') % field.label))
|
||||
user_variables = get_publisher().user_class.get_substitution_variables_list()
|
||||
for cat, name, comment in user_variables:
|
||||
variables.append((_('Form'), 'form_%s'%name, ''))
|
||||
return variables
|
||||
get_substitution_variables_list = classmethod(get_substitution_variables_list)
|
||||
|
||||
# don't pickle _formdef cache
|
||||
def __getstate__(self):
|
||||
odict = self.__dict__
|
||||
|
@ -212,3 +268,13 @@ class FormData(StorableObject):
|
|||
self.__dict__ = dict
|
||||
self._formdef = None
|
||||
|
||||
|
||||
Substitutions.register('form_receipt_date', category=N_('Form'), comment=N_('Form Receipt Date'))
|
||||
Substitutions.register('form_receipt_time', category=N_('Form'), comment=N_('Form Receipt Time'))
|
||||
Substitutions.register('form_number', category=N_('Form'), comment=N_('Form Number'))
|
||||
Substitutions.register('form_details', category=N_('Form'), comment=N_('Form Details'))
|
||||
Substitutions.register('form_url', category=N_('Form'), comment=N_('Form URL'))
|
||||
Substitutions.register('form_status_url', category=N_('Form'), comment=N_('Form Status URL'))
|
||||
Substitutions.register('form_user_display_name', category=N_('Form'), comment=N_('Form Submitter Name'))
|
||||
Substitutions.register('form_user_email', category=N_('Form'), comment=N_('Form Submitter Email'))
|
||||
Substitutions.register_dynamic_source(FormData)
|
||||
|
|
|
@ -44,6 +44,7 @@ class FormStatusPage(Directory):
|
|||
template.html_top(title = title, default_org = _('Forms'))
|
||||
|
||||
def __init__(self, formdef, filled):
|
||||
get_publisher().substitutions.feed(filled)
|
||||
self.formdef = formdef
|
||||
self.filled = filled
|
||||
for q in self._q_extra_exports:
|
||||
|
|
Loading…
Reference in New Issue