Example #1
0
def configuration_query(request, remote_set_id, instrument_name):
    """
        Query all jobs in a job set
        @param request: request object
        @param remote_id: pk of RemoteJobSet object
    """
    logger.debug("%s remote_set_id=%s"%(inspect.stack()[0][3],remote_set_id))
    
    instrument_name_lowercase = str.lower(str(instrument_name))
    instrument_name_capitals = str.capitalize(str(instrument_name))
    job_set = get_object_or_404(RemoteJobSet, pk=remote_set_id)
    
    breadcrumbs = Breadcrumbs()
    breadcrumbs.append('%s reduction'%instrument_name_lowercase,reverse('reduction_home',
                                                  kwargs={'instrument_name': instrument_name_lowercase }))
    breadcrumbs.append_configuration(instrument_name_lowercase, job_set.configuration.id)
    breadcrumbs.append('jobs',reverse('reduction_jobs', kwargs={'instrument_name': instrument_name_lowercase}))
    breadcrumbs.append("job results")
    
    template_values = {'remote_set_id': remote_set_id,
                       'configuration_title': job_set.configuration.name,
                       'configuration_id': job_set.configuration.id,
                       'breadcrumbs': breadcrumbs,
                       'title': '%s job results'%instrument_name_capitals,
                       'trans_id': job_set.transaction.trans_id,
                       'job_directory': job_set.transaction.directory,
                       'back_url': request.path,
                       'instrument': instrument_name_lowercase}
    
    # Get status of each job
    job_set_info = []
    first_job = None
    for item in job_set.jobs.all():
        job_info = remote.view_util.query_remote_job(request, item.remote_id)
        if job_info is not None:
            first_job = item
            job_info['reduction_name'] = item.reduction.name
            job_info['reduction_id'] = item.reduction.id # same as remote_job_remote_id!!
            job_info['id'] = item.id
            job_info['remote_id'] = item.remote_id
            job_info['parameters'] = item.get_data_dict()
            job_set_info.append(job_info)
    template_values['job_set_info'] = job_set_info
    
    # Show list of files in the transaction
    template_values['job_files'] = remote.view_util.query_files(request, job_set.transaction.trans_id)
    logger.debug(pprint.pformat(template_values['job_files']))
    
    # I(q) plots
    inst_view_util = view_util.import_module_from_app(instrument_name_lowercase,'view_util')
    template_values = inst_view_util.set_into_template_values_plots(template_values, request, first_job)
    # Link to download all I(q) files
    template_values = reduction_server.view_util.fill_template_values(request, **template_values)
    
    logger.debug(pprint.pformat(template_values))
    
    return render_to_response('%s/configuration_query.html'%instrument_name_lowercase, template_values,
                              context_instance=RequestContext(request))
Example #2
0
def reduction_options(request, reduction_id=None, instrument_name=None):
    """
        Display the reduction options form:
        
        If reduction_id exists, it will populate the form with information from that reduction.
            
        @param request: request object
        @param reduction_id: pk of reduction process object
    """
    
    logger.debug("Reduction: %s instrument_name=%s"%(inspect.stack()[0][3],instrument_name))
    
    instrument_name_capitals = str.capitalize(str(instrument_name))
    instrument_name_lowercase = str.lower(str(instrument_name))
    instrument_forms = view_util.import_module_from_app(instrument_name_lowercase,'forms')
    
    template_values = {}
    # Get reduction and configuration information
    config_obj = None
    if reduction_id is not None:
        reduction_proc = get_object_or_404(ReductionProcess, pk=reduction_id, owner=request.user)
        config_obj = reduction_proc.get_config()
    
    if request.method == 'POST':
        #logger.debug(pprint.pformat(request.POST.items()))
        
        options_form = instrument_forms.ReductionOptions(request.POST)
        # If the form is valid update or create an entry for it (if the data_file is different, a new entry is created!)
        if options_form.is_valid():
            new_reduction_id = options_form.to_db(request.user, reduction_id)
            if new_reduction_id is not None:
                messages.add_message(request, messages.SUCCESS, "Reduction parameters were sucessfully updated: " +
                "old_reduction_id=%s :: new_reduction_id=%s"%(reduction_id,new_reduction_id) )
                ## Keep the new reduction attached to the same configuration of the old one!
                # This is used for SEQ.
                # TODO: Check if SANS guys want that!
                if config_obj is not None:
                    reduction_proc = get_object_or_404(ReductionProcess, pk=new_reduction_id, owner=request.user)
                    config_obj.reductions.add(reduction_proc)
                    config_obj.save()
                return redirect(reverse('reduction_options',
                                        kwargs={'reduction_id' : new_reduction_id, 'instrument_name' : instrument_name}))
        else:
            messages.add_message(request, messages.ERROR, "The form is not valid. See errors above.")
    else:
        if reduction_id is not None:
            initial_values = instrument_forms.ReductionOptions.data_from_db(request.user, reduction_id)
        else:
            initial_values = copy.deepcopy(request.GET)
            if 'expt_name' in request.GET:
                initial_values['experiment'] = request.GET['expt_name']
        options_form = instrument_forms.ReductionOptions(initial=initial_values)
    
    breadcrumbs = Breadcrumbs()
    breadcrumbs.append_reduction(instrument_name_lowercase)
    
    if config_obj is not None:
        breadcrumbs.append_configuration(instrument_name_lowercase,config_obj.id)
        template_values.update({"properties":config_obj.get_data_dict()});
    if reduction_id is not None:
        breadcrumbs.append("reduction %s" % reduction_id)
    else:
        breadcrumbs.append("new reduction")

    # ICAT info url
    icat_url = reverse('catalog_run_info', args=[instrument_name_capitals, '0000'])
    icat_url = icat_url.replace('/0000', '')
    # TODO: add New an Save-As functionality
    template_values.update({'options_form': options_form,
                       'title': '%s Reduction' % instrument_name_capitals,
                       'breadcrumbs': breadcrumbs,
                       'reduction_id': reduction_id,
                       'icat_url': icat_url,
                       'instrument' : instrument_name_lowercase, })
    # Get existing jobs for this reduction
    if reduction_id is not None:
        existing_jobs = RemoteJob.objects.filter(reduction=reduction_proc)
        if len(existing_jobs) > 0:
            template_values['existing_jobs'] = existing_jobs.order_by('id')
        template_values['expt_list'] = reduction_proc.experiments.all()

    template_values = reduction_server.view_util.fill_template_values(request, **template_values)
    logger.debug(pprint.pformat(template_values))
    return render_to_response('%s/reduction_options.html' % instrument_name_lowercase,
                              template_values,context_instance=RequestContext(request))