Ejemplo 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 )
Ejemplo n.º 2
0
def index(request):
    "Login request"
    
    # users are not logged in so we can't use the Django messaging system
    error_message = ''

    if request.user.is_authenticated and request.user.username=='public':
        # someone is attempting a public access
        return html.template( request, name='notice.html')

    #
    # a logged in superuser may 'impersonate' other users 
    # this behavior may be disabled in the settings
    #
    if request.GET and settings.SUPERUSER_PASSWORD_OVERRIDE:
        uid = request.GET.get('uid', "").strip()
        if request.user.is_superuser and uid:
            user = User.objects.get(id=uid)
            backend = auth.get_backends()[0]
            user.backend = "%s.%s" % (backend.__module__, backend.__class__.__name__)
            auth.login(request, user)            
            return html.redirect("/project/list/")  
    #
    # normal login
    #
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email', '').strip()
            password = form.cleaned_data['password']
            userlist = User.objects.filter(email=email).all()
            if userlist:
                first = userlist[0]
                user = auth.authenticate(username=first.username, password=password)
                if user and user.is_active:
                    auth.login(request, user)                
                    return html.redirect("/project/list/")
                else:
                    error_message = 'Invalid user password!'
            else:
                 error_message = 'Invalid user email'
        else:
            # invalid form submission
            error_message = "Please specify an email and a password!"
    else:
        form = LoginForm()

    return html.template( request, name='login.html', form=form, error_message=error_message)
Ejemplo n.º 3
0
def index(request):
    "Main index page"
     # form submission
    params = html.Params( )

    
    return html.template( request, name='galaxy.html', params=params )
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo 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)
Ejemplo n.º 7
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 )
Ejemplo n.º 8
0
def details(request, did):
    "Renders the data view page"
    user = request.user
    data = authorize.get_data(user=user, did=did)    
    param = html.Params(file_list=data.file_list(), image_list= data.image_list())
    return html.template( request=request, name='data-details.html', data=data, param=param)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def browser(request, index, url, galaxy_url, dataid=0):
    ""
    global FORM_DEFAULTS

    # incoming parameters cast into a dictionary
    incoming = dict( request.POST.items() )

    # alters the incoming parameters based on user interaction
    incoming = browserutils.modify_incoming(incoming, FORM_DEFAULTS)

    # create the necessary forms
    forms  = html.Params()
    forms.search  = formspec.make_form(index.labels)(incoming)
    forms.navbar  = formspec.NavbarForm()
    forms.fitting = formspec.FitForm(  incoming )
    forms.peaks   = formspec.PeakForm( incoming )

    # extract the search parameters
    params = browserutils.parse_parameters(forms=forms, defaults=formspec.ALL_DEFAULTS)

    # run the tool or return an image
    if 'runtool' in incoming:
        # need to run the tool
        # form the url with dictionary substitution
        
        # TODO make parameters names consistent across Galaxy, GeneTrack and script!
        strand = 'all' if params.strand=='ALL' else 'two'
        mode = 'nolap' if params.smoothing_func =='GK' else 'all'

        urlparams = dict(
            strand = strand,
            exclusion=params.feature_width,
            level=int(params.minimum_peak),
            mode=mode,
            sigma=int(params.sigma),
            input=dataid,
            method='gauss',
            runtool_btn="Execute"
        )

        url = "%s&%s" % (galaxy_url, urllib.urlencode( urlparams ))
        return html.redirect(url)
       
    # creates the multiplot
    multi = dataview_multiplot(index=index, params=params, debug=False)
    params.image_height = multi.h
    
    # close the data
    index.close()

    # trigger the occasional cache cleaning
    webutil.cache_clean(age=1, chance=10)

    # creates a file representation and a name
    image_name, image_path = webutil.cache_file(ext='png')

    # saves the multiplot
    multi.save(image_path)
    params.image_name = image_name

    return html.template( request=request, name='data-browse.html', forms=forms, params=params, url=url)
Ejemplo n.º 11
0
def listall(request):
    "Lists all projects"
    params = html.Params()
    projects = authorize.project_list(request.user)
    params.project_count = authorize.project_count(request.user)
    return html.template(request=request, name="project-list.html", projects=projects, params=params)
Ejemplo 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)
Ejemplo n.º 13
0
def error500(request):
    "Server error page when debug flag is False"
    context = RequestContext(request)
    exc_type, exc_value, tb = sys.exc_info()
    logger.error(exc_value)
    return html.template( request, name='500.html', debug=exc_value )
Ejemplo n.º 14
0
def todo(request):
    "Todo page"
    params = html.Params(info='**test**')
    return html.template( request, name='todo.html', params=params )
Ejemplo n.º 15
0
def index(request):
    "Main index page"
    params = html.Params()
    params.project_count = authorize.project_count(request.user)
    return html.template( request, name='index.html', params=params )