source: MSI/Discovery/trunk/DI01-LoggingFramework/urlRedirection/trunk/ndgredirect/controllers/ndgURLredirect.py @ 5427

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MSI/Discovery/trunk/DI01-LoggingFramework/urlRedirection/trunk/ndgredirect/controllers/ndgURLredirect.py@5427
Revision 5427, 1.5 KB checked in by sdonegan, 11 years ago (diff)

Update ndg url tracking code

Line 
1import logging,urllib
2from urlparse import urlparse
3from ndgredirect.lib.base import *
4from ndgredirect.lib.urlRedirectDB import urlRedirectDB
5log = logging.getLogger(__name__)
6
7class NdgurlredirectController(BaseController):
8
9
10    def index(self):
11        # Return a rendered template
12        #   return render('/some/template.mako')
13        # or, Return a response
14        return 'Redirection service COPACETIC (whatever that means but it sounds good)'
15
16
17    def redirect(self):
18       
19        #Method to parse useful info from ndg redirect url and store in database to make interesting usage reports
20        #on what users are doing and where they are a headed.
21               
22        url_as_string = urllib.unquote(request.params['url']).encode('utf-8')
23       
24       
25        datasetURL = url_as_string
26        datasetID = request.params['docID']
27        datasetTitle = request.params['docTitle']
28        originatingIp = "not.yet.known.really"
29       
30        #fudge until we get a proper config file sorted...
31        configFileName = '/usr/local/ndg-redirect/config/redirect.config'
32         
33        #now update database   
34        try:     
35            urlRedirectDB(datasetURL,datasetID,datasetTitle,originatingIp,configFileName)
36            logging.info("Successfully updated url redirection database")
37           
38        except:
39            logging.warn("Failed at updating url redirection database")
40           
41        #perform redirect
42        redirect_to( url_as_string )
43       
44   
Note: See TracBrowser for help on using the repository browser.