wcs.session_user.diff
formdata.py (copie de travail) | ||
---|---|---|
224 | 224 | |
225 | 225 |
user = self.get_user() |
226 | 226 |
if user: |
227 |
for k, v in user.get_substitution_variables().items(): |
|
228 |
d['form_'+k] = v |
|
227 |
d.update(user.get_substitution_variables(prefix='form_')) |
|
229 | 228 | |
230 | 229 |
data = get_dict_with_varnames(self.formdef.fields, self.data) |
231 | 230 |
for k, v in data.items(): |
... | ... | |
266 | 265 |
variables.append(( |
267 | 266 |
_('Form'), 'form_var_'+field.varname, |
268 | 267 |
_('Form Field: %s') % field.label)) |
269 |
user_variables = get_publisher().user_class.get_substitution_variables_list() |
|
270 |
for cat, name, comment in user_variables: |
|
271 |
variables.append((_('Form'), 'form_%s'%name, '')) |
|
268 |
if True: |
|
269 |
# TODO: do this only if form.user exists (think about the "hash" patch) |
|
270 |
variables.append((_('Form'), 'form_user', _('Form Submitter'))) |
|
271 |
variables.append((_('Form'), 'form_user_display_name', _('Form Submitter Name'))) |
|
272 |
variables.append((_('Form'), 'form_user_email', _('Form Submitter Email'))) |
|
273 |
user_variables = get_publisher().user_class.get_substitution_variables_list(prefix='form_') |
|
274 |
for cat, name, comment in user_variables: |
|
275 |
variables.append((_('Form'), name, _('Form Submitter Field'))) |
|
272 | 276 |
return variables |
273 | 277 |
get_substitution_variables_list = classmethod(get_substitution_variables_list) |
274 | 278 | |
... | ... | |
291 | 295 |
Substitutions.register('form_url', category=N_('Form'), comment=N_('Form URL')) |
292 | 296 |
Substitutions.register('form_uri', category=N_('Form'), comment=N_('Form URI')) |
293 | 297 |
Substitutions.register('form_status_url', category=N_('Form'), comment=N_('Form Status URL')) |
294 |
Substitutions.register('form_user_display_name', category=N_('Form'), comment=N_('Form Submitter Name')) |
|
295 |
Substitutions.register('form_user_email', category=N_('Form'), comment=N_('Form Submitter Email')) |
|
298 |
#Substitutions.register('form_user', category=N_('Form'), comment=N_('Form Submitter')) |
|
299 |
#Substitutions.register('form_user_display_name', category=N_('Form'), comment=N_('Form Submitter Name')) |
|
300 |
#Substitutions.register('form_user_email', category=N_('Form'), comment=N_('Form Submitter Email')) |
|
296 | 301 |
Substitutions.register_dynamic_source(FormData) |
users.py (copie de travail) | ||
---|---|---|
124 | 124 |
return users_with_role |
125 | 125 |
get_users_with_role = classmethod(get_users_with_role) |
126 | 126 | |
127 |
def get_substitution_variables(self): |
|
127 |
def get_substitution_variables(self, prefix='session_'):
|
|
128 | 128 |
d = { |
129 |
'user': self, |
|
130 |
'user_display_name': self.display_name, |
|
131 |
'user_email': self.email, |
|
129 |
prefix+'user': self,
|
|
130 |
prefix+'user_display_name': self.display_name,
|
|
131 |
prefix+'user_email': self.email,
|
|
132 | 132 |
} |
133 | 133 |
formdef = self.get_formdef() |
134 | 134 |
if formdef: |
135 | 135 |
from formdata import get_dict_with_varnames |
136 | 136 |
data = get_dict_with_varnames(formdef.fields, self.form_data) |
137 | 137 |
for k, v in data.items(): |
138 |
d['user_'+k] = v |
|
138 |
d[prefix+'user_'+k] = v
|
|
139 | 139 |
return d |
140 | 140 | |
141 |
def get_substitution_variables_list(cls): |
|
141 |
def get_substitution_variables_list(cls, prefix='session_'):
|
|
142 | 142 |
formdef = cls.get_formdef() |
143 | 143 |
if not formdef: |
144 | 144 |
return [] |
... | ... | |
148 | 148 |
# considered stable |
149 | 149 |
if field.varname: |
150 | 150 |
variables.append(( |
151 |
_('User'), 'user_var_'+field.varname, |
|
152 |
_('User Field: %s') % field.label)) |
|
151 |
_('User'), prefix+'user_var_'+field.varname,
|
|
152 |
_('Session User Field: %s') % field.label))
|
|
153 | 153 |
return variables |
154 | 154 |
get_substitution_variables_list = classmethod(get_substitution_variables_list) |
155 | 155 | |
156 |
Substitutions.register('user', category=N_('User'), comment=N_('User'))
|
|
157 |
Substitutions.register('user_display_name', category=N_('User'), comment=N_('User Display Name'))
|
|
158 |
Substitutions.register('user_email', category=N_('User'), comment=N_('User Email'))
|
|
156 |
Substitutions.register('session_user', category=N_('User'), comment=N_('Session User'))
|
|
157 |
Substitutions.register('session_user_display_name', category=N_('User'), comment=N_('Session User Display Name'))
|
|
158 |
Substitutions.register('session_user_email', category=N_('User'), comment=N_('Session User Email'))
|
|
159 | 159 |
Substitutions.register_dynamic_source(User) |