source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/viewItems.py @ 3611

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/viewItems.py@3611
Revision 3611, 2.9 KB checked in by cbyrom, 11 years ago (diff)

Add redirect in controller for viewItems if not items are currently selected - to avoid page crash.

Line 
1#
2# Controller for the 'View' tab - allowing the display of WMC map layers
3#
4# $Id$
5#
6from ows_server.lib.base import *
7from paste.request import parse_querystring
8from ows_server.models import Utilities
9from ows_server.lib.wmc_util import *
10from ows_server.models import stubB
11import copy
12
13class ViewitemsController(BaseController):
14   
15    def index(self):
16        self.inputs=dict(parse_querystring(request.environ))
17        c.wmcURL = ""
18        # check if all we're doing is removing a view item
19        if 'removeItem' in self.inputs:
20            return self.removeViewItem(self.inputs['removeItem'])
21       
22        # check if we're doing an AJAX callback to get some WMC data
23        if 'REQUEST' in self.inputs and self.inputs['REQUEST'] == 'GetWebMapContext':
24            return GetWebMapContext(self)
25       
26        # otherwise, we can get here by two routes:
27        # i) either by clicking on the WMC icon in the details view - if so, get passed endpoint and add to
28        #    selected items;
29        # ii) or from the selections tab - which will already have set up the correct selected items
30           
31        # if ENDPOINT specified, we've reached the page via the WMC icon
32        if ('ENDPOINT' in self.inputs):
33            self.addViewItem(self.inputs['ENDPOINT'])
34       
35        # avoid page crashing if we come here without view items defined
36        if 'viewItems' not in session:
37            h.redirect_to(h.url_for(controller='discovery'))
38                                       
39        session.save()
40       
41        # check if page has been visited before; if not display tab
42        if (Utilities.isTabRequired(c.pageTabs, 'View')):
43            c.pageTabs.append(('View', h.url_for(controller='viewItems',action='index')))
44
45        return render('viewItems')
46
47
48    # add a selected item to the session
49    # - if this is the first item, then display the selections tab
50    def addViewItem(self,endpoint):
51       
52        item = stubB.SelectedItem(None, None, None, endpoint)
53       
54        selections = [item,]
55        # avoid duplicates
56        if 'viewItems' in session:
57            for selection in session['viewItems']:
58                if selection.wmcURL != endpoint:
59                    selections.append(selection)
60                   
61        session['viewItems'] = selections
62        session.save()
63       
64   
65    # Remove view item from session data
66    # - NB, do this by rebuilding the session data
67    # without the input data included
68    def removeViewItem(self,endpoint):
69        selections = []
70        for selection in session['viewItems']:
71            if selection.wmcURL != endpoint:
72                selections.append(selection)
73               
74        # if the new list is empty, remove the session variable
75        if len(selections) == 0:
76            del session['viewItems']
77            c.UpdatePageTabs=1
78        else:
79            session['viewItems'] = selections
80
81        session.save()
82       
Note: See TracBrowser for help on using the repository browser.