source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/trackback.py @ 3536

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/trackback.py
Revision 3536, 1.9 KB checked in by cbyrom, 12 years ago (diff)

Upgrade the server code to make consistent with newer pylons codebase - v0.9.6.1.
This mainly involves the replacement of the Response object, and associated methods,
with the inbuild, default response object. Typical changes include:

render_response -> render - with required settings on the response object
made before the render call against the response object

Response(...) -> response.write() - for content + response.headers.. = .. for headers info

  • also included the replacement of depricated functions, as highlighted by

the server logging

Line 
1from ows_server.lib.base import *
2from ows_server.lib.mailer import mailHandler
3class TrackbackController(BaseController):
4    ''' Provides the pylons controller for recieving trackbacks to NDG documents '''
5    def index(self,uri):
6        ''' This is the default trackback receipt method. Note we haven't implemented
7        whitelisting yet '''
8       
9        err=0
10       
11        # need to receive a trackback, and mail someone ...
12       
13        incoming=request.params
14        keys=incoming.keys()
15        payload='<trackback><uri>%s</uri></trackback>'%uri
16       
17        #make sure we have both url and title
18        if 'url' not in keys and 'title' not in keys:
19            err='Incomplete trackback, need both url and title at the every least'
20        for key in keys:
21            payload+='<%s>%s</%s>'%(key,incoming[key],key)
22       
23        #now get server and trackback recipient.
24        self.cf=request.environ['ndgConfig']
25       
26        server=self.cf.get('DEFAULT','mailserver',None)
27        if server is None:
28            err='Server not configured for trackback (no mail server)'
29       
30        recipient=self.cf.get('DEFAULT','tbrecipient',None)
31        if recipient is None:
32            err='Server not configured for trackback (no recipient)'
33       
34        body='Citation Trackback for %s\n\n\n%s'% (uri, payload)
35        name='CitationTrackbackFor_%s.xml'%uri
36       
37       
38           
39        if err!=0:
40            c.message=err
41            c.err=1
42        else: 
43            status,message=mailHandler([recipient,],body,body,xmlAttachments=[(payload,name),],
44                server=server)
45            if status:
46                c.err=0
47            else:
48                c.err=1
49                c.message='Unable to forward trackback to designated recipient [%s]'%message
50       
51        response.headers['content-type'] = 'text/xml'
52        return render('trackback',format='xml')
Note: See TracBrowser for help on using the repository browser.