Esempio n. 1
0
def paginate(page, adjacent=2):
    numpages = page.paginator.num_pages
    # Don't paginate if there is only one page
    if numpages <= 1:
        return []

    chunkstart = page.number - adjacent
    chunkend = page.number + adjacent
    ellipsis_pre = True
    ellipsis_post = True

    if chunkstart <= 2:
        ellipsis_pre = False
        chunkstart = 1
        chunkend = max(chunkend, adjacent * 2)

    if chunkend >= (numpages - 1):
        ellipsis_post = False
        chunkend = numpages
        chunkstart = min(chunkstart, numpages - (adjacent * 2) + 1)
    if chunkstart <= 2:
        ellipsis_pre = False

    chunkstart = max(chunkstart, 1)
    chunkend = min(chunkend, numpages)

    def create_page_nav(page_idx):
        return PaginationNav(page_idx, is_current=page_idx == page.number)

    # create page navs in 'chunk' (i.e. middle range)
    pages = [
        create_page_nav(page_idx)
        for page_idx in range(chunkstart, chunkend + 1)
    ]

    # insert first element and ellipsis if applicable
    if ellipsis_pre:
        pages.insert(0, PaginationNav(display='...'))
        pages.insert(0, create_page_nav(1))

    # append last element and ellipsis if applicable
    if ellipsis_post:
        pages.append(PaginationNav(display='...'))
        pages.append(create_page_nav(page.paginator.num_pages))

    # determine whether we need a 'previous' link and build it
    if page.has_previous():
        pages.insert(
            0, PaginationNav(page.previous_page_number(), safe('Previous')))

    # determine whether we need a 'next' link and build it
    if page.has_next():
        pages.append(PaginationNav(page.next_page_number(), safe('Next')))

    return pages
def paginate(page, adjacent=2):
    numpages = page.paginator.num_pages
    # Don't paginate if there is only one page
    if numpages <= 1:
        return []

    chunkstart = page.number - adjacent
    chunkend = page.number + adjacent
    ellipsis_pre = True
    ellipsis_post = True

    if chunkstart <= 2:
        ellipsis_pre = False
        chunkstart = 1
        chunkend = max(chunkend, adjacent * 2)

    if chunkend >= (numpages - 1):
        ellipsis_post = False
        chunkend = numpages
        chunkstart = min(chunkstart, numpages - (adjacent * 2) + 1)
    if chunkstart <= 2:
        ellipsis_pre = False

    chunkstart = max(chunkstart, 1)
    chunkend = min(chunkend, numpages)

    def create_page_nav(page_idx):
        return PaginationNav(page_idx, is_current=page_idx == page.number)

    # create page navs in 'chunk' (i.e. middle range)
    pages = [create_page_nav(page_idx)
             for page_idx in range(chunkstart, chunkend + 1)]

    # insert first element and ellipsis if applicable
    if ellipsis_pre:
        pages.insert(0, PaginationNav(display='...'))
        pages.insert(0, create_page_nav(1))

    # append last element and ellipsis if applicable
    if ellipsis_post:
        pages.append(PaginationNav(display='...'))
        pages.append(create_page_nav(page.paginator.num_pages))

    # determine whether we need a 'previous' link and build it
    if page.has_previous():
        pages.insert(0, PaginationNav(page.previous_page_number(),
                     safe('Previous')))

    # determine whether we need a 'next' link and build it
    if page.has_next():
        pages.append(PaginationNav(page.next_page_number(),
                     safe('Next')))

    return pages
def dojo_sort(request, display='Name', value='title', default=None):
    field = 'o'
    icon = '<i class="fa fa-sort'
    title = 'Click to sort '
    if field in request.GET:
        if value in request.GET[field]:
            if request.GET[field].startswith('-'):
                icon += '-desc'
                title += 'ascending'
            else:
                value = '-' + value
                icon += '-asc'
                title += 'descending'
        else:
            title += 'ascending'
    elif default:
        icon += '-' + default
        if default == 'asc':
            value = '-' + value
            title += 'descending'
        else:
            title += 'ascending'
    else:
        title += 'ascending'

    icon += ' dd-sort"></i>'
    dict_ = request.GET.copy()
    dict_[field] = value
    link = '<a title="' + title + '" href="?' + dict_.urlencode(
    ) + '">' + display + '&nbsp;' + icon + '</a>'
    return safe(link)
Esempio n. 4
0
def dojo_sort(request, display='Name', value='title', default=None):
    field = 'o'
    icon = '<i class="fa fa-sort'
    title = 'Click to sort '
    if field in request.GET:
        if value in request.GET[field]:
            if request.GET[field].startswith('-'):
                icon += '-desc'
                title += 'ascending'
            else:
                value = '-' + value
                icon += '-asc'
                title += 'descending'
        else:
            title += 'ascending'
    elif default:
        icon += '-' + default
        if default == 'asc':
            value = '-' + value
            title += 'descending'
        else:
            title += 'ascending'
    else:
        title += 'ascending'

    icon += ' dd-sort"></i>'
    dict_ = request.GET.copy()
    dict_[field] = value
    link = '<a title="' + title + '" href="?' + dict_.urlencode() + '">' + display + '&nbsp;' + icon + '</a>'
    return safe(link)
def query_string_as_hidden(context):
    request = context['request']
    query_string = request.META['QUERY_STRING']
    inputs = ''
    if query_string:
        parameters = query_string.split('&')
        for param in parameters:
            parts = param.split('=')
            if len(parts) == 2:
                inputs += "<input type='hidden' name='" + escape(parts[0]) + "' value='" + escape(parts[1]) + "'/>"
            else:
                inputs += "<input type='hidden' name='" + escape(parts[0]) + "' value=''/>"
    return safe(inputs)
Esempio n. 6
0
def query_string_as_hidden(context):
    request = context['request']
    query_string = request.META['QUERY_STRING']
    inputs = ''
    if query_string:
        parameters = query_string.split('&')
        for param in parameters:
            parts = param.split('=')
            if len(parts) == 2:
                inputs += "<input type='hidden' name='" + escape(parts[0]) + "' value='" + escape(parts[1]) + "'/>"
            else:
                inputs += "<input type='hidden' name='" + escape(parts[0]) + "' value=''/>"
    return safe(inputs)
 def render(self, context):
     user = Variable(self.user).resolve(context)
     profile = user.get_profile()
     html = ''
     group_template = loader.get_template('profile/group.html')
     for group in profile.get_groups():
         fields_html = ''
         """
         import pdb
         pdb.set_trace()
         """
         for field in group.get_fields_for(user, empty=self.empty):
             fields_html += render_field(field, self.editable, user,
                                         self.change)
         group_context = Context({'legend': group.name,
                                  'fields': safe(fields_html)})
         html += group_template.render(group_context)
     return html
     # --- Borrar de acá en más --- #
     """