示例#1
0
文件: views.py 项目: IHLeanne/mayan
def document_page_navigation_last(request, document_page_id):
    check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
    view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)

    document_page = get_object_or_404(DocumentPage, pk=document_page_id)
    document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.document.documentpage_set.count())
    return HttpResponseRedirect(reverse(view, args=[document_page.pk]))
示例#2
0
文件: views.py 项目: IHLeanne/mayan
def document_page_navigation_previous(request, document_page_id):
    check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
    view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)

    document_page = get_object_or_404(DocumentPage, pk=document_page_id)
    if document_page.page_number <= 1:
        messages.warning(request, _(u'You are already at the first page of this document'))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', u'/'))
    else:
        document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number - 1)
        return HttpResponseRedirect(reverse(view, args=[document_page.pk]))
示例#3
0
文件: views.py 项目: IHLeanne/mayan
def document_page_navigation_next(request, document_page_id):
    check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
    view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)

    document_page = get_object_or_404(DocumentPage, pk=document_page_id)
    if document_page.page_number >= document_page.document.documentpage_set.count():
        messages.warning(request, _(u'There are no more pages in this document'))
        return HttpResponseRedirect(request.META.get('HTTP_REFERER', u'/'))
    else:
        document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number + 1)
        return HttpResponseRedirect(reverse(view, args=[document_page.pk]))
示例#4
0
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    # Don't fudge with the original global dictionary
    links_dict = links_dict.copy()

    query_string = urlparse.urlparse(request.get_full_path()).query or urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('overrided_object_links').resolve(context)
        if navigation_object_links:
            return [link for link in resolve_links(context, navigation_object_links, current_view, current_path, parsed_query_string)]
    except VariableDoesNotExist:
        pass

    try:
        """
        Check for and inject a temporary navigation dictionary
        """
        temp_navigation_links = Variable('temporary_navigation_links').resolve(context)
        if temp_navigation_links:
            links_dict.update(temp_navigation_links)
    except VariableDoesNotExist:
        pass

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    obj, object_name = get_navigation_object(context)

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links
示例#5
0
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    query_string = urlparse.urlparse(request.get_full_path()).query or urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('navigation_object_links').resolve(context)
        if navigation_object_links:
            return [link for link in resolve_links(context, navigation_object_links, current_view, current_path, parsed_query_string)]
    except VariableDoesNotExist:
        pass

    try:
        object_name = Variable('navigation_object_name').resolve(context)
    except VariableDoesNotExist:
        object_name = 'object'

    try:
        obj = Variable(object_name).resolve(context)
    except VariableDoesNotExist:
        obj = None

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links
示例#6
0
def _get_object_navigation_links(context, menu_name=None, links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    query_string = urlparse.urlparse(request.get_full_path()).query or urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('overrided_object_links').resolve(context)
        if navigation_object_links:
            return [link for link in resolve_links(context, navigation_object_links, current_view, current_path, parsed_query_string)]
    except VariableDoesNotExist:
        pass

    try:
        object_name = Variable('navigation_object_name').resolve(context)
    except VariableDoesNotExist:
        object_name = 'object'

    try:
        obj = Variable(object_name).resolve(context)
    except VariableDoesNotExist:
        obj = None

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path, parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links
示例#7
0
    def render(self, context):
        request = Variable('request').resolve(context)
        current_path = request.META['PATH_INFO']
        current_view = resolve_to_name(current_path)

        all_menu_links = [entry.get('link', {}) for entry in top_menu_entries]
        menu_links = resolve_links(context, all_menu_links, current_view, current_path)

        for index, link in enumerate(top_menu_entries):
            children_views = link.get('children_views', [])
            if current_view in children_views:
                menu_links[index]['active'] = True

            children_path_regex = link.get('children_path_regex', [])
            for child_path_regex in children_path_regex:
                if re.compile(child_path_regex).match(current_path.lstrip('/')):
                    menu_links[index]['active'] = True

        context['menu_links'] = menu_links
        return ''
示例#8
0
    def render(self, context):
        request = Variable('request').resolve(context)
        current_path = request.META['PATH_INFO']
        current_view = resolve_to_name(current_path)

        all_menu_links = [entry.get('link', {}) for entry in top_menu_entries]
        menu_links = resolve_links(context, all_menu_links, current_view, current_path)

        for index, link in enumerate(top_menu_entries):
            children_views = link.get('children_views', [])
            if current_view in children_views:
                menu_links[index]['active'] = True

            children_path_regex = link.get('children_path_regex', [])
            for child_path_regex in children_path_regex:
                if re.compile(child_path_regex).match(current_path.lstrip('/')):
                    menu_links[index]['active'] = True

        context['menu_links'] = menu_links
        return ''
示例#9
0
文件: views.py 项目: IHLeanne/mayan
def transform_page(request, document_page_id, zoom_function=None, rotation_function=None):
    check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
    view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)

    document_page = get_object_or_404(DocumentPage, pk=document_page_id)
    # Get the query string from the referer url
    query = urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
    # Parse the query string and get the zoom value
    # parse_qs return a dictionary whose values are lists
    zoom = int(urlparse.parse_qs(query).get('zoom', ['100'])[0])
    rotation = int(urlparse.parse_qs(query).get('rotation', ['0'])[0])

    if zoom_function:
        zoom = zoom_function(zoom)

    if rotation_function:
        rotation = rotation_function(rotation)

    return HttpResponseRedirect(
        u'?'.join([
            reverse(view, args=[document_page.pk]),
            urlencode({'zoom': zoom, 'rotation': rotation})
        ])
    )
示例#10
0
 def render(self, context):
     request = Variable('request').resolve(context)
     view_name = resolve_to_name(request.META['PATH_INFO'])
     context[self.var_name] = sidebar_templates.get(view_name, [])
     return ''
示例#11
0
 def render(self, context):
     request = Variable('request').resolve(context)
     view_name = resolve_to_name(request.META['PATH_INFO'])
     context[self.var_name] = sidebar_templates.get(view_name, [])
     return ''
示例#12
0
def _get_object_navigation_links(context,
                                 menu_name=None,
                                 links_dict=object_navigation):
    request = Variable('request').resolve(context)
    current_path = request.META['PATH_INFO']
    current_view = resolve_to_name(current_path)
    context_links = []

    # Don't fudge with the original global dictionary
    links_dict = links_dict.copy()

    query_string = urlparse.urlparse(
        request.get_full_path()).query or urlparse.urlparse(
            request.META.get('HTTP_REFERER', u'/')).query
    parsed_query_string = urlparse.parse_qs(query_string)

    try:
        """
        Override the navigation links dictionary with the provided
        link list
        """
        navigation_object_links = Variable('overrided_object_links').resolve(
            context)
        if navigation_object_links:
            return [
                link for link in
                resolve_links(context, navigation_object_links, current_view,
                              current_path, parsed_query_string)
            ]
    except VariableDoesNotExist:
        pass

    try:
        """
        Check for and inject a temporary navigation dictionary
        """
        temp_navigation_links = Variable('temporary_navigation_links').resolve(
            context)
        if temp_navigation_links:
            links_dict.update(temp_navigation_links)
    except VariableDoesNotExist:
        pass

    try:
        links = links_dict[menu_name][current_view]['links']
        for link in resolve_links(context, links, current_view, current_path,
                                  parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    obj, object_name = get_navigation_object(context)

    try:
        links = links_dict[menu_name][type(obj)]['links']
        for link in resolve_links(context, links, current_view, current_path,
                                  parsed_query_string):
            context_links.append(link)
    except KeyError:
        pass

    return context_links