Exemplo n.º 1
0
def edit(request, did):
    "Updates or creates a project"
    user = request.user
    
    data = authorize.get_data(user=user, did=did)
    project = authorize.get_project(user=user, pid=data.project.id, write=False)
    editable = (data.owner == user) or (project.is_manager) 

    # raise error on not editable data
    if not editable:
        raise authorize.AccessError('Data not editable by this role')

    # no submission
    if 'submit' not in request.POST:
        form = DataForm( dict(name=data.name, info=data.info) )        
        return html.template( request=request, name='data-edit.html', data=data, form=form )
    
    # form submission
    form = DataForm( request.POST )  
    if form.is_valid():
        get  = form.cleaned_data.get      
        data.name = get('name')
        data.info = get('info')
        data.save()
        return html.redirect("/data/details/%s/" % data.id)
    else:    
        return html.template( request=request, name='data-edit.html', did=did, form=form )
Exemplo n.º 2
0
def edit(request, pid):
    "Updates or creates a project"
    user = request.user

    form = ProjectForm(request.POST)

    if form.is_valid():
        # incoming data
        get = form.cleaned_data.get
        if pid == "new":
            project = authorize.create_project(user=user, name=get("name"), info=get("info"))
            user.message_set.create(message="Project created")
            return html.redirect("/project/list/")
        else:
            authorize.update_project(user=user, pid=pid, name=get("name"), info=get("info"))
            user.message_set.create(message="Project updated")
            return html.redirect("/project/view/%s/" % pid)
    else:
        # no form data sent
        if pid == "new":
            title = "Create New Project"
            form = ProjectForm()
        else:
            title = "Edit Project"
            project = authorize.get_project(user=user, pid=pid)
            form = ProjectForm(dict(name=project.name, info=project.info))
        return html.template(request=request, name="project-edit.html", pid=pid, title=title, form=form)
Exemplo n.º 3
0
def share(request, pid):
    "Manages sharing to a project"
    user = request.user
    project = authorize.get_project(user=user, pid=pid, write=False)
    members = models.Member.objects.filter(project=project).order_by("role")

    text = request.GET.get("text", "").strip()
    results = []

    # found incoming search parameters
    if text:
        text = text.strip()

        if text != "*":
            query = models.User.objects.filter
            query = query(first_name__icontains=text) | query(last_name__icontains=text)
        else:
            query = models.User.objects
        results = query.all().order_by("last_name")

    uid = request.GET.get("uid")
    action = request.GET.get("action")

    # update the roles according to the action parameter
    if action and uid:
        authorize.update_role(user=user, pid=pid, action=action, uid=uid)
        return html.redirect("/project/share/%s/" % pid)

    params = html.Params(results=results, text=text, members=members)
    return html.template(request=request, name="project-share.html", project=project, params=params)
Exemplo n.º 4
0
def download(request, did):
    "Edits an existing project"
    user = request.user
    try:
        data = models.Data.objects.get(id=did)
        project = authorize.get_project(user=user, pid=data.project.id, write=False)
    except ObjectDoesNotExist, exc:
        raise authorize.AccessError("may not access this data")
Exemplo n.º 5
0
def result_delete(request, rid):
    "Uploads a result"
    user = request.user
    
    result = authorize.get_result(user=user, rid=rid)
    project = authorize.get_project(user=user, pid=result.data.project.id, write=True)
    result.delete()
    user.message_set.create(message="Result %s deleted" % result.name)
    return html.redirect("/data/details/%s/" % result.data.id)
Exemplo n.º 6
0
def delete(request, pid):
    "Deletes a project (with confirmation)"
    user = request.user
    project = authorize.get_project(user=user, pid=pid, write=True)
    if "delete" in request.POST:
        project.delete()
        user.message_set.create(message="Project deletion complete")
        return html.redirect("/project/list/")
    else:
        return html.template(request=request, name="project-delete.html", project=project)
    def test_data_creation(self):
        """
        Create datasets
        """
        
        # it seems that importing it earlier messes up the test database setup
        from genetrack.server.web import authorize

        john = User.objects.get(username='******')
        project = authorize.create_project(user=john, name="Test project")
        stream = File( open(conf.testdata('test-users.csv')) )
        data = authorize.create_data(user=john, pid=project.id, stream=stream, name="Test data")

        # project counts update
        project = authorize.get_project(user=john, pid=project.id)
        self.assertEqual(project.data_count, 1)

        # testing data deletion
        authorize.delete_data(user=john, pid=project.id, dids=[data.id])
        project = authorize.get_project(user=john, pid=project.id)
        self.assertEqual(project.data_count, 0)
Exemplo n.º 8
0
def action(request, pid):
    "Data related actions"
    user = request.user
    project = authorize.get_project(user=user, pid=pid, write=False)

    action = request.REQUEST.get('action')

    if action == u'delete':
        # delete request
        dids = request.REQUEST.getlist('did')
        authorize.delete_data(user=user, pid=pid, dids=dids)
    else:
        user.message_set.create(message="no valid action was selected")

    return html.redirect( "/project/view/%s/" % pid )
Exemplo n.º 9
0
    def test_data_creation(self):
        """
        Create datasets
        """

        # it seems that importing it earlier messes up the test database setup
        from genetrack.server.web import authorize

        john = User.objects.get(username='******')
        project = authorize.create_project(user=john, name="Test project")
        stream = File(open(conf.testdata('test-users.csv')))
        data = authorize.create_data(user=john,
                                     pid=project.id,
                                     stream=stream,
                                     name="Test data")

        # project counts update
        project = authorize.get_project(user=john, pid=project.id)
        self.assertEqual(project.data_count, 1)

        # testing data deletion
        authorize.delete_data(user=john, pid=project.id, dids=[data.id])
        project = authorize.get_project(user=john, pid=project.id)
        self.assertEqual(project.data_count, 0)
Exemplo n.º 10
0
def result_upload(request, did):
    "Uploads a result"
    user = request.user
    
    data = authorize.get_data(user=user, did=did)
    project = authorize.get_project(user=user, pid=data.project.id, write=False)


    # no submission, default page
    if 'submit' not in request.POST:
        form = ResultForm()        
        return html.template( request=request, name='result-upload.html', data=data, form=form )
    
    # actual form submission
    form = ResultForm( request.POST, request.FILES )  
    if form.is_valid():
        get = form.cleaned_data.get   
        authorize.create_result(user=user, data=data, content=get('content'), image=get('image'))        
        return html.redirect("/data/details/%s/" % data.id)
    else:    
        # error messages will be generated
        user.message_set.create(message="Some form fields could NOT be validated.")
        return html.template( request=request, name='result-upload.html', data=data, form=form )
Exemplo n.º 11
0
def upload_simple(request, pid):
    "Renders the upload page"
    user = request.user
    project = authorize.get_project(user=user, pid=pid, write=False)    
    return html.template( request=request, name='data-upload-simple.html', project=project)
Exemplo n.º 12
0
def view(request, pid):
    "Lists all projects"
    project = authorize.get_project(user=request.user, pid=pid, write=False)
    return html.template(request=request, name="project-view.html", project=project)