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/")
            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)
        # no form data sent
        if pid == "new":
            title = "Create New Project"
            form = ProjectForm()
            title = "Edit Project"
            project = authorize.get_project(user=user, pid=pid)
            form = ProjectForm(dict(,
        return html.template(request=request, name="project-edit.html", pid=pid, title=title, form=form)
Beispiel #2
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/")
                    error_message = 'Invalid user password!'
                 error_message = 'Invalid user email'
            # invalid form submission
            error_message = "Please specify an email and a password!"
        form = LoginForm()

    return html.template( request, name='login.html', form=form, error_message=error_message)
Beispiel #3
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,, 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(, )        
        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      = get('name') = get('info')
        return html.redirect("/data/details/%s/" %
        return html.template( request=request, name='data-edit.html', did=did, form=form )
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)
            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)
Beispiel #5
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,, write=True)
    user.message_set.create(message="Result %s deleted" %
    return html.redirect("/data/details/%s/" %
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:
        user.message_set.create(message="Project deletion complete")
        return html.redirect("/project/list/")
        return html.template(request=request, name="project-delete.html", project=project)
Beispiel #7
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)
        user.message_set.create(message="no valid action was selected")

    return html.redirect( "/project/view/%s/" % pid )
Beispiel #8
def upload_processor(request, pid):
    "Handles the actual data upload"
    user = request.user
    if user.is_authenticated() and user.username!='public':
        if 'upload' in request.POST:
            count = 0
            for i in range(50): # take at most 50 files
                key = 'File%s' % i
                if key in request.FILES:
                    count += 1
                    stream = request.FILES[key]
                    name = html.chop_dirname( )
                    logger.debug('%s uploaded file %s' % (user.username, name) )
                    authorize.create_data(user=user, pid=pid, stream=stream, name=name, info='no information')

            user.message_set.create(message="Uploaded %s files" % count)
        if 'simple' in request.POST:
            return html.redirect("/project/view/%s/" % pid)

    # this is needed only because the JUPload applet makes a HEAD request        
    return html.response('SUCCESS\n')
Beispiel #9
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,, 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/" %
        # 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 )
Beispiel #10
def logout(request):
    "Logout request"
    return html.redirect("/")
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()  = 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,

        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

    # 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
    params.image_name = image_name

    return html.template( request=request, name='data-browse.html', forms=forms, params=params, url=url)