Changeset 5023 for MILK


Ignore:
Timestamp:
23/02/09 16:52:37 (10 years ago)
Author:
cbyrom
Message:

Update TrackBack? controller to provide a meaningful 'ping' mechanism
to be accessed when trackbacks are referenced; this now emails
meaningful info (looked up using the new NDGDoc data model) to the
trackback recipient and adds the info to a new feed dedicated to
citation info.

Location:
MILK/trunk/milk_server/milk_server
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • MILK/trunk/milk_server/milk_server/config/routing.py

    r4984 r5023  
    5454 
    5555    # routing for trackback 
    56     map.connect('trackback/:uri', controller='trackback/trackback') 
     56    map.connect('trackback/:uri', controller='trackback/trackback', action='ping') 
    5757    map.connect('askCorrect/:uri', controller='trackback/trackback', action='askCorrect') 
    5858    map.connect('correct/:uri', controller='trackback/trackback', action='correct') 
  • MILK/trunk/milk_server/milk_server/controllers/trackback/trackback.py

    r4999 r5023  
    44 i) commenting on metadata 
    55 ii) referencing of metadata 
    6    
     6 
     7 NB, info on TrackBack available from: 
     8  
     9 http://www.sixapart.com/pronet/docs/trackback_spec 
     10  
    711 @author: C Byrom, Tessella Feb 2009 
    812''' 
     
    1014from milk_server.lib.mailer import mailHandler  
    1115from milk_server.lib import mailer 
     16from milk_server.models.ndgdoc import NDGDoc  
    1217from ndg.common.src.models.ndgObject import ndgObject 
     18import ndg.common.src.clients.xmldb.eXist.dbconstants as dc 
    1319 
    1420class TrackbackController(BaseController): 
     
    2228        ''' 
    2329        logging.info("Setting up TrackbackController") 
    24         self.cf=request.environ['ndgConfig'] 
     30        self.cf = request.environ['ndgConfig'] 
    2531        try: 
    26             self.uri=ndgObject(uri, config=self.cf) 
     32            self.uri=ndgObject(uri, config = self.cf) 
    2733        except ValueError,e: 
    2834            return e 
     
    3036        self.inputs = request.params 
    3137 
     38        self.ndgDoc = NDGDoc(ndgURI = uri, config = self.cf) 
    3239        logging.info("TrackbackController set up") 
    3340        return 0     
    3441 
    3542 
    36      
    37     def index(self,uri): 
     43    def ping(self, uri): 
    3844        '''  
    39         This is the default trackback receipt method. Note we haven't implemented 
    40         whitelisting yet  
     45        This is the default trackback receipt method. When a doc is referenced 
     46        from a TrackBack enabled site, this method should be invoked, via a  
     47        TrackBack ping, to notify that it has been referenced.  Log the reference 
     48        by sending a mail to the trackback recipient set in the config file and 
     49        adding an entry to the citation feed. 
     50        ( Note we haven't implemented whitelisting yet )  
     51        @param uri: ndgURI associated with the doc being pinged by trackback 
    4152        ''' 
    42         err=0 
     53        logging.info("Trackback ping called - notifying trackback recipient + feed of citation") 
     54        err = 0 
     55        status=self.__setup(uri) 
    4356         
    44         # need to receive a trackback, and mail someone ... 
    45         incoming=request.params 
    46         keys=incoming.keys() 
    47         payload='<trackback><uri>%s</uri></trackback>'%uri 
     57        # lookup referenced doc - to ensure it exists and get extra info to add 
     58        # to citation messages 
     59        self.ndgDoc.setupDocumentModel() 
     60        payload = "" 
     61        if self.ndgDoc.status: 
     62            payload = '<trackback><uri>%s</uri><title>%s</title></trackback>' %(self.ndgDoc.docModel.atomBrowseURL,  
     63                                                                                self.ndgDoc.name) 
     64        else: 
     65            err = "Could not find document, '%s', to reference in trackback" %uri 
    4866         
    49         # make sure we have both url and title 
    50         if 'url' not in keys and 'title' not in keys: 
    51             err='Incomplete trackback, need both url and title at the every least' 
    52         for key in keys: 
    53             payload+='<%s>%s</%s>'%(key,incoming[key],key) 
     67        server = self.cf.get('DEFAULT', 'mailserver') 
     68        if server is None: 
     69            err = 'Server not configured for trackback (no mail server)' 
    5470         
    55         # now get server and trackback recipient. 
    56         self.cf=request.environ['ndgConfig'] 
    57          
    58         server=self.cf.get('DEFAULT','mailserver',None) 
    59         if server is None: 
    60             err='Server not configured for trackback (no mail server)' 
    61          
    62         recipient=self.cf.get('DEFAULT','tbrecipient',None) 
     71        recipient=self.cf.get('DEFAULT', 'tbrecipient') 
    6372        if recipient is None: 
    64             err='Server not configured for trackback (no recipient)' 
     73            err = 'Server not configured for trackback (no recipient)' 
    6574         
    6675        body='Citation Trackback for %s\n\n\n%s'% (uri, payload) 
    6776        name='CitationTrackbackFor_%s.xml'%uri 
    6877         
    69         if err!=0: 
    70             c.message=err 
    71             c.err=1 
     78        if err != 0: 
     79            c.message = err 
     80            c.err = 1 
    7281        else:  
    73             status,message=mailHandler([recipient,],body,body,xmlAttachments=[(payload,name),], 
    74                 server=server) 
     82            logging.info("Sending notification mail to '%s'" %recipient) 
     83            status, message=mailHandler([recipient,], body, body, 
     84                                        xmlAttachments = [(payload, name),], 
     85                                        server = server) 
    7586            if status: 
    76                 c.err=0 
     87                c.err = 0 
    7788            else: 
    78                 c.err=1 
    79                 c.message='Unable to forward trackback to designated recipient [%s]'%message 
     89                c.err = 1 
     90                c.message = 'Unable to forward trackback to designated recipient [%s]' %message 
     91 
     92            # lastly, add to citation feed 
     93            logging.info("Mail sent - now add data to the citations feed") 
     94            g.validator._atomClient.feedClient.createGenericFeedEntry(name, payload, 
     95                                                                      dc.CITATIONS_COLLECTION_PATH) 
    8096         
    8197        response.headers['content-type'] = 'text/xml' 
    82         return render('trackback',format='xml') 
     98 
     99        logging.info("Trackback logged - now sending receipt") 
     100        return render('genshi', 'trackback/trackback',format='xml') 
    83101     
    84102 
     
    100118            trackback:ping="%s" /> 
    101119        </rdf:RDF> 
    102         -->'''%(uri,g.server+h.url_for(),name,g.server+h.url_for(controller="trackback/trackback")) 
     120        -->'''%(uri,g.server+h.url_for(),name, 
     121                g.server+h.url_for(controller="trackback/trackback", action="ping")) 
    103122        return s 
    104123 
     
    117136 
    118137        try: 
    119             html =  render("genshi", 'correct',fragment=True) 
     138            html =  render("genshi", 'trackback/correct',fragment=True) 
    120139        except Exception, e: 
    121140            logging.error("Error experienced whilst rendering 'correct' template: %s" %e) 
     
    125144 
    126145     
    127     def correct(self,uri): 
     146    def correct(self, uri): 
    128147        '''  
    129148        Receive a correction form to update a record and post it to the holder  
     
    132151            "maintainer + added to the corrections feed") 
    133152        status=self.__setup(uri) 
    134 #        if 'ndgSec' not in session: 
    135         if 'ndgSec' in session: 
     153        if 'ndgSec' not in session: 
    136154            c.xml = 'Error - user not currently logged in.  Please login before submitting user comments.' 
    137155            logging.error(c.xml) 
     
    157175        # add the maintainer info 
    158176        body += " - for metadata maintainer, '%s'" %maintainer  
    159         g.validator._atomClient.feedClient.createCorrectionsFeedEntry(body, payload) 
     177        g.validator._atomClient.feedClient.createGenericFeedEntry(body, payload, 
     178                                                                  dc.CORRECTIONS_COLLECTION_PATH) 
    160179 
    161180        g.correctionPosted = result  
Note: See TracChangeset for help on using the changeset viewer.