ext/rest.py
branchtls-sprint
changeset 1643 59c5cec05bbd
parent 1447 a1ca676294f0
child 1977 606923dff11b
equal deleted inserted replaced
1642:12a98b17fb05 1643:59c5cec05bbd
    74                             **options)], []
    74                             **options)], []
    75 
    75 
    76 register_canonical_role('eid', eid_reference_role)
    76 register_canonical_role('eid', eid_reference_role)
    77 
    77 
    78 
    78 
    79 def card_reference_role(role, rawtext, text, lineno, inliner,
       
    80                        options={}, content=[]):
       
    81     text = text.strip()
       
    82     try:
       
    83         wikiid, rest = text.split(u':', 1)
       
    84     except:
       
    85         wikiid, rest = text, text
       
    86     context = inliner.document.settings.context
       
    87     cardrset = context.req.execute('Card X WHERE X wikiid %(id)s',
       
    88                                    {'id': wikiid})
       
    89     if cardrset:
       
    90         ref = cardrset.get_entity(0, 0).absolute_url()
       
    91     else:
       
    92         schema = context.schema
       
    93         if schema.eschema('Card').has_perm(context.req, 'add'):
       
    94             ref = context.req.build_url('view', vid='creation', etype='Card', wikiid=wikiid)
       
    95         else:
       
    96             ref = '#'
       
    97     set_classes(options)
       
    98     return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref,
       
    99                             **options)], []
       
   100 
       
   101 register_canonical_role('card', card_reference_role)
       
   102 
       
   103 
       
   104 def winclude_directive(name, arguments, options, content, lineno,
    79 def winclude_directive(name, arguments, options, content, lineno,
   105                        content_offset, block_text, state, state_machine):
    80                        content_offset, block_text, state, state_machine):
   106     """Include a reST file as part of the content of this reST file.
    81     """Include a reST file as part of the content of this reST file.
   107 
    82 
   108     same as standard include directive but using config.locate_doc_resource to
    83     same as standard include directive but using config.locate_doc_resource to