Exemplo n.º 1
0
    def questionnaire_export(self,
                             report_id,
                             REQUEST,
                             answers=None,
                             type='excel'):
        """ Exports the report in excel or pdf format """
        report = self.getReport(report_id)
        if not report:
            raise NotFound('Report %s' % (report_id, ))
        if answers is None:
            answers = self.getAnswers()
        if type == 'excel':
            ret = self.generate_excel(report, answers=answers)
            content_type = 'application/vnd.ms-excel'
            filename = '%s Export.xls' % report.id
        elif type == 'pdf':
            ret = self.generate_pdf(report_id)
            content_type = 'application/pdf'
            filename = '%s Export.pdf' % report.id
        else:
            raise NotImplemented

        if REQUEST is not None:
            filesize = len(ret)
            set_response_attachment(REQUEST.RESPONSE, filename, content_type,
                                    filesize)
        return ret
Exemplo n.º 2
0
 def view_my_answer_html(self, REQUEST):
     """Display a page with the answer of the current user"""
     answer = self.getMyAnswer()
     if answer is None:
         raise NotFound("You haven't taken this survey")
         # TODO: replace with a proper exception/error message
     return answer.index_html(REQUEST=REQUEST)
Exemplo n.º 3
0
def forum_publish_save(context, REQUEST):
    scrub = scrubber.Scrubber().scrub
    response = {"status": "success"}
    content = REQUEST.form["content"]
    topic = _get_topic(context, REQUEST.form["topic"])
    filename = REQUEST.form["filename"]

    if hasattr(topic, "forum_publish_objects"):
        content = scrub(content)
        site = context.getSite()
        doc = get_document_or_create(site, title=filename)

        doc_content = doc.getLocalAttribute("body",
                                            site.gl_get_selected_language())
        doc_content += content
        # update Naaya document
        doc.set_localpropvalue("body", site.gl_get_selected_language(),
                               doc_content)
        # doc.body = content
        doc.recatalogNyObject(doc)

        # clear preview document
        _clear_preview(context, REQUEST.form["topic"])

        response["url"] = doc.absolute_url()
        REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
        return simplejson.dumps(response)
    else:
        raise NotFound("No objects to publish")
Exemplo n.º 4
0
 def notFoundError(self, entry='Unknown'):
     self.setStatus(404)
     raise NotFound(
         self._error_html(
             "Resource not found",
             "Sorry, the requested resource does not exist." +
             "<p>Check the URL and try again.</p>" +
             "<p><b>Resource:</b> %s</p>" % escape(entry)))
Exemplo n.º 5
0
 def getLinksListById(self, p_id):
     #return the links list with the given id
     if not p_id:
         ob = None
     else:
         try:
             ob = self._getOb(p_id)
         except AttributeError:
             raise NotFound('links group %s' % (p_id, ))
         if ob.meta_type != METATYPE_LINKSLIST:
             ob = None
     return ob
Exemplo n.º 6
0
    def viewer_view_report_html(self, REQUEST):
        """View the report for the viewer"""
        if REQUEST.form.has_key('review_template'):
            review_template = self.aq_parent['tools']['general_template']['general-template']
            report = review_template.getSurveyTemplate().getReport('viewer')
        elif REQUEST.form.has_key('library'):
            library = self.aq_parent['tools']['virtual_library']['bibliography-details-each-assessment']
            report = library.getSurveyTemplate().getReport('viewer')
        else:
            #the function was called directly, without parameters
            return None

        if not report:
            raise NotFound('Report %s' % ('viewer',))
        if REQUEST.has_key('answer_ids'):
            answers_list = REQUEST.get('answer_ids', [])
            if isinstance(answers_list, basestring):
                answers_list = [answers_list]
            if answers_list:
                answers = [getattr(report, answer) for answer in answers_list]
                return report.questionnaire_export(report_id='viewer', REQUEST=REQUEST, answers=answers)
        else:
            return report.questionnaire_export(REQUEST=REQUEST, report_id='viewer', answers=[])
        return REQUEST.RESPONSE.redirect(REQUEST.HTTP_REFERER)
Exemplo n.º 7
0
 def debugError(self, entry):
     raise NotFound(
         self._error_html(
             "Debugging Notice",
             "Zope has encountered a problem publishing your object.<p>"
             "\n%s</p>" % entry))
Exemplo n.º 8
0
 def questionnaire_view_report_html(self, report_id, REQUEST):
     """View the report report_id"""
     report = self.getReport(report_id)
     if not report:
         raise NotFound('Report %s' % (report_id, ))
     return report.view_report_html(answers=self.getAnswers())
Exemplo n.º 9
0
def _get_topic(context, title):
    try:
        return context[title]
    except KeyError:
        raise NotFound("Topic not found")