Пример #1
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)
                                                  )
Пример #2
0
def centre(request,centre_id):
    ''' 
    Handle the top page on a centre by centre basis 
    '''
    
    c=Centre.objects.get(id=centre_id)
    
    #models=[]
    models=[Component.objects.get(id=m.id) for m in c.component_set.filter(
                                                    scienceType='model').filter(
                                                    isDeleted=False)]
    #monkey patch the urls to edit these ...
    for m in models:
        m.url=reverse('pimms.apps.qn.views.componentEdit',args=(c.id,m.id))
        m.cpURL=reverse('pimms.apps.qn.views.componentCopy',args=(c.id,m.id))
    
    platforms=[Platform.objects.get(id=p['id']) for p in c.platform_set.values().filter(isDeleted=False)]
    for p in platforms:
        p.url=reverse('pimms.apps.qn.views.platformEdit',args=(c.id,p.id))
    
    sims=Simulation.objects.filter(centre=c.id).filter(isDeleted=False).order_by('abbrev')
    for s in sims:
        s.url=reverse('pimms.apps.qn.views.simulationEdit',args=(c.id,s.id))
    
    grids=Grid.objects.filter(centre=c.id).filter(istopGrid=True).filter(isDeleted=False) 
    for g in grids:
        g.url=reverse('pimms.apps.qn.views.gridEdit',args=(c.id,g.id))
        g.cpURL=reverse('pimms.apps.qn.views.gridCopy',args=(c.id,g.id))
    
    newmodURL=reverse('pimms.apps.qn.views.componentAdd',args=(c.id,))
    newplatURL=reverse('pimms.apps.qn.views.platformEdit',args=(c.id,))
    viewsimURL=reverse('pimms.apps.qn.views.simulationList',args=(c.id,))
    newgridURL=reverse('pimms.apps.qn.views.gridAdd',args=(c.id,))
    
    
    refs=Reference.objects.filter(centre=c)
    files=DataContainer.objects.filter(centre=c)
    parties=ResponsibleParty.objects.filter(centre=c)
    
    #get simulation info for sim table
    tablesims = getsims(c)
    
    logging.info('Viewing %s'%c.id)
    return render_to_response('centre/centre.html',
                              {'centre':c, 
                               'models':models,
                               'platforms':platforms,
                               'grids':grids, 
                               'refs':refs,
                               'files':files, 
                               'parties':parties,
                               'newmod':newmodURL,
                               'newplat':newplatURL,
                               'newgrid':newgridURL,
                               'sims':sublist(sims,3),
                               'viewsimurl':viewsimURL,
                               'tabs':tabs(request,c.id, 'Summary'),
                               'notAjax':not request.is_ajax(),
                               'tablesims':tablesims})
Пример #3
0
    def list(self,request):
        ''' Show a list of the basic entities, either all of them, or those
        associated with a specific instance of a specific class '''
        
        objects=self.objects()
        #construct a set of options for filtering to a specific class (if appropriate)
        ftype=self.resource['filter']
        if ftype:
            url=reverse('pimms.apps.qn.views.filterlist',args=(self.cid,self.resource['type'],))
            ops=ftype.objects.all()
            try: # if we can filter on centres, we do ...
                ops.filter(centre__id=self.cid)
            except AttributeError: pass
            filterops={'m':'Filter by %s'%ftype._meta.module_name,
                       'ops':ops,
                       'url':url,
                       'klass':ftype._meta.module_name}
        else: filterops=None
        
        # construct a CMIP5 export button
        if self.resource['type']=='file':
            exportFiles=reverse('pimms.apps.qn.views.exportFiles',args=(self.cid,))
        else: exportFiles=None
        
        if self.target:

            # in the case of a list, the target is used to go back ...

            # get a URL for a blank form
            formURL=reverse('pimms.apps.qn.views.edit',
                            args=(self.cid,self.resource['type'],0,
                            self.target['type'],self.target['instance'].id,'list',))
            for o in objects:
                # monkey patch an edit URL into the object allowing for the target,
                # saying come back here (to the list). Unfortunately doing that
                # means we lose the incoming reference.
                args=(self.cid,self.resource['type'],o.id,
                                  self.target['type'],self.target['instance'].id,'list',)
                o.editURL=reverse('pimms.apps.qn.views.edit',args=args)
                o.delURL=reverse('pimms.apps.qn.views.delete',args=args)
                #o.delURL=reverse('pimms.apps.qn.views.delete',
                #            args=(self.cid,self.resource['type'],o.id,self.currentURL)
                # Need to be able to make sure this isn't an html get from an <a> otherwise
                # do it as  form with a method of delete.
        else:
            # get a URL for a blank form
            formURL=reverse('pimms.apps.qn.views.edit',
                            args=(self.cid,self.resource['type'],0,'list',))
            
            for o in objects:
                # monkey patch an edit URL into the object, saying come back here (list)
                args=(self.cid,self.resource['type'],o.id,'list',)
                o.editURL=reverse('pimms.apps.qn.views.edit',args=args)
                if o.centre==self.centre:
                    o.delURL=reverse('pimms.apps.qn.views.delete',args=args)
                else:
                    o.delURL=None
        # we pass a form and formURL for a new instance to be created.
        # we're doing all this because we think we have too many entities to use a formset
       
        return render_to_response(self.listHTML,{
                'objects':sublist(objects,3),
                'tabs':tabs(request,self.cid,self.resource['tab']),
                'form':self._constructForm('GET'),
                'editURL':formURL,
                'instance':self.resource,
                'snippet_template':'%s_snippet.html'%self.resource['type'],
                'target':self.target,
                'exportFiles':exportFiles,
                'filter':filterops
                })