Beispiel #1
0
def ripinfo(request):
    '''
       Gathering rip information for a centre
    ''' 
    if request.method=='GET':
        #yep we've selected something
        try:
            if 'ripinfo' in request.GET:
                #get centre for web display
                centre = Centre.objects.get(id=request.GET['centrerip'])
                ensembles = []
                sims=Simulation.objects.filter(centre=request.GET['centrerip']).filter(isDeleted=False)
                    #ensembles.append(s.ensemble_set.get())
                    #if s.ensemble_set.filter(riphidden=False):
                        #sims.delete(s)
                        #ensembles.append(s.ensemble_set.get())
                #ensemblemembers=[]
                #for e in ensembles:
                #    ensemblemembers.append(e.ensemblemember_set.all())
                return render_to_response('ripinfo.html',{'sims':sims, "ensembles":ensembles, "centre":centre})
                #return render_to_response('ripinfo.html',{'sims':sims, "ensembles":ensembles, "ensmems":ensemblemembers, "centre":centre})
        except KeyError:
            m='Unable to select requested centre %s'%request.POST['centrerip']
            logging.info('ERROR on centres page: Unable to select requested centre %s'%request.POST['centrerip'])
            return render_badrequest('error.html',{'message':m})    
Beispiel #2
0
def centres(request):
    ''' For choosing amongst centres '''
    p=Centre.objects.all()
    for ab in ['CMIP5','1. Example','2. Test Centre']:
        p=p.exclude(abbrev=ab)
    
    # creating a separate list for the example and test centre
    p_aux=Centre.objects.filter(Q(abbrev='1. Example')|Q(abbrev='2. Test Centre'))  
    
    if request.method=='POST':
        #yep we've selected something
        try:
            if 'choice' in request.POST:
                selected_centre=p.get(id=request.POST['choice'])
                return HttpResponseRedirect(reverse('pimms.apps.qn.views.centre',args=(selected_centre.id,)))
            elif 'auxchoice' in request.POST:
                selected_centre=p_aux.get(id=request.POST['auxchoice'])
                return HttpResponseRedirect(reverse('pimms.apps.qn.views.centre',args=(selected_centre.id,)))
            elif 'ripchoice' in request.POST:
                centre = Centre.objects.get(id=request.POST['ripchoice'])
                ensembles = []
                sims=Simulation.objects.filter(centre=request.POST['ripchoice']).filter(isDeleted=False)
                #FIXME
                # A temporary fix for empty start dates on input mods
                for sim in sims:
                    for ens in sim.ensemble_set.all():
                        for mem in ens.ensemblemember_set.all():
                            if mem.imod:
                                try:
                                    m = mem.imod.memberStartDate
                                    print 'Successful startdate found - %s' % m
                                except:
                                    print 'Replacing null startdate with %s' % sim.duration.startDate
                                    mem.imod.memberStartDate = sim.duration.startDate
                                    
                return render_to_response('ripinfo.html',{'sims':sims, "ensembles":ensembles, "centre":centre})
        except KeyError:
            m='Unable to select requested centre %s'%request.POST['choice']
            logging.info('ERROR on centres page: Unable to select requested centre %s'%request.POST['choice'])
            return render_badrequest('error.html',{'message':m})
    else: 
        logging.info('Viewing centres')
        curl = reverse('pimms.apps.qn.views.centres')
        feeds=DocFeed.feeds.keys()
        feedlist=[]
        for f in sorted(feeds):
            feedlist.append((f,reverse('django.contrib.syndication.views.feed',args=('cmip5/%s'%f,))))
            
        #get publication list for front page table
        pubs = getpubs()
        
        return render_to_response('centres/centres.html', {'objects':sublist(p,4),
                                                  'centreList':p,
                                                  'auxList':p_aux,
                                                  'curl':curl,
                                                  'pubs':pubs,
                                                  'feedobjects':sublist(feedlist,4)},
                                                  context_instance = RequestContext(request)
                                                  )
Beispiel #3
0
 def filterlist(self,request):
     ''' construct a filter based on a posted form and redirect to a targetted list'''
     if request.method=='POST':
         logging.debug('Trying to filter on %s'%request.POST)
         url=reverse('pimms.apps.qn.views.list',args=(self.cid,self.resource['type'],request.POST['klass'],request.POST['id'],))
         return HttpResponseRedirect(url)
     else:
        return render_badrequest('error.html',{'message':'Error, No GET to filterlist'})
Beispiel #4
0
def genericDoc(request,cid,docType,pkid,method):
    ''' Handle the generic documents '''
    logging.debug('entering generic document handler')
    try:
        klass={'simulation':Simulation,'experiment':Experiment,'component':Component,
           'platform':Platform}[docType]
    except Exception,e:
        return render_badrequest('error.html',{'message':'Document type %s not known (%s)'%(docType,e)})
Beispiel #5
0
def assign(request,cen_id,resourceType,targetType,target_id):
    ''' Provide a page to allow the assignation of resources of type resourceType
    to resource target_id of type targetType '''
    if resourceType=='file':
        return render_badrequest('error.html',{'message':'Cannot assign files to targets, assign objects from within them!'})
   
    h=ViewHandler(cen_id,resourceType,None,target_id,targetType)
    return h.assign(request) 
Beispiel #6
0
def persistedDoc(request, docType, uri, version=0):
    ''' 
       Persisted document handling : 
       Will retrieve an xml document with a given uri and version number  
    '''
    
    if docType not in ('platform', 'experiment', 'simulation', 'component', 
                       'datacontainer'):
        return HttpResponseBadRequest('Invalid document type requests - %s' 
                                      %docType)
    
    set = CIMObject.objects.filter(uri=uri)
    # Document doesn't exist in the database scenario
    if len(set) == 0:
        return render_badrequest('error.html', 
                                 {'message':'Document with uri %s not found' %uri})
    
    # Handling different versions 
    if version <> 0:
        try:
            set = set.filter(documentVersion=version)
            # Should only be one version per uri
            if len(set) <> 1: 
                logging.info('CIM Document Inconsistency - %s identical versions'
                             %len(set))
            obj=set.get(documentVersion=version)
        except:
            logging.info('Attempt to retrieve %s with version %s failed' 
                         %(uri, version))
            return render_badrequest('error.html', 
                                     {'message':'Document with uri %s has no version %s' 
                                      %(uri, version)})
    else:
        obj=set[len(set)-1]
    
    # generate an xml 
    return HttpResponse(obj.xmlfile.read(), mimetype='application/xml')
Beispiel #7
0
def exportFiles(request,cen_id):
    ''' Used to export all files to CMIP5 in one go '''
    objects=DataContainer.objects.filter(centre__id=cen_id)
    return render_badrequest('error.html',{'message':'Sorry not completely implemented'})
Beispiel #8
0
        return HttpResponse('<br/>'.join(modelnames))


def genericDoc(request,cid,docType,pkid,method):
    ''' Handle the generic documents '''
    logging.debug('entering generic document handler')
    try:
        klass={'simulation':Simulation,'experiment':Experiment,'component':Component,
           'platform':Platform}[docType]
    except Exception,e:
        return render_badrequest('error.html',{'message':'Document type %s not known (%s)'%(docType,e)})
    logging.debug('ok initially')
    try:
        obj=klass.objects.get(id=pkid)
    except:
        return render_badrequest('error.html',{'message':'Document id %s not known as %s'%(pkid,docType)})
    logging.debug('ok thus far')
    c=cimHandler(obj)
    try:
        cmethod=getattr(c,method)
    except:
        return render_badrequest('error.html',{'message':'Method %s not known as a generic document handler'%method})
    logging.debug('made it')
    return cmethod()


def persistedDoc(request, docType, uri, version=0):
    ''' 
       Persisted document handling : 
       Will retrieve an xml document with a given uri and version number  
    '''