Revision 058b6ec7 snf-astakos-app/astakos/im/templatetags/astakos_tags.py

b/snf-astakos-app/astakos/im/templatetags/astakos_tags.py
39 39
from django.core.urlresolvers import resolve
40 40
from django.conf import settings
41 41
from django.template import TemplateSyntaxError, Variable
42
from django.utils.translation import ugettext as _
43
from django.template.loader import render_to_string
44
from django.template import RequestContext
45
from django.core.urlresolvers import reverse
46
from django.utils.safestring import mark_safe
42 47

  
43 48
register = template.Library()
44 49

  
......
207 212

  
208 213
    return "%s%s%s" % (provider.add_url, joinchar, urllib.urlencode(attrs))
209 214

  
215

  
216
EXTRA_CONTENT_MAP = {
217
    'confirm_text': '<textarea name="reason"></textarea>'
218
}
219

  
220
CONFIRM_LINK_PROMPT_MAP = {
221
    'project_modification_cancel': _('Are you sure you want to dismiss this '
222
                                     'project ?'),
223
    'project_app_cancel': _('Are you sure you want to cancel this project ?'),
224
    'project_app_approve': _('Are you sure you want to approve this '
225
                             'project ?'),
226
    'project_app_deny': _('Are you sure you want to deny this project ? '
227
                          '<br /><br />You '
228
                          'may optionally provide denial reason in the '
229
                          'following field: <br /><br /><textarea class="deny_reason" '
230
                          'name="reason"></textarea>'),
231
    'project_app_dismiss': _('Are you sure you want to dismiss this '
232
                             'project ?'),
233
    'project_app_join': _('Are you sure you want to join this project ?'),
234
    'project_app_leave': _('Are you sure you want to leave this project ?'),
235
}
236

  
237

  
238
@register.tag(name="confirm_link")
239
@basictag(takes_context=True)
240
def confirm_link(context, title, prompt='', url=None, urlarg=None,
241
                 extracontent='',
242
                 confirm_prompt=None,
243
                 inline=True,
244
                 template="im/table_rich_link_column.html"):
245

  
246
    urlargs = None
247
    if urlarg:
248
        urlargs = (urlarg,)
249

  
250
    if CONFIRM_LINK_PROMPT_MAP.get(prompt, None):
251
        prompt = mark_safe(CONFIRM_LINK_PROMPT_MAP.get(prompt))
252

  
253
    url = reverse(url, args=urlargs)
254
    title = _(title)
255
    tpl_context = RequestContext(context.get('request'))
256
    tpl_context.update({
257
        'col': {
258
            'method': 'POST',
259
            'cancel_prompt': 'CANCEL',
260
            'confirm_prompt': confirm_prompt or title
261
        },
262
        'inline': inline,
263
        'url': url,
264
        'action': title,
265
        'prompt': prompt,
266
        'extra_form_content': EXTRA_CONTENT_MAP.get(extracontent, ''),
267
        'confirm': True
268
    })
269

  
270
    content = render_to_string(template, tpl_context)
271
    return content
272

  

Also available in: Unified diff