Beispiel #1
0
def save_annotation_session(request,cid):
    '''save_annotation_session will save the annotation set, meaning creation of 
    a session with the queryset. (not in use)
    :param cid: the collection id to use
    '''
    collection = get_report_collection(cid)
    if has_collection_edit_permission(request,collection):
        if request.method == "POST":

            # What user does the request want to see annotations by?
            user_id = request.POST.get('user')
            user = get_user(request,user_id)

            # What annotation (name and label) do we filter to?
            selection_keys = [x for x in request.POST.keys() if re.search("^whatisit[||]", x)]
            selections = []
            seen_annotations = []
            for selection_key in selection_keys:
                name,label = selection_key.replace("whatisit||","").split("||")
                annotation_object = AllowedAnnotation.objects.get(name=name,
                                                                      label=label)

                # Query to select the reports of interest
                selection = Annotation.objects.filter(annotator=user,
                                                      annotation=annotation_object,
                                                      reports__collection=collection)
                for annotation in selection:
                    if annotation not in seen_annotations:
                        selections = list(chain(selections,annotation.reports.all()))
                        seen_annotations.append(annotation)

            request.session['reports'] = selections
            return annotate_session(request,cid)

    return HttpResponseRedirect(collection.get_absolute_url())
Beispiel #2
0
def approve_annotate_permission(request,cid,uid):
    '''a user must first get approved for annotate permission before being
    added to an annotation set
    '''
    collection = get_report_collection(cid)
    if has_collection_edit_permission(request,collection):
        requester = get_user(request,uid)
        permission_request = RequestMembership.objects.get(collection=collection,
                                                           requester=requester)
        if permission_request.status not in ["APPROVED","DENIED"]:

            # Update the collection
            collection.annotators.add(requester)
            collection.save()

            # Update the permission request
            permission_request.status = "APPROVED"
            permission_request.save()

            # Send a notification to the user
            message = """Your request to annotate sets in the collection %s 
                         has been approved!""" %(collection.name)
            notify.send(collection.owner, recipient=requester, verb=message)
            messages.success(request, 'Annotators approved.')
    
    return view_report_collection(request,cid)
Beispiel #3
0
def save_annotation_set(request,cid):
    '''save_annotation_set will save the annotation set, meaning creation of 
    a ReportSet with the queryset.
    :param cid: the collection id to use
    '''
    collection = get_report_collection(cid)
    if has_collection_edit_permission(request,collection):
        if request.method == "POST":
            
            # What does the user want to name the set?
            set_name = request.POST.get('setname').lower().replace(" ","_")

            # What user should be used as gold standard?
            gold_standard = request.POST.get('gold_standard')

            # How many reports in the set?
            request,N = parse_numeric_input(request=request,
                                            value=request.POST.get('N'),
                                            default=100,
                                            description="the number of reports")
            
            # How many tests should be given and passing?
            request,testing_set = parse_numeric_input(request=request,
                                                      value=request.POST.get('testing_set'),
                                                      default=25,
                                                      description="the number of testing reports")

            request,testing_set_correct = parse_numeric_input(request=request,
                                                              value=request.POST.get('testing_set_correct'),
                                                              default=20,
                                                              description="the number reports correct to pass")

            # Required number correct must be less than total
            if testing_set_correct > testing_set:
                messages.info(request,"The required number of passing questions must be less than or equal to the number of testing questions.")
                return create_annotation_set(request,cid)

            # What users does the request want to see annotations by?
            user_id = request.POST.get('user')
            if user_id == 'all':
                user = [u.id for u in get_collection_users(collection)]
            else:
                user = [get_user(request,user_id).id]

            # What annotation (name and label) do we filter to?
            selection_keys = [x for x in request.POST.keys() if re.search("^whatisit[||]", x)]
            generate_annotation_set.apply_async(kwargs={'uid':request.user.id,
                                                        'user_ids':user,
                                                        'selection_keys':selection_keys,
                                                        'cid':collection.id,
                                                        'N':N,
                                                        'testing_set':testing_set,
                                                        'testing_set_correct':testing_set_correct,
                                                        'gid':gold_standard,
                                                        'set_name':set_name})

            messages.info(request,"""Your set is being created. It's status will be sent via notification. Once it is created, you should add annotators to it.""")

    return redirect('report_collection_details',cid=collection.id)
Beispiel #4
0
def remove_contributor(request,cid,uid):
    '''remove a contributor from a collection
    :param cid: the collection id
    :param uid: the contributor (user) id
    '''
    collection = get_report_collection(cid)
    user = get_user(request,uid)
    contributors = collection.contributors.all()
    if request.user == collection.owner:
        if user in contributors:    
            collection.contributors = [x for x in contributors if x != user]
            collection.save()
            messages.success(request, 'User %s is no longer a contributor to the collection.' %(contributor))

    return edit_contributors(request,cid)
Beispiel #5
0
def new_set_annotator(request,sid):
    '''creates a new Credential for a user and a particular 
    collection, with default state TESTING to ensure tests first.
    :param sid: the report_set id
    '''
    report_set = get_report_set(sid)
    collection = report_set.collection
    if has_collection_edit_permission(request,collection):
        if request.method == "POST":
            user_id = request.POST.get('user',None)
            if user_id:
                user = get_user(request,user_id)
                credential = Credential.objects.create(user=user,
                                                       report_set=report_set)
                credential.save()
                messages.success(request, 'Credential for user %s added, user will need to test before annotating.' %(user))
    return redirect('edit_set_annotators',sid=report_set.id)
Beispiel #6
0
def remove_set_annotator(request,sid,uid):
    '''completely remove a user from an annotation set.
    :param sid: the report_set id
    :param uid: the user id
    '''
    report_set = get_report_set(sid)
    collection = report_set.collection
    if has_collection_edit_permission(request,collection):
        annotator = get_user(request,uid)
        credential = Credential.objects.get(user=annotator,
                                            report_set=report_set)
        credential.delete()
        messages.info(request, "User %s has been removed from set annotators." %(annotator))
        return render(request, 'reports/report_collection_annotators.html', context)

    # Does not have permission, return to collection
    messages.info(request, "You do not have permission to edit annotators for this collection.")
    return view_report_collection(request,cid)
Beispiel #7
0
def add_contributor(request,cid):
    '''add a new contributor to a collection
    :param cid: the collection id
    '''
    collection = get_report_collection(cid)
    if request.user == collection.owner:
        if request.method == "POST":
            user_id = request.POST.get('user',None)
            if user_id:
                user = get_user(request,user_id)
                collection.contributors.add(user)
                collection.save()

                # Alert the user of the status change
                message = """You have been added as a contributor to the %s.""" %(collection.name)
                notify.send(collection.owner, recipient=user, verb=message)

                messages.success(request, 'User %s added as contributor to collection.' %(user))

    return edit_contributors(request,cid)
Beispiel #8
0
def deny_annotate_permission(request,cid,uid):
    '''a user can be denied annotate permission at the onset (being asked) or
    have it taken away, given asking --> pending --> does not pass test
    '''
    collection = get_report_collection(cid)
    if has_collection_edit_permission(request,collection):
        requester = get_user(request,uid)
        permission_request = RequestMembership.objects.get(collection=collection,
                                                           requester=requester)
        if permission_request.status != "DENIED":
            permission_request.status = "DENIED"
            permission_request.save()

            # Send a notification to the user
            message = """Your request to annotate sets in the collection %s 
                         has been denied""" %(collection.name)
            notify.send(collection.owner, recipient=requester, verb=message)


            messages.success(request, 'Annotators updated.')    
    return view_report_collection(request,cid)
Beispiel #9
0
def change_set_annotator(request,sid,uid,status):
    '''change the status of a set annotator to one of 
    PASSED,DENIED,TESTING
    :param sid: the report_set id
    :param uid: the user id
    '''
    report_set = get_report_set(sid)
    collection = report_set.collection
    if has_collection_edit_permission(request,collection):
        annotator = get_user(request,uid)
        credential = Credential.objects.get(user=annotator,
                                            report_set=report_set)
        credential.status = status
        credential.save()
        messages.info(request,"User %s status changed to %s" %(annotator,status.lower()))

        # If the user is passed, add to annotators
        if status == "PASSED":
            report_set.annotators.add(annotator)
        elif status in ["DENIED","TESTING"]:
            report_set.annotators.remove(annotator) 
        report_set.save()

        # Alert the user of the status change
        message = """Your request to annotate set %s for 
                     collection %s has updated status %s""" %(report_set.name,
                                                              collection.name,
                                                              status.lower())

        notify.send(collection.owner, recipient=annotator, verb=message)

        return redirect('edit_set_annotators',sid=report_set.id)

    # Does not have permission, return to collection
    messages.info(request, "You do not have permission to edit annotators for this collection.")
    return view_report_collection(request,cid)