How can I implement this in a view. I am not sure how to call that markmin
action to be used instead of MARKMIN helper.
Dana srijeda, 8. svibnja 2013. 17:23:24 UTC+2, korisnik Massimo Di Pierro
napisao je:
>
> There is an "official" syntax for this.
>
> @{component:controller/function/args}
>
> To enable this and enable OEMBED I do:
>
> def markmin(body):
> from gluon.contrib.autolinks import expand_one
> def component(text):
> items = text.split('/')
> controller, function, args = items[0], items[1], items[2:]
> return LOAD(controller, function, args=args, ajax=True).xml()
> return MARKMIN(body, url=True, environment={'component':component},
> autolinks=lambda link: expand_one(link, {})).xml()
> db.table.field.represent = lambda v,r: markmin(v or '')
>
> This is done automatically by auth.wiki()
>
> Massimo
>
> On Wednesday, 8 May 2013 09:16:21 UTC-5, villas wrote:
>>
>> For anyone interested in my monologue...
>
> Function to my previous ideas, a function as follows could handle both
>> internal and external URLs.
>> I also included a simple check for allowed domains:
>>
>> def __component(text):
>> if text and text.lower().strip().startswith('http'):
>> from urlparse import urlparse
>> allowed_domains = [
>> 'www.domain1.com',
>> 'www.domain2.com',
>> ]
>> if allowed_domains and not any(i in urlparse(text)[1] for i
>> inallowed_domains
>> ):
>> return H1('domain not allowed').xml()
>> else:
>> return LOAD(url=text, ajax=True).xml()
>> else:
>> items = text.split('/')
>> controller, function, args = items[0], items[1], items[2:]
>> return LOAD(controller, function, args=args, ajax=True).xml()
>>
>> MARKMIN(mytext,url=True,extra=dict(component = lambda value: __component(
>> value)))
>>
>> In our Markmin we can then include...
>>
>> ``http://www.domain1.com/app/mycont/myfunc/arg1``:component<http://www.domain1.com/app/mycont/myfunc/arg1:component>
>>
>> and/or
>>
>> ``mycont/myfunc/arg1``:component
>>
>> .
>> Maybe someone has other better, or more flexibile, ideas?
>>
>>
>> On Wednesday, May 8, 2013 2:09:28 AM UTC+1, villas wrote:
>>>
>>> I can do something like this...
>>> mytext = """
>>>
>>> ``default/get_cms_article/4``:component
>>>
>>> """
>>>
>>> def __component(text):
>>> items = text.split('/')
>>> controller, function, args = items[0], items[1], items[2:]
>>> return LOAD(controller, function, args=args, ajax=True).xml()
>>>
>>> MARKMIN_ENV = dict(
>>> component = lambda value: __component(value)
>>> )
>>>
>>> MARKMIN(mytext,url=True,extra=MARKMIN_ENV)
>>>
>>>
>>> This uses LOAD. What is recommended for loading components from other
>>> domains? I think I have used JSON for that in the past, but maybe there
>>> are other ways, I am not sure that I am using the currently recommended
>>> methods for Markmin.
>>>
>>> Thanks!
>>>
>>>
>>>
>>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.