###############################################################################
#
# Copyright (C) 2007-TODAY Tiny ERP Pvt Ltd. All Rights Reserved.
#
# $Id$
#
# Developed by Tiny (http://openerp.com) and Axelor (http://axelor.com).
#
# The OpenERP web client is distributed under the "OpenERP Public License".
# It's based on Mozilla Public License Version (MPL) 1.1 with following
# restrictions:
#
# - All names, links and logos of Tiny, OpenERP and Axelor must be
# kept as in original distribution without any changes in all software
# screens, especially in start-up page and the software header, even if
# the application source code has been changed or updated or code has been
# added.
#
# - All distributions of the software must keep source code with OEPL.
#
# - All integrations to any other software must keep source code with OEPL.
#
# If you need commercial licence to remove this kind of restriction please
# contact us.
#
# You can see the MPL licence at: http://www.mozilla.org/MPL/MPL-1.1.html
#
###############################################################################
import re
import cherrypy
import wikimarkup
from openobject import rpc
from openobject.widgets import CSSLink
from openerp.widgets import register_widget
from openerp.widgets.form import Text
_image = re.compile(r'img:(.*)\.(.*)', re.UNICODE)
_rss = re.compile(r'rss:(.*)\.(.*)', re.UNICODE)
_attach = re.compile(r'attach:(.*)\.(.*)', re.UNICODE)
_internalLinks = re.compile(r'\[\[.*\]\]', re.UNICODE)
_edit = re.compile(r'edit:(.*)\|(.*)', re.UNICODE)
_view = re.compile(r'view:(.*)\|(.*)', re.UNICODE)
class WikiParser(wikimarkup.Parser):
def parse(self, text, id):
text = text.replace(' ', 'n-b-s-p')
text = text.replace('&', 'n-a-m-p')
text = text.replace('&','&')
text = text.replace('n-b-s-p', ' ')
text = text.replace('n-a-m-p', '&')
text = text.replace('', '
', '')
text = wikimarkup.to_unicode(text)
text = self.strip(text)
text = super(WikiParser, self).parse(text)
text = self.addImage(text, id)
text = self.attachDoc(text, id)
text = self.recordLink(text)
text = self.viewRecordLink(text)
text = self.addInternalLinks(text)
#TODO : already implemented but we will implement it later after releasing the 5.0
#text = self.addRss(text, id)
return text
def viewRecordLink(self, text):
def record(path):
record = path.group().replace('view:','').split("|")
model = record[0]
text = record[1].replace('\r','').strip()
label = "View Record"
if len(record) > 2:
label = record[2]
proxy = rpc.RPCProxy(model)
ids = proxy.name_search(text, [], 'ilike', {})
if len(ids):
id = ids[0][0]
else:
try:
id = int(text)
except:
id = 0
return "[[/openerp/form/view?model=%s&id=%d | %s]]" % (model, id, label)
bits = _view.sub(record, text)
return bits
def addRss(self, text, id):
def addrss(path):
rssurl = path.group().replace('rss:','')
import rss.feedparser as feedparser
data = feedparser.parse(rssurl)
values = "')
text = text.replace('