Пример #1
0
def convert_text(value):
    """
    Return text with only <br/> intact, all other tags stripped.
    """
    # Essentially, convert newline to br, strip tags turns br into newlines and
    # removes everything else, nl2br turns it into br again :)
    try:
        return nl2br(strip_tags(nl2br(value)))
    except:
        return colander.null
Пример #2
0
def transform_text(request, text, html=True, tag_func=tags2links):
    if html:
        text = auto_link(text)
        text = nl2br(text)
        text = tag_func(unicode(text))
        text = at_userid_link(request, text)
    return text
Пример #3
0
def transform_text(request, text, html=True, tag_func=tags2links):
    if html:
        text = auto_link(text)
        text = nl2br(text)
        text = tag_func(unicode(text))
        text = at_userid_link(request, text)
    return text
Пример #4
0
def user_basic_profile(context, request, va, **kw):
    response = dict(
        about_me = nl2br(context.get_field_value('about_me')),
        api = kw['api'],
        context = context,
    )
    return render('../templates/snippets/user_basic_info.pt', response, request = request)
Пример #5
0
def render_proposal_text(request,
                         proposal,
                         tag_func=tags2links,
                         diff_brief=True):
    """ Render a proposal as a diff or as the original text. """
    if not IProposal.providedBy(proposal):
        raise TypeError("%s is not a proposal" % proposal)
    if proposal.diff_text_para is None:
        # This is a regular proposal without the diff functions active
        return request.transform_text(proposal.text, tag_func=tag_func)
    else:
        ai = request.agenda_item
        if ai is None:
            ai = proposal.__parent__
        diff_text = IDiffText(ai)
        paragraphs = diff_text.get_paragraphs()
        try:
            original = paragraphs[proposal.diff_text_para]
        except (TypeError, IndexError):
            # Simply abort
            return request.transform_text(proposal.text, tag_func=tag_func)
        text = ""
        if proposal.diff_text_leadin:
            text += tag_func(proposal.diff_text_leadin) + "\n\n"
        text += diff_text(original, proposal.text, brief=diff_brief)
        return nl2br(text).unescape()
Пример #6
0
 def transform(self, text):
     """ Transform text. Base for any tags is current context. """
     text = sanitize(text)
     text = auto_link(text, link='urls')
     text = nl2br(text)
     text = tags2links(unicode(text))
     text = at_userid_link(text, self.context, self.request)
     return text
Пример #7
0
def rte_content(text,bbcode=True):
    if not text:
        return u''
    if bbcode:
        text = bbcode.render(unicode(text.encode('utf8'),'utf8'))
    text = literal(text)
    text = nl2br(text)
    return text
Пример #8
0
def user_basic_profile(context, request, va, **kw):
    response = dict(
        about_me=nl2br(context.about_me),
        context=context,
    )
    return render('voteit.core:templates/snippets/user_basic_info.pt',
                  response,
                  request=request)
Пример #9
0
 def __call__(self):
     paragraphs = self.diff_text.get_paragraphs()
     try:
         original = paragraphs[self.context.diff_text_para]
     except (TypeError, IndexError):
         raise HTTPNotFound("No diff for this context")
     text = self.diff_text(original, self.context.text)
     return {'text': nl2br(text).unescape()}
Пример #10
0
 def transform(self, text):
     """ Transform text. Base for any tags is current context. """
     text = sanitize(text)
     text = auto_link(text, link='urls')
     text = nl2br(text)
     text = tags2links(unicode(text))
     text = at_userid_link(text, self.context, self.request)
     return text
Пример #11
0
 def __call__(self):
     paragraphs = self.diff_text.get_paragraphs()
     try:
         original = paragraphs[self.context.diff_text_para]
     except (TypeError, IndexError):
         raise HTTPNotFound("No diff for this context")
     text = self.diff_text(original, self.context.text)
     return {'text': nl2br(text).unescape()}
Пример #12
0
def user_basic_profile(context, request, va, **kw):
    response = dict(
        about_me=nl2br(context.get_field_value('about_me')),
        api=kw['api'],
        context=context,
    )
    return render('../templates/snippets/user_basic_info.pt',
                  response,
                  request=request)
Пример #13
0
def create_feed_object(request):
    settings = IFeedSettings(request.meeting, {})
    te = request.localizer.translate
    fg = FeedGenerator()
    fg.id(rss_feed_url(request, token=settings.get('token', None))) #Mandatory for atom feeds
    fg.title(request.meeting.title)
    fg.description(settings.get('description_text', te(_("No description"))))
    #fg.author({'name': 'XXXX', 'email': '*****@*****.**'})
    fg.link(href=request.resource_url(request.meeting), rel='alternate')
    #fg.icon('http://ex.com/icon.jpg')
    #fg.logo('http://ex.com/logo.jpg')
    #fg.rights('cc-by')
    #fg.subtitle('This is a cool feed!')
    fg.link(href=rss_feed_url(request, token=settings.get('link_token')), rel='self')
    fg.language(request.localizer.locale_name)
    # Fetch objects we want to interact with
    limit = settings.get('limit', 50)
    type_names = list(settings.get('type_names', ()))
    items = get_feed_items(request, type_names, limit=limit)
    # Create feed entries
    for obj in items:
        # Newest first is already the case in items
        fe = fg.add_entry(order='append')
        author_txt = _cleanup_txt(request.creators_info(obj.creator, portrait=False, no_tag=True))
        # Needed?
        fe.id(request.resource_url(obj))
        fe.published(obj.created)
        if obj.type_name == 'Poll':
            fe.title(te(_("${state} poll: ${title}",
                          mapping={'state': te(voteit_mf(obj.current_state_title(request))),
                                   'title': obj.title})))
            fe.content()
            #fe.summary()
        if obj.type_name == 'DiscussionPost':
            fe.title(te(_("${name} added a discussion post", mapping={'name': author_txt})))
            fe.content(nl2br(obj.text))
            #fe.summary()
        if obj.type_name == 'Proposal':
            fe.title(te(_("${name} added a proposal", mapping={'name': author_txt})))
            fe.content(request.render_proposal_text(obj, tag_func=lambda x: x))
            #fe.summary()
        fe.link(href=request.resource_url(obj), rel='alternate')
        fe.author(name=author_txt)
    return fg
Пример #14
0
def render_proposal_text(request, proposal, tag_func=tags2links):
    """ Render a proposal as a diff or as the original text. """
    if not IProposal.providedBy(proposal):
        raise TypeError("%s is not a proposal" % proposal)
    if proposal.diff_text_para is None:
        #This is a regular proposal without the diff functions active
        return request.transform_text(proposal.text, tag_func=tag_func)
    else:
        ai = request.agenda_item
        if ai is None:
            ai = proposal.__parent__
        diff_text = IDiffText(ai)
        paragraphs = diff_text.get_paragraphs()
        try:
            original = paragraphs[proposal.diff_text_para]
        except (TypeError, IndexError):
            #Simply abort
            return request.transform_text(proposal.text, tag_func=tag_func)
        text = ""
        if proposal.diff_text_leadin:
            text += tag_func(proposal.diff_text_leadin) + "\n\n"
        text += diff_text(original, proposal.text, brief=True)
        return nl2br(text).unescape()
Пример #15
0
 def nl2br(self, text):
     return unicode(nl2br(text))
Пример #16
0
 def appstruct(self):
     return {
         'text': nl2br(self.staged_data['text']).unescape(),
         'leadin': self.staged_data['leadin'],
         'diff_text': nl2br(self.get_staged_diff()).unescape()
     }
Пример #17
0
def _transform_text(text):
    text = auto_link(text)
    text = nl2br(text)
    return tags2links(unicode(text))
Пример #18
0
        pre = matched_dict['pre']
        url = u"?%s" % urlencode({'tag': tag.encode('utf-8')})
        return u"""%s<a href="%s" class="tag">#%s</a>""" % (pre, url, tag)

    return re.sub(TAG_PATTERN, handle_match, text)


def strip_and_truncate(text, limit=200):
    try:
        text = sanitize(text)
    except Exception, e:
        #FIXME: Logg unrecoverable error
        #This is a bad exception that should never happen, if we translate it it will be hard to search in the source code
        return u"Unrecoverable error: could not truncate text"
    if len(text) > limit:
        text = u"%s<...>" % nl2br(text[:limit])
    return nl2br(text)


def move_object(obj, new_parent):
    """ Move an object to a new location. """
    name = obj.__name__
    if name in new_parent:
        raise ValueError("Already exist")
    old_parent = obj.__parent__
    new_obj = deepcopy(obj)
    del old_parent[name]
    new_parent[name] = new_obj
    return new_obj

Пример #19
0
def test_nl2br():
    eq_(u'A B<br />\nC D<br />\n<br />\nE F', nl2br("A B\nC D\r\n\r\nE F"))
Пример #20
0
def test_nl2br3():
    eq_(u'<strike>W</strike><br />\nThe W',
        nl2br(literal("<strike>W</strike>\nThe W")))
Пример #21
0
def test_nl2br2():
    eq_(u'&lt;strike&gt;W&lt;/strike&gt;<br />\nThe W',
        nl2br("<strike>W</strike>\nThe W"))
Пример #22
0
 def appstruct(self):
     return {'text': nl2br(self.staged_data['text']).unescape(),
             'leadin': self.staged_data['leadin'],
             'diff_text': nl2br(self.get_staged_diff()).unescape()}
Пример #23
0
 def format_text(self, text):
     text = sanitize(text)
     text = auto_link(text)
     return nl2br(text)
Пример #24
0
        matched_dict = matchobj.groupdict()
        tag = matched_dict['tag']
        pre = matched_dict['pre']
        url = u"?%s" % urlencode({'tag': tag.encode('utf-8')})
        return u"""%s<a href="%s" class="tag">#%s</a>""" % (pre, url, tag)
    return re.sub(TAG_PATTERN, handle_match, text)

def strip_and_truncate(text, limit=200):
    try:
        text = sanitize(text)
    except Exception, e:
        #FIXME: Logg unrecoverable error
        #This is a bad exception that should never happen, if we translate it it will be hard to search in the source code
        return u"Unrecoverable error: could not truncate text"
    if len(text) > limit:
        text = u"%s<...>" % nl2br(text[:limit])
    return nl2br(text)

def move_object(obj, new_parent):
    """ Move an object to a new location. """
    name = obj.__name__
    if name in new_parent:
        raise ValueError("Already exist")
    old_parent = obj.__parent__
    new_obj = deepcopy(obj)
    del old_parent[name]
    new_parent[name] = new_obj
    return new_obj

def send_email(subject, recipients, html, sender = None, plaintext = None, request = None, send_immediately = False, **kw):
    """ Send an email to users. This also checks the required settings and translates
Пример #25
0
def user_basic_profile(context, request, va, **kw):
    response = dict(
        about_me = nl2br(context.about_me),
        context = context,
    )
    return render('voteit.core:templates/snippets/user_basic_info.pt', response, request = request)