Exemple #1
0
    def render(self, context):
        page = template.Variable(self.page).resolve(context)
        url = template.Variable(self.base_url).resolve(context)
        url = PAGE_RE.sub("", url)
        url = url.replace("%", "%%")
        
        pages = page.paginator.num_pages

        page_link = u'<a class="pagelink %%s" href="%s%spage=%%s"><img src="%s%%s" alt=""></a>' % (url, url.find("?") == -1 and  "?" or "&", settings.STATIC_URL)
        first = getattr(settings, "PAGE_ICON_FIRST", "peavy/img/first.png")
        prev = getattr(settings, "PAGE_ICON_PREV", "peavy/img/prev.png")
        next = getattr(settings, "PAGE_ICON_NEXT", "peavy/img/next.png")
        last = getattr(settings, "PAGE_ICON_LAST", "peavy/img/last.png")

        output = ""
        if page.paginator.num_pages > 1:
            output = u'<div class="page_navigator">%s: ' % _(u"Page")
            output += page_link % ("first", 1, first)
            if page.has_previous:
                output += page_link % ("previous", page.previous_page_number(), prev)
            output += " %s / %s " % (page.number, pages)
            if page.has_next:
                output += page_link % ("next", page.next_page_number(), next)
            output += page_link % ("last", pages, last)                
            output += "</div>"
        return mark_safe(fix_ampersands(output))
Exemple #2
0
def parse_email_list(value):
    """
    Parse a list of comma-seperated email addresses into
    a list of mailto: links.

    Splitting a string of email addresses should return a list:

    >>> unicode(parse_email_list('[email protected], [email protected]'))
    u'<a href="mailto:[email protected]">[email protected]</a>, <a href="mailto:[email protected]">[email protected]</a>'

    Parsing a non-string should return the input value, rather than fail:
    
    >>> parse_email_list(['*****@*****.**', '*****@*****.**'])
    ['*****@*****.**', '*****@*****.**']
    
    Null input values should pass through silently:
    
    >>> parse_email_list('')
    ''

    >>> parse_email_list(None)


    """
    if value and isinstance(value, (types.StringType,types.UnicodeType)): # testing for 'value' being true isn't necessary; it's a fast-out route
        addrs = re.split(", ?", value)
        ret = []
        for addr in addrs:
            (name, email) = parseaddr(addr)
            if not(name):
                name = email
            ret.append('<a href="mailto:%s">%s</a>' % ( fix_ampersands(email), escape(name) ))
        return mark_safe(", ".join(ret))
    else:
        return value
def shrink(value, arg=None):
    """
    Reduce the length of given string. Replace ' and ' word with ampersand,
    cut the string if it's longer than given length.
    """
    if arg is None:
        length = 50
    else:
        try:
            length = int(arg)
        except ValueError:
            return u""
    value = value.replace(u" and ", u" & ")
    if len(value) > length:
        value = value[:length] + u"&hellip;"
    return mark_safe(fix_ampersands(value));
    def render(self, context):
        page = template.Variable(self.page).resolve(context)
        url = template.Variable(self.base_url).resolve(context)
        parsed_url = urlparse.urlparse(url)
        data = urlparse.parse_qs(parsed_url[4])

        offset = 1 + self.window_size * ((page.number - 1) // self.window_size)
        last_page = min(page.paginator.num_pages + 1,
                        offset + self.window_size)

        li_template = '<li class="%s">%s</li>'
        link_template = '<a href="%s">%s</a>'

        output = ''

        # support multiple paginators per template
        page_param = 'page'
        for component in self.id_components:
            page_param += '_%s' % template.Variable(component).resolve(context)

        if page.paginator.num_pages > 0:
            output = '<ul class="page_navigator">'
            if page.has_previous():
                data[page_param] = page.previous_page_number()
                link = link_template % (self.make_page_url(parsed_url,
                                                           data), '')
                output += li_template % ('prev', link)

            for i in range(offset, last_page):
                link = i
                if page.number != i:
                    data[page_param] = i
                    link = link_template % (self.make_page_url(
                        parsed_url, data), i)
                output += li_template % (
                    'current %s' %
                    (i == last_page - 1 and ' final' or ''), link)

            if page.has_next():
                data[page_param] = page.next_page_number()
                link = link_template % (self.make_page_url(parsed_url,
                                                           data), '')
                output += li_template % ('next', link)

            output += "</ul>"
        return mark_safe(fix_ampersands(output))
Exemple #5
0
def parse_email_list(value):
    """
    Parse a list of comma-seperated email addresses into
    a list of mailto: links.

    Splitting a string of email addresses should return a list:

    >>> unicode(parse_email_list('[email protected], [email protected]'))
    u'<a href="mailto:[email protected]">[email protected]</a>, <a href="mailto:[email protected]">[email protected]</a>'

    Parsing a non-string should return the input value, rather than fail:
    
    >>> parse_email_list(['*****@*****.**', '*****@*****.**'])
    ['*****@*****.**', '*****@*****.**']
    
    Null input values should pass through silently:
    
    >>> parse_email_list('')
    ''

    >>> parse_email_list(None)


    """
    if value and isinstance(
            value, (types.StringType, types.UnicodeType)
    ):  # testing for 'value' being true isn't necessary; it's a fast-out route
        addrs = re.split(", ?", value)
        ret = []
        for addr in addrs:
            (name, email) = emailutils.parseaddr(addr)
            if not (name):
                name = email
            ret.append('<a href="mailto:%s">%s</a>' %
                       (fix_ampersands(email), escape(name)))
        return ", ".join(ret)
    else:
        return value
Exemple #6
0
def fix_ampersands_filter(value):
    """Replaces ampersands with ``&amp;`` entities."""
    return fix_ampersands(value)
def fix_ampersands(value):
    """Replaces ampersands with ``&amp;`` entities."""
    from django.utils.html import fix_ampersands
    return fix_ampersands(value)
Exemple #8
0
def fix_ampersands(value):
    """Replaces ampersands with ``&amp;`` entities."""
    from django.utils.html import fix_ampersands
    return fix_ampersands(value)
Exemple #9
0
def fix_ampersands_filter(value):
    """Replaces ampersands with ``&amp;`` entities."""
    return fix_ampersands(value)
def _escape_text_nodes(tag):
    for i, child in enumerate(tag.contents):
        if isinstance(child, NavigableString):
            t = fix_ampersands(child)
            t = t.replace('<', '&lt;').replace('>', '&gt;')
            child.parent.contents[i] = NavigableString(t)
Exemple #11
0
 def item_description(self, item):
     return mark_safe(fix_ampersands(item.announce))
Exemple #12
0
def _escape_text_nodes(tag):
    for i, child in enumerate(tag.contents):
        if isinstance(child, NavigableString):
            t = fix_ampersands(child)
            t = t.replace('<', '&lt;').replace('>', '&gt;')
            child.parent.contents[i] = NavigableString(t)
Exemple #13
0
 def get_prep_value(self, value):
     "Standardize encoding, entities, etc."
     value = super(HTMLField, self).get_prep_value(value)
     if isinstance(value, basestring):
         value = html.fix_ampersands(unescape_entities(value))
     return value