Exemple #1
0
def index(request, klass, my=False, order_by='-pub_date', filter_type=None):
    """Index/My page for section given by klass.

    @param request: request data
    @type request: Django request
    @param klass: item's class for lookup in correct database table
    @type klass: either Data, Task or Method
    @param my: if the page should be a My page or the archive index of the section
    @type my: boolean
    @return: section's index or My page
    @rtype: Django response
    """
    objects = klass.objects.filter(is_deleted=False)

    if klass == Task and filter_type:
        objects = objects.filter(type=filter_type)

    if klass == Data:
        objects = objects.filter(is_approved=True)

    if my and request.user.is_authenticated():
        objects = objects.filter(user=request.user, is_current=True)
        if klass == Data:
            unapproved = klass.objects.filter(user=request.user,
                                              is_approved=False)
        else:
            unapproved = None
        my_or_archive = _('My')
    else:
        objects = objects.filter(is_current=True, is_public=True)
        unapproved = None
        my_or_archive = _('Public Archive')

    objects = objects.order_by(order_by, '-pub_date')

    kname = klass.__name__.lower()
    PER_PAGE = get_per_page(objects.count())
    info_dict = {
        'request': request,
        kname: get_page(request, objects, PER_PAGE),
        kname + '_per_page': PER_PAGE,
        'klass': klass.__name__,
        'unapproved':
        get_page(request, unapproved, PER_PAGE) if unapproved else [],
        'my_or_archive': my_or_archive,
        'tagcloud': get_tag_clouds(request),
        'section': 'repository',
        'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
        'yeah': 'index',
    }

    return render_to_response('repository/item_index.html',
                              info_dict,
                              context_instance=RequestContext(request))
Exemple #2
0
def index(request, klass, my=False, order_by='-pub_date', filter_type=None):
    """Index/My page for section given by klass.

    @param request: request data
    @type request: Django request
    @param klass: item's class for lookup in correct database table
    @type klass: either Data, Task or Method
    @param my: if the page should be a My page or the archive index of the section
    @type my: boolean
    @return: section's index or My page
    @rtype: Django response
    """
    objects = klass.objects.filter(is_deleted=False)

    if klass == Task and filter_type:
        objects = objects.filter(type=filter_type)
        
    if klass == Data:
        objects = objects.filter(is_approved=True)

    if my and request.user.is_authenticated():
        objects = objects.filter(user=request.user, is_current=True)
        if klass == Data:
            unapproved = klass.objects.filter(
                user=request.user, is_approved=False
            )
        else:
            unapproved = None
        my_or_archive = _('My')
    else:
        objects = objects.filter(is_current=True, is_public=True)
        unapproved = None
        my_or_archive = _('Public Archive')

    objects = objects.order_by(order_by, '-pub_date')

    kname=klass.__name__.lower()
    PER_PAGE = get_per_page(objects.count())
    info_dict = {
        'request': request,
        kname : get_page(request, objects, PER_PAGE),
        kname + '_per_page': PER_PAGE,
        'klass' : klass.__name__,
        'unapproved': get_page(request, unapproved, PER_PAGE) if unapproved else [],
        'my_or_archive': my_or_archive,
        'tagcloud': get_tag_clouds(request),
        'section': 'repository',
        'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
        'yeah': 'index',
    }

    return render_to_response('repository/item_index.html',
            info_dict, context_instance=RequestContext(request))
Exemple #3
0
def tags_view(request, tag, klass):
    """View all items tagged by given tag in given klass.

    @param request: request data
    @type request: Django request
    @param tag: name of the tag
    @type tag: string
    @param klass: klass of tagged item
    @type klass: repository.Data/Task/Method
    @return: rendered response page
    @rtype: Django response
    @raise Http404: if tag doesn't exist or no items are tagged by given tag
    """
    try:
        tag = Tag.objects.get(name=tag)
        objects = klass.get_current_tagged_items(request.user, tag)
        if not objects: raise Http404
    except Tag.DoesNotExist:
        raise Http404

    PER_PAGE = get_per_page(len(objects))
    kname = klass.__name__.lower()

    info_dict = {
        'request': request,
        'tag': tag,
        'tagcloud': get_tag_clouds(request),
        kname : get_page(request, objects, PER_PAGE),
        'klass' : klass.__name__,
        kname + '_per_page': PER_PAGE,
        'section': 'repository',
        'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
    }
    return render_to_response('repository/item_index.html', info_dict,
            context_instance=RequestContext(request))
Exemple #4
0
def search(request):
    """Search the repository for given term.

    @param request: request data
    @type request: Django request
    @return: rendered response page
    @rtype: Django response
    """
    if request.method == 'GET' and 'searchterm' in request.GET:
        searchterm = request.GET['searchterm']

        classes = []
        for c in (Data, Task, Method, Challenge):
            kname = c.__name__.lower()
            if kname in request.GET:
                classes.append(c)

        info_dict = {
            'request': request,
            'tagcloud': get_tag_clouds(request),
            'section': 'repository',
            'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
            'yeah': 'search',
            'my_or_archive': _('Search Results for "%s"' % searchterm)
        }

        for klass in classes:
            objects = klass.objects.filter(is_deleted=False,
                                           is_current=True,
                                           is_public=True)
            if klass == Data:
                objects = objects.filter(is_approved=True)

            searcherror = True

            if searchterm:
                info_dict['searchterm'] = searchterm
                objects = objects.filter(
                    Q(name__icontains=searchterm)
                    | Q(summary__icontains=searchterm)).order_by('-pub_date')
                searcherror = objects.count() == 0

            kname = klass.__name__.lower()
            PER_PAGE = get_per_page(objects.count())
            info_dict[kname] = get_page(request, objects, PER_PAGE)
            info_dict[kname + '_per_page'] = PER_PAGE
            info_dict[kname + '_searcherror'] = searcherror

        return render_to_response('repository/item_index.html',
                                  info_dict,
                                  context_instance=RequestContext(request))
    raise Http404
Exemple #5
0
def search(request):
    """Search the repository for given term.

    @param request: request data
    @type request: Django request
    @return: rendered response page
    @rtype: Django response
    """
    if request.method == 'GET' and 'searchterm' in request.GET:
        searchterm = request.GET['searchterm']

        classes=[]
        for c in (Data, Task, Method, Challenge):
            kname=c.__name__.lower()
            if kname in request.GET:
                classes.append(c)

        info_dict = {
            'request': request,
            'tagcloud': get_tag_clouds(request),
            'section': 'repository',
            'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
            'yeah': 'search',
            'my_or_archive' : _('Search Results for "%s"' % searchterm)
        }

        for klass in classes:
            objects = klass.objects.filter(is_deleted=False, is_current=True, is_public=True)
            if klass == Data:
                objects = objects.filter(is_approved=True)

            searcherror = True

            if searchterm:
                info_dict['searchterm'] = searchterm
                objects = objects.filter(Q(name__icontains=searchterm) |
                        Q(summary__icontains=searchterm)).order_by('-pub_date')
                searcherror = objects.count()==0

            kname=klass.__name__.lower()
            PER_PAGE = get_per_page(objects.count())
            info_dict[kname]=get_page(request, objects, PER_PAGE)
            info_dict[kname + '_per_page']=PER_PAGE
            info_dict[kname + '_searcherror']=searcherror

        return render_to_response('repository/item_index.html', info_dict,
                context_instance=RequestContext(request))
    raise Http404
Exemple #6
0
def tags_view(request, tag, klass):
    """View all items tagged by given tag in given klass.

    @param request: request data
    @type request: Django request
    @param tag: name of the tag
    @type tag: string
    @param klass: klass of tagged item
    @type klass: repository.Data/Task/Method
    @return: rendered response page
    @rtype: Django response
    @raise Http404: if tag doesn't exist or no items are tagged by given tag
    """
    try:
        tag = Tag.objects.get(name=tag)
        objects = klass.get_current_tagged_items(request.user, tag)
        if not objects: raise Http404
    except Tag.DoesNotExist:
        raise Http404

    PER_PAGE = get_per_page(len(objects))
    kname = klass.__name__.lower()

    info_dict = {
        'request': request,
        'tag': tag,
        'tagcloud': get_tag_clouds(request),
        kname: get_page(request, objects, PER_PAGE),
        'klass': klass.__name__,
        kname + '_per_page': PER_PAGE,
        'section': 'repository',
        'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
    }
    return render_to_response('repository/item_index.html',
                              info_dict,
                              context_instance=RequestContext(request))
Exemple #7
0
def view(request, klass, slug_or_id, version=None):
    """View item given by slug and klass.

    @param request: request data
    @type request: Django request
    @param klass: item's class for lookup in correct database table
    @type klass: either Data, Task or Method
    @param slug_or_id: slug or id of the item to view
    @type slug_or_id: string or integer
    @return: view page or review page if klass Data and item not approved
    @rtype: Django response
    @raise Http404: if item couldn't be found
    """
    kname=klass.__name__.lower()
    obj = klass.get_object(slug_or_id, version)
    if not obj: raise Http404
    if not obj.can_view(request.user):
        return HttpResponseForbidden()
    if not obj.check_is_approved():
        return HttpResponseRedirect(reverse(kname + '_review', args=[obj.slug]))

    current = obj.update_current_hits()

    # need tags in list
    versions = get_versions_paginator(request, obj)
    info_dict = {
        'object': obj,
        'request': request,
        'can_edit': obj.can_edit(request.user),
        'can_activate': obj.can_activate(request.user),
        'can_delete': obj.can_delete(request.user),
        'dependent_entries_exist': obj.dependent_entries_exist(),
        'dependent_link': '',
        'current': current,
        'rating_form': RatingForm.get(request, obj),
        'tagcloud': get_tag_clouds(request),
        'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
        kname : True,
        'klass': klass.__name__,
        'section': 'repository',
        'versions': versions,
    }
    if request.method == 'GET' and 'c' in request.GET:
        info_dict['show_comments'] = True

    if klass == Data:
        tasks=obj.get_related_tasks(request.user)
        PER_PAGE = get_per_page(tasks.count())
        info_dict['page']=get_page(request, tasks, PER_PAGE)
        info_dict['per_page']=PER_PAGE
        info_dict['related_tasks']=tasks
        info_dict['dependent_link']='#tabs-method'
    else:
        if request.user.is_authenticated():
            form = handle_result_form(request)
            info_dict['result_form'] = form


        if klass == Task:
            objects=Result.objects.filter(task=obj)
            if request.user.is_authenticated():
                form.fields['task'].queryset = obj
                form.fields['challenge'].queryset = obj.get_challenges()
            PER_PAGE = get_per_page(objects.count())
            info_dict['page']=get_page(request, objects, PER_PAGE)
            info_dict['per_page']=PER_PAGE
            info_dict['data']=obj.get_data()
            info_dict['dependent_link']='foo'

        elif klass == Method:
            objects=Result.objects.filter(method=obj)
            PER_PAGE = get_per_page(objects.count())
            info_dict['page']=get_page(request, objects, PER_PAGE)
            info_dict['per_page']=PER_PAGE

        elif klass == Challenge:
            t=obj.get_tasks()
            if request.user.is_authenticated():
                form.fields['task'].queryset = t
                form.fields['challenge'] = obj
            info_dict['tasks']=t
            objects=Result.objects.filter(challenge=obj).order_by('task__name','aggregation_score')
            PER_PAGE = get_per_page(objects.count())
            info_dict['page']=get_page(request, objects, PER_PAGE)
            info_dict['per_page']=PER_PAGE


    if hasattr(obj, 'data_heldback') and obj.data_heldback:
        info_dict['can_view_heldback'] = obj.data_heldback.can_view(request.user)
    info_dict['extract'] = obj.get_extract()
    return _response_for(request, klass, 'item_view', info_dict)
Exemple #8
0
def view(request, klass, slug_or_id, version=None):
    """View item given by slug and klass.

    @param request: request data
    @type request: Django request
    @param klass: item's class for lookup in correct database table
    @type klass: either Data, Task or Method
    @param slug_or_id: slug or id of the item to view
    @type slug_or_id: string or integer
    @return: view page or review page if klass Data and item not approved
    @rtype: Django response
    @raise Http404: if item couldn't be found
    """
    kname = klass.__name__.lower()
    obj = klass.get_object(slug_or_id, version)
    if not obj: raise Http404
    if not obj.can_view(request.user):
        return HttpResponseForbidden()
    if not obj.check_is_approved():
        return HttpResponseRedirect(reverse(kname + '_review',
                                            args=[obj.slug]))

    current = obj.update_current_hits()

    # need tags in list
    versions = get_versions_paginator(request, obj)
    info_dict = {
        'object': obj,
        'request': request,
        'can_edit': obj.can_edit(request.user),
        'can_activate': obj.can_activate(request.user),
        'can_delete': obj.can_delete(request.user),
        'dependent_entries_exist': obj.dependent_entries_exist(),
        'dependent_link': '',
        'current': current,
        'rating_form': RatingForm.get(request, obj),
        'tagcloud': get_tag_clouds(request),
        'download_warning_limit': DOWNLOAD_WARNING_LIMIT,
        kname: True,
        'klass': klass.__name__,
        'section': 'repository',
        'versions': versions,
    }
    if request.method == 'GET' and 'c' in request.GET:
        info_dict['show_comments'] = True

    if klass == Data:
        tasks = obj.get_related_tasks(request.user)
        PER_PAGE = get_per_page(tasks.count())
        info_dict['page'] = get_page(request, tasks, PER_PAGE)
        info_dict['per_page'] = PER_PAGE
        info_dict['related_tasks'] = tasks
        info_dict['dependent_link'] = '#tabs-method'
    else:
        if request.user.is_authenticated():
            form = handle_result_form(request)
            info_dict['result_form'] = form

        if klass == Task:
            objects = Result.objects.filter(task=obj)
            if request.user.is_authenticated():
                form.fields['task'].queryset = obj
                form.fields['challenge'].queryset = obj.get_challenges()
            PER_PAGE = get_per_page(objects.count())
            info_dict['page'] = get_page(request, objects, PER_PAGE)
            info_dict['per_page'] = PER_PAGE
            info_dict['data'] = obj.get_data()
            info_dict['dependent_link'] = 'foo'

        elif klass == Method:
            objects = Result.objects.filter(method=obj)
            PER_PAGE = get_per_page(objects.count())
            info_dict['page'] = get_page(request, objects, PER_PAGE)
            info_dict['per_page'] = PER_PAGE

        elif klass == Challenge:
            t = obj.get_tasks()
            if request.user.is_authenticated():
                form.fields['task'].queryset = t
                form.fields['challenge'] = obj
            info_dict['tasks'] = t
            objects = Result.objects.filter(challenge=obj).order_by(
                'task__name', 'aggregation_score')
            PER_PAGE = get_per_page(objects.count())
            info_dict['page'] = get_page(request, objects, PER_PAGE)
            info_dict['per_page'] = PER_PAGE

    if hasattr(obj, 'data_heldback') and obj.data_heldback:
        info_dict['can_view_heldback'] = obj.data_heldback.can_view(
            request.user)
    info_dict['extract'] = obj.get_extract()
    return _response_for(request, klass, 'item_view', info_dict)