Beispiel #1
0
def getNotAuthorizedRedirect(request, post):

    # check project access first
    if post.project.active == False:
        return getProjectNotActiveRedirect(request, post.project)
    elif post.project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, post.project)

    # user is NOT authorized
    if not userCanView(request.user, post):
        if not request.user.is_authenticated():
            return HttpResponseRedirect(
                reverse('login') + "?next=%s" % request.path)
        else:
            messages = [
                'This page is only viewable to members of %s.' %
                post.project.short_name,
                '<a href="/membership/request/%s">Request to join this project</a>.'
                % post.project.short_name
            ]
            return render(
                request, 'cog/common/message.html', {
                    'mytitle': 'Page Access Restricted',
                    'project': post.project,
                    'messages': messages
                })

    # user is authorized, return no redirect
    else:
        return None
Beispiel #2
0
def page_detail(request, project_short_name):

    # load project
    project = get_object_or_404(Project, short_name__iexact=project_short_name)

    # HTTP redirect for non-local projects
    if not project.isLocal():
        return HttpResponseRedirect("http://%s%s" %
                                    (project.site.domain, request.path))

    # check project is active
    if project.active == False:
        return getProjectNotActiveRedirect(request, project)
    elif project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, project)

    # load page with URL equal to request path
    url = quote(request.path)

    #page = get_object_or_404(Post, url=quote(request.path))
    #TODO: add another case...if project description or long_name has changed.
    try:
        page = Post.objects.get(url=url)
    except Post.DoesNotExist:
        # dynamically create a templated project page if url matches one of the pre-defined values
        page = create_project_page(url, project)
        # if page has not been created, return error
        if not page:
            raise Http404

    # Check page access
    redirect = getNotAuthorizedRedirect(request, page)
    if redirect is not None:
        return redirect

    dict = {"title": page.title, "post": page, "project": project}

    related_pages = []
    for post in page.post_set.all():
        if not post.is_predefined():
            related_pages.append(post)
    dict['related_pages'] = related_pages

    # add extra objects for home page
    if page.is_home:
        dict['project_latest_signals'] = project.signals()[0:5]

    # render page template
    return render(request, page.template, dict)
Beispiel #3
0
def page_detail(request, project_short_name):
             
    # load project
    project = get_object_or_404(Project, short_name__iexact=project_short_name)
        
    # HTTP redirect for non-local projects
    if not project.isLocal():
        return HttpResponseRedirect("http://%s%s" % (project.site.domain, request.path))
    
    # check project is active
    if project.active == False:
        return getProjectNotActiveRedirect(request, project)
    elif project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, project)
        
    # load page with URL equal to request path
    url = quote(request.path)

    #page = get_object_or_404(Post, url=quote(request.path))
    #TODO: add another case...if project description or long_name has changed.
    try:
        page = Post.objects.get(url=url)
    except Post.DoesNotExist:
        # dynamically create a templated project page if url matches one of the pre-defined values
        page = create_project_page(url, project)
        # if page has not been created, return error
        if not page:
            raise Http404
    
    # Check page access
    redirect = getNotAuthorizedRedirect(request, page)
    if redirect is not None:
        return redirect

    dict = {"title": page.title, "post": page, "project": project}
    
    related_pages = []
    for post in page.post_set.all():
        if not post.is_predefined():
            related_pages.append(post)
    dict['related_pages'] = related_pages
    
    # add extra objects for home page
    if page.is_home:
        dict['project_latest_signals'] = project.signals()[0:5]
            
    # render page template
    return render(request, page.template, dict)
Beispiel #4
0
def external_urls_display(request, project_short_name, suburl):
    #external_url_type,
    #template_title, template_form_pages):

    project = get_object_or_404(Project, short_name__iexact=project_short_name)

    # check project is active
    if project.active == False:
        return getProjectNotActiveRedirect(request, project)
    elif project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, project)

    try:
        externalUrlConf = externalUrlManager.getConf(suburl=suburl)
    except KeyError:
        raise Exception("URL: %s is not properly configured" % request.path)

    external_url_type = externalUrlConf.type
    template_title = externalUrlConf.label
    template_form_page = "%s_update" % suburl
    template_form_pages = {
        reverse(template_form_page, args=[project_short_name, suburl]):
        template_title
    }

    # build list of children with external urls of this type
    children = _subSelectProjects(project.children(), externalUrlConf,
                                  request.user)

    # build list of peers with with external urls of this type
    peers = _subSelectProjects(project.peers.all(), externalUrlConf,
                               request.user)

    # to change to tabbed rollups, load 'cog/common/rollup_tabbed.html'
    return render(
        request,
        'cog/common/rollup_accordion.html',
        {
            'project': project,
            'title': '%s %s' % (project.short_name, template_title),
            # 'title': template_title,
            'template_page': 'cog/project/_external_urls_list.html',
            'template_title': template_title,
            'template_form_pages': template_form_pages,
            'children': children,
            'peers': peers,
            'external_url_type': external_url_type
        })
Beispiel #5
0
def bookmark_list(request, project_short_name):

    # order of bookmarks occurs in /forms_bookmarks.py

    # load the project
    project = get_object_or_404(Project, short_name__iexact=project_short_name)

    # check project is active
    if project.active == False:
        return getProjectNotActiveRedirect(request, project)
    elif project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, project)

    # get or create top-level folder
    # folder = getTopFolder(project)

    # build list of children with bookmarks that are visible to user
    children = []
    for child in project.children():
        if _hasBookmarks(child) and child.isVisible(request.user):
            children.append(child)

    # build list of peers with bookmarks that are visible to user
    peers = []
    for peer in project.peers.all():
        if _hasBookmarks(peer) and peer.isVisible(request.user):
            peers.append(peer)

    # return to view
    template_page = 'cog/bookmarks/_bookmarks.html'
    template_title = "Resources"
    template_form_name = None

    # change render template to 'cog/common/rollup_tabbed.html' to turn on tabbed rollups.

    return render(
        request, 'cog/common/rollup_accordion.html', {
            'project': project,
            'title': '%s %s' % (project.short_name, template_title),
            'template_page': template_page,
            'template_title': template_title,
            'template_form_name': template_form_name,
            'children': children,
            'peers': peers
        })
Beispiel #6
0
def bookmark_list(request, project_short_name):

    # order of bookmarks occurs in /forms_bookmarks.py
        
    # load the project
    project = get_object_or_404(Project, short_name__iexact=project_short_name)
    
    # check project is active
    if project.active == False:
        return getProjectNotActiveRedirect(request, project)
    elif project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, project)
        
    # get or create top-level folder
    # folder = getTopFolder(project)
    
    # build list of children with bookmarks that are visible to user
    children = []
    for child in project.children():
        if _hasBookmarks(child) and child.isVisible(request.user):
            children.append(child)
    
    # build list of peers with bookmarks that are visible to user
    peers = []
    for peer in project.peers.all():
        if _hasBookmarks(peer) and peer.isVisible(request.user):
            peers.append(peer)
                      
    # return to view    
    template_page = 'cog/bookmarks/_bookmarks.html'
    template_title = "Resources"
    template_form_name = None

    # change render template to 'cog/common/rollup_tabbed.html' to turn on tabbed rollups.

    return render(request,
                  'cog/common/rollup_accordion.html',
                   {'project': project,
                    'title': '%s %s' % (project.short_name, template_title),
                    'template_page': template_page,
                    'template_title': template_title,
                    'template_form_name': template_form_name,
                    'children': children,
                    'peers': peers})
Beispiel #7
0
def external_urls_display(request, project_short_name, suburl):
                          #external_url_type, 
                          #template_title, template_form_pages):
    
    project = get_object_or_404(Project, short_name__iexact=project_short_name)
    
    # check project is active
    if project.active == False:
        return getProjectNotActiveRedirect(request, project)
    elif project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, project)
    
    try:
        externalUrlConf = externalUrlManager.getConf(suburl=suburl)
    except KeyError:
        raise Exception("URL: %s is not properly configured" % request.path)
    
    external_url_type = externalUrlConf.type
    template_title = externalUrlConf.label
    template_form_page = "%s_update" % suburl
    template_form_pages = {reverse(template_form_page, args=[project_short_name, suburl]): template_title}
        
    # build list of children with external urls of this type
    children = _subSelectProjects(project.children(), externalUrlConf, request.user)
    
    # build list of peers with with external urls of this type
    peers = _subSelectProjects(project.peers.all(), externalUrlConf, request.user)

    # to change to tabbed rollups, load 'cog/common/rollup_tabbed.html'
    return render(request,
                  'cog/common/rollup_accordion.html',
                   {'project': project, 
                    'title': '%s %s' % (project.short_name, template_title),
                    # 'title': template_title,
                    'template_page': 'cog/project/_external_urls_list.html', 
                    'template_title': template_title, 
                    'template_form_pages': template_form_pages,
                    'children': children, 'peers': peers,
                    'external_url_type': external_url_type})
Beispiel #8
0
def getNotAuthorizedRedirect(request, post):
    
    # check project access first
    if post.project.active == False:
        return getProjectNotActiveRedirect(request, post.project)
    elif post.project.isNotVisible(request.user):
        return getProjectNotVisibleRedirect(request, post.project)
    
    # user is NOT authorized
    if not userCanView(request.user, post):
        if not request.user.is_authenticated():
            return HttpResponseRedirect(reverse('login')+"?next=%s" % request.path)
        else:
            messages = ['This page is only viewable to members of %s.' % post.project.short_name,
                        '<a href="/membership/request/%s">Request to join this project</a>.' % post.project.short_name]
            return render(request,
                          'cog/common/message.html', 
                          {'mytitle': 'Page Access Restricted',
                           'project': post.project,
                           'messages': messages})

    # user is authorized, return no redirect
    else:
        return None