Example #1
0
    def _process(self):

        if not self._target.isScheduled():
            raise NoReportError(
                _("You cannot export the contribution with id %s because it is not scheduled"
                  ) % self._target.getId())

        filename = "%s-Contribution.ics" % self._target.getTitle()

        hook = ContributionHook({}, 'contribution', {
            'event': self._conf.getId(),
            'idlist': self._contrib.getId(),
            'dformat': 'ics'
        })
        res = hook(self.getAW(), self._req)
        resultFossil = {'results': res[0]}

        serializer = Serializer.create('ics')
        data = serializer(resultFossil)

        self._req.headers_out["Content-Length"] = "%s" % len(data)
        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType("ICAL")
        self._req.content_type = """%s""" % (mimetype)
        self._req.headers_out[
            "Content-Disposition"] = """inline; filename="%s\"""" % cleanHTMLHeaderFilename(
                filename)
        return data
Example #2
0
    def _process( self ):

        hook = CategoryEventHook({'from': ['today']}, 'categ', {'idlist':self._target.getId(), 'dformat': 'atom'})
        res = hook(self.getAW(), self._req)
        resultFossil = {'results': res[0], 'url': str(self._uh.getURL(self._target))}

        serializer = Serializer.create('atom')
        data = serializer(resultFossil)

        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType( "ATOM" )
        self._req.content_type = """%s"""%(mimetype)

        return data
Example #3
0
    def _process( self ):
        filename = "%s-Session.ics"%self._session.getTitle()

        hook = SessionHook({}, 'session', {'event': self._conf.getId(), 'idlist':self._session.getId(), 'dformat': 'ics'})
        res = hook(self.getAW(), self._req)
        resultFossil = {'results': res[0]}

        serializer = Serializer.create('ics')
        data = serializer(resultFossil)

        self._req.headers_out["Content-Length"] = "%s"%len(data)
        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType( "ICAL" )
        self._req.content_type = """%s"""%(mimetype)
        self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename.replace("\r\n"," ")
        return data
Example #4
0
    def _process( self ):
        filename = "%s-Session.ics"%self._session.getTitle()

        hook = SessionHook({}, 'session', {'event': self._conf.getId(), 'idlist':self._session.getId(), 'dformat': 'ics'})
        res = hook(self.getAW(), self._req)
        resultFossil = {'results': res[0]}

        serializer = Serializer.create('ics')
        data = serializer(resultFossil)

        self._req.headers_out["Content-Length"] = "%s"%len(data)
        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType( "ICAL" )
        self._req.content_type = """%s"""%(mimetype)
        self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%cleanHTMLHeaderFilename(filename)
        return data
Example #5
0
    def _process( self ):
        filename = "%s-Categ.ics"%self._target.getName().replace("/","")

        hook = CategoryEventHook({}, 'categ', {'idlist':self._target.getId(), 'dformat': 'ics'})
        res = hook(self.getAW(), self._req)
        resultFossil = {'results': res[0]}

        serializer = Serializer.create('ics')
        data = serializer(resultFossil)

        self._req.headers_out["Content-Length"] = "%s"%len(data)
        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType( "ICAL" )
        self._req.content_type = """%s"""%(mimetype)
        self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%cleanHTMLHeaderFilename(filename)

        return data
Example #6
0
    def _process( self ):

        if not self._target.isScheduled():
            raise NoReportError(_("You cannot export the contribution with id %s because it is not scheduled")%self._target.getId())

        filename = "%s-Contribution.ics"%self._target.getTitle()

        hook = ContributionHook({}, 'contribution', {'event': self._conf.getId(), 'idlist':self._contrib.getId(), 'dformat': 'ics'})
        res = hook(self.getAW(), self._req)
        resultFossil = {'results': res[0]}

        serializer = Serializer.create('ics')
        data = serializer(resultFossil)

        self._req.headers_out["Content-Length"] = "%s"%len(data)
        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType( "ICAL" )
        self._req.content_type = """%s"""%(mimetype)
        self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename.replace("\r\n"," ")
        return data
Example #7
0
    def _process(self):

        hook = CategoryEventHook({'from': ['today']}, 'categ', {
            'idlist': self._target.getId(),
            'dformat': 'atom'
        })
        res = hook(self.getAW(), self._req)
        resultFossil = {
            'results': res[0],
            'url': str(self._uh.getURL(self._target))
        }

        serializer = Serializer.create('atom')
        data = serializer(resultFossil)

        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType("ATOM")
        self._req.content_type = """%s""" % (mimetype)

        return data
Example #8
0
    def _process(self):
        filename = "%s-Categ.ics" % self._target.getName().replace("/", "")

        hook = CategoryEventHook({}, 'categ', {
            'idlist': self._target.getId(),
            'dformat': 'ics'
        })
        res = hook(self.getAW(), self._req)
        resultFossil = {'results': res[0]}

        serializer = Serializer.create('ics')
        data = serializer(resultFossil)

        self._req.headers_out["Content-Length"] = "%s" % len(data)
        cfg = Config.getInstance()
        mimetype = cfg.getFileTypeMimeType("ICAL")
        self._req.content_type = """%s""" % (mimetype)
        self._req.headers_out[
            "Content-Disposition"] = """inline; filename="%s\"""" % cleanHTMLHeaderFilename(
                filename)

        return data
Example #9
0
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""
simplejson-based fossil serializer
"""
# indico imports
from indico.util import json

# module imports
from indico.util.metadata.serializer import Serializer


class JSONSerializer(Serializer):

    """
    Does basically direct translation from the fossi
    """

    _mime = 'application/json'

    def __call__(self, fossil):
        return json.dumps(fossil, pretty=self.pretty)


Serializer.register('json', JSONSerializer)
Example #10
0
                else:
                    break
        else:
            # No need to commit stuff if we didn't use an API key
            # (nothing was written)
            if minfo.getRoomBookingModuleActive():
                Factory.getDALManager().rollback()
                Factory.getDALManager().disconnect()
            dbi.endRequest(False)

        # Log successful POST api requests
        if error is None and req.method == 'POST':
            logger.info('API request: %s?%s' % (path, query))

        serializer = Serializer.create(dformat,
                                       pretty=pretty,
                                       typeMap=typeMap,
                                       **remove_lists(queryParams))

        if error:
            resultFossil = fossilize(error)
        else:
            iface = None
            if mode == 'export':
                iface = IHTTPAPIExportResultFossil
            resultFossil = fossilize(
                HTTPAPIResult(result, path, query, ts, complete, extra), iface)

        del resultFossil['_fossil']

        try:
Example #11
0
File: xml.py Project: bubbas/indico
                            else:
                                subelem = etree.SubElement(elem, 'item')
                                subelem.text = self._convert(subv)
                elif type(v) == dict:
                    elem.append(self._xmlForFossil(v))
                else:
                    txt = self._convert(v)
                    try:
                        elem.text = txt
                    except Exception, e:
                        Logger.get('xmlSerializer').error('Setting XML text value failed: %s (id: %s)' % (e, id))


        return felement

    def __call__(self, fossil, xml_declaration=True):
        if type(fossil) == list:
            # collection of fossils
            doc = etree.ElementTree(etree.Element("collection"))
            for elem in fossil:
                self._xmlForFossil(elem, doc)
            result = doc
        else:
            result = self._xmlForFossil(fossil)

        return etree.tostring(result, pretty_print=self.pretty,
                              xml_declaration=xml_declaration, encoding='utf-8')


Serializer.register('xml', XMLSerializer)
Example #12
0
                            else:
                                subelem = etree.SubElement(elem, 'item')
                                subelem.text = self._convert(subv)
                elif type(v) == dict:
                    elem.append(self._xmlForFossil(v))
                else:
                    txt = self._convert(v)
                    try:
                        elem.text = txt
                    except Exception, e:
                        Logger.get('xmlSerializer').error('Setting XML text value failed: %s (id: %s)' % (e, id))


        return felement

    def __call__(self, fossil, xml_declaration=True):
        if type(fossil) == list:
            # collection of fossils
            doc = etree.ElementTree(etree.Element("collection"))
            for elem in fossil:
                self._xmlForFossil(elem, doc)
            result = doc
        else:
            result = self._xmlForFossil(fossil)

        return etree.tostring(result, pretty_print=self.pretty,
                              xml_declaration=xml_declaration, encoding='utf-8')


Serializer.register('xml', XMLSerializer)
Example #13
0
                    pass # retry
                else:
                    break
        else:
            # No need to commit stuff if we didn't use an API key
            # (nothing was written)
            if minfo.getRoomBookingModuleActive():
                Factory.getDALManager().rollback()
                Factory.getDALManager().disconnect()
            dbi.endRequest(False)

        # Log successful POST api requests
        if error is None and req.method == 'POST':
            logger.info('API request: %s?%s' % (path, query))

        serializer = Serializer.create(dformat, pretty=pretty, typeMap=typeMap,
                                       **remove_lists(queryParams))

        if error:
            resultFossil = fossilize(error)
        else:
            iface = None
            if mode == 'export':
                iface = IHTTPAPIExportResultFossil
            resultFossil = fossilize(HTTPAPIResult(result, path, query, ts, complete, extra), iface)

        del resultFossil['_fossil']

        try:

            if error and not serializer.schemaless:
                # if our serializer has a specific schema (HTML, ICAL, etc...)