Example #1
0
def resolve_links(context, links, current_view, current_path, parsed_query_string=None):
    """
    Express a list of links from definition to final values
    """
    context_links = []
    for link in links:
        # Check to see if link has conditional display
        if 'condition' in link:
            condition_result = link['condition'](context)
        else:
            condition_result = True
        
        if condition_result:
            new_link = copy.copy(link)
            try:
                args, kwargs = resolve_arguments(context, link.get('args', {}))
            except VariableDoesNotExist:
                args = []
                kwargs = {}

            if 'view' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['view'] == current_view

                try:
                    if kwargs:
                        new_link['url'] = reverse(link['view'], kwargs=kwargs)
                    else:
                        new_link['url'] = reverse(link['view'], args=args)
                        if link.get('keep_query', False):
                            new_link['url'] = urlquote(new_link['url'], parsed_query_string)
                except NoReverseMatch, err:
                    new_link['url'] = '#'
                    new_link['error'] = err
            elif 'url' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['url'] == current_path
                    
                if kwargs:
                    new_link['url'] = link['url'] % kwargs
                else:
                    new_link['url'] = link['url'] % args
                    if link.get('keep_query', False):
                        new_link['url'] = urlquote(new_link['url'], parsed_query_string)
            else:
                new_link['active'] = False
                
            if 'conditional_disable' in link:
                new_link['disabled'] = link['conditional_disable'](context)
            else:
                new_link['disabled'] = False
                            
            context_links.append(new_link)
Example #2
0
def resolve_links(context, links, current_view, current_path, parsed_query_string=None):
    """
    Express a list of links from definition to final values
    """
    context_links = []
    for link in links:
        # Check to see if link has conditional display
        if 'condition' in link:
            condition_result = link['condition'](context)
        else:
            condition_result = True

        if condition_result:
            new_link = copy.copy(link)
            try:
                args, kwargs = resolve_arguments(context, link.get('args', {}))
            except VariableDoesNotExist:
                args = []
                kwargs = {}

            if 'view' in link:
                new_link['active'] = link['view'] == current_view

                try:
                    if kwargs:
                        new_link['url'] = reverse(link['view'], kwargs=kwargs)
                    else:
                        new_link['url'] = reverse(link['view'], args=args)
                        if link.get('keep_query', False):
                            new_link['url'] = urlquote(new_link['url'], parsed_query_string)
                except NoReverseMatch, err:
                    new_link['url'] = '#'
                    new_link['error'] = err
            elif 'url' in link:
                new_link['active'] = link['url'] == current_path
                if kwargs:
                    new_link['url'] = link['url'] % kwargs
                else:
                    new_link['url'] = link['url'] % args
                    if link.get('keep_query', False):
                        new_link['url'] = urlquote(new_link['url'], parsed_query_string)
            else:
                new_link['active'] = False

            if 'conditional_disable' in link:
                new_link['disabled'] = link['conditional_disable'](context)
            else:
                new_link['disabled'] = False

            context_links.append(new_link)
Example #3
0
    def done(self, request, form_list):
        if self.multiple:
            view = 'upload_document_from_local'
        else:
            view = 'upload_document'

        if self.document_type:
            self.query_dict['document_type_id'] = self.document_type.pk

        url = urlquote(reverse(view), self.query_dict)
        return HttpResponseRedirect(url)
Example #4
0
def document_print(request, document_id):
    check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])

    document = get_object_or_404(Document, pk=document_id)

    RecentDocument.objects.add_document_for_user(request.user, document)

    post_redirect = None
    next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', post_redirect or document.get_absolute_url())))

    new_window_url = None
    html_redirect = None

    if request.method == 'POST':
        form = PrintForm(request.POST)
        if form.is_valid():
            hard_copy_arguments = {}
            # Get page range
            if form.cleaned_data['page_range']:
                hard_copy_arguments['page_range'] = form.cleaned_data['page_range']

            # Compute page width and height
            if form.cleaned_data['custom_page_width'] and form.cleaned_data['custom_page_height']:
                page_width = form.cleaned_data['custom_page_width']
                page_height = form.cleaned_data['custom_page_height']
            elif form.cleaned_data['page_size']:
                page_width, page_height = dict(PAGE_SIZE_DIMENSIONS)[form.cleaned_data['page_size']]

            # Page orientation
            if form.cleaned_data['page_orientation'] == PAGE_ORIENTATION_LANDSCAPE:
                page_width, page_height = page_height, page_width

            hard_copy_arguments['page_width'] = page_width
            hard_copy_arguments['page_height'] = page_height

            new_url = [reverse('document_hard_copy', args=[document_id])]
            if hard_copy_arguments:
                new_url.append(urlquote(hard_copy_arguments))

            new_window_url = u'?'.join(new_url)
            new_window_url_name = u'document_hard_copy'
            #html_redirect = next
            #messages.success(request, _(u'Preparing document hardcopy.'))
    else:
        form = PrintForm()

    return render_to_response('generic_form.html', {
        'form': form,
        'object': document,
        'title': _(u'print: %s') % document,
        'next': next,
        'html_redirect': html_redirect if html_redirect else html_redirect,
        'new_window_url': new_window_url if new_window_url else new_window_url
    }, context_instance=RequestContext(request))
Example #5
0
def resolve_links(context, links, current_view, current_path, parsed_query_string=None):
    """
    Express a list of links from definition to final values
    """
    context_links = []
    for link in links:
        # Check to see if link has conditional display
        if 'condition' in link:
            condition_result = link['condition'](context)
        else:
            condition_result = True

        if condition_result:
            new_link = copy.copy(link)
            try:
                args, kwargs = resolve_arguments(context, link.get('args', {}))
            except VariableDoesNotExist:
                args = []
                kwargs = {}

            if 'view' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['view'] == current_view

                try:
                    if kwargs:
                        new_link['url'] = reverse(link['view'], kwargs=kwargs)
                    else:
                        new_link['url'] = reverse(link['view'], args=args)
                        if link.get('keep_query', False):
                            new_link['url'] = urlquote(new_link['url'], parsed_query_string)
                except NoReverseMatch, err:
                    new_link['url'] = '#'
                    new_link['error'] = err
            elif 'url' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['url'] == current_path

                if kwargs:
                    new_link['url'] = link['url'] % kwargs
                else:
                    new_link['url'] = link['url'] % args
                    if link.get('keep_query', False):
                        new_link['url'] = urlquote(new_link['url'], parsed_query_string)
            else:
                new_link['active'] = False

            if 'conditional_highlight' in link:
                new_link['active'] = link['conditional_highlight'](context)

            if 'conditional_disable' in link:
                new_link['disabled'] = link['conditional_disable'](context)
            else:
                new_link['disabled'] = False

            if current_view in link.get('children_views', []):
                new_link['active'] = True

            for child_url_regex in link.get('children_url_regex', []):
                if re.compile(child_url_regex).match(current_path.lstrip('/')):
                    new_link['active'] = True

            for children_view_regex in link.get('children_view_regex', []):
                if re.compile(children_view_regex).match(current_view):
                    new_link['active'] = True

            for cls in link.get('children_classes', []):
                obj, object_name = get_navigation_object(context)
                if type(obj) == cls or obj == cls:
                    new_link['active'] = True

            context_links.append(new_link)
Example #6
0
    def done(self, request, form_list):
        if self.document_type:
            self.query_dict['document_type_id'] = self.document_type.pk

        url = urlquote(reverse('upload_interactive'), self.query_dict)
        return HttpResponseRedirect(url)
def resolve_links(context, links, current_view, current_path, parsed_query_string=None):
    """
    Express a list of links from definition to final values
    """

    context_links = []
    for link in links:
        # Check to see if link has conditional display
        if 'condition' in link:
            condition_result = link['condition'](context)
        else:
            condition_result = True

        if condition_result:
            new_link = copy.copy(link)
            try:
                args, kwargs = resolve_arguments(context, link.get('args', {}))
            except VariableDoesNotExist:
                args = []
                kwargs = {}

            if 'view' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['view'] == current_view

                try:
                    if kwargs:
                        new_link['url'] = reverse(link['view'], kwargs=kwargs)
                    else:
                        new_link['url'] = reverse(link['view'], args=args)
                        if link.get('keep_query', False):
                            try:
                                for key in link.get('remove_from_query', []):
                                    del parsed_query_string[key]
                            except KeyError:
                                # We were asked to remove a key not found in the
                                # query string, that is not fatal
                                pass

                            new_link['url'] = urlquote(new_link['url'], parsed_query_string)
                except NoReverseMatch as exception:
                    new_link['url'] = '#'
                    new_link['error'] = exception
            elif 'url' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['url'] == current_path

                if kwargs:
                    new_link['url'] = link['url'] % kwargs
                else:
                    new_link['url'] = link['url'] % args
                    if link.get('keep_query', False):
                        try:
                            for key in link.get('remove_from_query', []):
                                del parsed_query_string[key]
                        except KeyError:
                            # We were asked to remove a key not found in the
                            # query string, that is not fatal
                            pass

                        new_link['url'] = urlquote(new_link['url'], parsed_query_string)
            else:
                new_link['active'] = False

            if 'conditional_highlight' in link:
                new_link['active'] = link['conditional_highlight'](context)

            if 'conditional_disable' in link:
                new_link['disabled'] = link['conditional_disable'](context)
            else:
                new_link['disabled'] = False

            context_links.append(new_link)
    return context_links
Example #8
0
def resolve_links(context,
                  links,
                  current_view,
                  current_path,
                  parsed_query_string=None):
    """
    Express a list of links from definition to final values
    """
    context_links = []
    for link in links:
        # Check to see if link has conditional display
        if 'condition' in link:
            condition_result = link['condition'](context)
        else:
            condition_result = True

        if condition_result:
            new_link = copy.copy(link)
            try:
                args, kwargs = resolve_arguments(context, link.get('args', {}))
            except VariableDoesNotExist:
                args = []
                kwargs = {}

            if 'view' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['view'] == current_view

                try:
                    if kwargs:
                        new_link['url'] = reverse(link['view'], kwargs=kwargs)
                    else:
                        new_link['url'] = reverse(link['view'], args=args)
                        if link.get('keep_query', False):
                            print 'parsed_query_string', parsed_query_string
                            new_link['url'] = urlquote(new_link['url'],
                                                       parsed_query_string)
                except NoReverseMatch, err:
                    new_link['url'] = '#'
                    new_link['error'] = err
            elif 'url' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['url'] == current_path

                if kwargs:
                    new_link['url'] = link['url'] % kwargs
                else:
                    new_link['url'] = link['url'] % args
                    if link.get('keep_query', False):
                        new_link['url'] = urlquote(new_link['url'],
                                                   parsed_query_string)
            else:
                new_link['active'] = False

            if 'conditional_highlight' in link:
                new_link['active'] = link['conditional_highlight'](context)

            if 'conditional_disable' in link:
                new_link['disabled'] = link['conditional_disable'](context)
            else:
                new_link['disabled'] = False

            if current_view in link.get('children_views', []):
                new_link['active'] = True

            for child_url_regex in link.get('children_url_regex', []):
                if re.compile(child_url_regex).match(current_path.lstrip('/')):
                    new_link['active'] = True

            for children_view_regex in link.get('children_view_regex', []):
                if re.compile(children_view_regex).match(current_view):
                    new_link['active'] = True

            for cls in link.get('children_classes', []):
                obj, object_name = get_navigation_object(context)
                if type(obj) == cls or obj == cls:
                    new_link['active'] = True

            context_links.append(new_link)
Example #9
0
def resolve_links(context,
                  links,
                  current_view,
                  current_path,
                  parsed_query_string=None):
    """
    Express a list of links from definition to final values
    """

    context_links = []
    for link in links:
        # Check to see if link has conditional display
        if 'condition' in link:
            condition_result = link['condition'](context)
        else:
            condition_result = True

        if condition_result:
            new_link = copy.copy(link)
            try:
                args, kwargs = resolve_arguments(context, link.get('args', {}))
            except VariableDoesNotExist:
                args = []
                kwargs = {}

            if 'view' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['view'] == current_view

                try:
                    if kwargs:
                        new_link['url'] = reverse(link['view'], kwargs=kwargs)
                    else:
                        new_link['url'] = reverse(link['view'], args=args)
                        if link.get('keep_query', False):
                            try:
                                for key in link.get('remove_from_query', []):
                                    del parsed_query_string[key]
                            except KeyError:
                                # We were asked to remove a key not found in the
                                # query string, that is not fatal
                                pass

                            new_link['url'] = urlquote(new_link['url'],
                                                       parsed_query_string)
                except NoReverseMatch as exception:
                    new_link['url'] = '#'
                    new_link['error'] = exception
            elif 'url' in link:
                if not link.get('dont_mark_active', False):
                    new_link['active'] = link['url'] == current_path

                if kwargs:
                    new_link['url'] = link['url'] % kwargs
                else:
                    new_link['url'] = link['url'] % args
                    if link.get('keep_query', False):
                        try:
                            for key in link.get('remove_from_query', []):
                                del parsed_query_string[key]
                        except KeyError:
                            # We were asked to remove a key not found in the
                            # query string, that is not fatal
                            pass

                        new_link['url'] = urlquote(new_link['url'],
                                                   parsed_query_string)
            else:
                new_link['active'] = False

            if 'conditional_highlight' in link:
                new_link['active'] = link['conditional_highlight'](context)

            if 'conditional_disable' in link:
                new_link['disabled'] = link['conditional_disable'](context)
            else:
                new_link['disabled'] = False

            context_links.append(new_link)
    return context_links