source: publico/ILSAPL/branches/2.5/lexml/SAPLOAIServer.py @ 7145

Última Alteração nesse arquivo desde 7145 foi 7145, incluída por gustavolepri, 7 anos atrás

fix bug em relacao as consultas

File size: 4.5 KB
Linha 
1# -*- coding: utf-8 -*-
2
3from datetime import datetime
4from DateTime import DateTime
5from OFS import SimpleItem, Folder
6import Globals
7import Acquisition
8from Persistence import Persistent
9from Globals import PersistentMapping
10from AccessControl import ClassSecurityInfo, Permissions
11from Products.PageTemplates.PageTemplateFile import PageTemplateFile
12import time, os, sys
13
14from OAI import OAIServerFactory
15
16from oaipmh import client, metadata, error, server
17from oaipmh.datestamp import datetime_to_datestamp
18
19from Products.CMFCore.utils import getToolByName
20
21manage_addSAPLOAIServerForm = PageTemplateFile('www/addSAPLOAIServer', globals())
22manage_addSAPLOAIServerForm.__name__='addSAPLOAIServer'
23
24def manage_addSAPLOAIServer(self, email, titulo, batch_size, base_url, id='oai', REQUEST=None):
25    """Adicionar um servidor OAI para integracao com o LeXML.
26    """
27    SAPL_OAI = SAPLOAIServer(email,titulo,batch_size,base_url)
28    self._setObject(id, SAPL_OAI)
29    if REQUEST is None:
30        return
31    try:
32        u = self.DestinationURL()
33    except:
34        u = REQUEST['URL1']
35    if REQUEST.has_key('submit_edit'):
36        u = "%s/%s" % (u, urllib.quote(id))
37    REQUEST.RESPONSE.redirect(u+'/manage_main')
38
39class SAPLOAIServer(SimpleItem.SimpleItem,Persistent):
40    """ """
41   
42    security = ClassSecurityInfo()
43    meta_type = 'SAPL OAI Server'
44    manage_options = (
45        {'label':'Editar', 'action':'manage_main'},
46        ) + SimpleItem.SimpleItem.manage_options
47
48    def __init__(self, email, titulo, batch_size, base_url):
49        self.id = 'oai'
50        self._titulo = titulo
51        self._email = email
52        self._batch_size = batch_size
53        self._base_url = base_url
54
55    manage_editForm = PageTemplateFile(
56        "www/editSAPLOAIServer", globals(), __name__='manage_editForm')
57    manage_main = manage_editForm
58
59    security.declareProtected('View management screens', 'manage_edit')
60    def manage_edit(self, email, titulo,batch_size, base_url, REQUEST=None):
61        """Edit settings.
62        """
63       
64        if titulo:
65            self._titulo = titulo
66        if email:
67            self._email = email
68        if batch_size:
69            self._batch_size = batch_size
70        if base_url:
71            self._base_url = base_url
72        if REQUEST is not None:
73            return self.manage_main(manage_tabs_message="Configurações alteradas")
74
75    def config(self):
76        config = {}
77        config['titulo'] = self.get_nome_repositorio()
78        config['email'] = self.get_email()
79        config['base_url'] = self.get_base_url()
80        config['metadata_prefixes'] = ['oai_lexml',]
81        config['descricao'] = self.get_descricao_casa()
82        config['batch_size'] = self.get_batch_size()
83        config['content_type'] = None,
84        config['delay'] = 0,
85        config['base_asset_path']=None
86        return config
87
88    def get_nome_repositorio(self):
89        return self._titulo
90   
91    def get_email(self):
92        emails = []
93        emails.append(self._email)
94        return emails
95
96    def get_descricao_casa(self):
97        descricao = ''
98        consulta = self.zsql.lexml_provedor_obter_zsql()
99        if consulta:
100            descricao = consulta[0].xml_provedor
101            if descricao:
102                descricao = descricao.encode('utf-8')
103        return descricao
104
105    def get_batch_size(self):
106        return int(self._batch_size)
107   
108    def get_base_url(self):
109        return self._base_url
110
111    def index_html(self, REQUEST=None,RESPONSE=None):
112        """ processa os argumentos recebidos pela URL
113        """
114        if REQUEST is not None:
115            return self.handle_request(req=REQUEST)
116        else:
117            return None
118
119    def write(self, req, data, mimetype,RESPONSE=None):
120        """ Retorna os dados para o cliente
121        """
122        req.RESPONSE.setHeader('Content-Type' , mimetype)
123        req.RESPONSE.setHeader('Content-Length' ,len(data))
124        return data.decode('utf-8').encode('ascii', 'xmlcharrefreplace')
125
126    def handle_request(self, req,RESPONSE=None):
127        if not req.URL.startswith(self._base_url):
128            return req.RESPONSE.setStatus('500 Internal Server Error',
129                 u'The url "%s" does not start with base url "%s".' % (req.URL,
130                                                                      self._base_url))
131        sapl_tool = getToolByName(self,'portal_sapl')
132        oai_server = OAIServerFactory(sapl_tool, self.config())
133        return self.write(req, oai_server.handleRequest(req.form),'text/xml',RESPONSE)
134
135   
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.