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

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

Remove the selectedItems class from stubB and put into its own separate class
+ add additional documentation to viewItems and selectedItems python scripts.

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