def render(self): """ """ content = self.context.aq_inner # Read portlet assignment pointers from the GET query name = self.request.form.get("portletName") manager = self.request.form.get("portletManager") imageId = self.request.form.get("image") key = self.request.form.get("portletKey", None) if not key: # This is probably a bot trying to fetch the image # and clearing the query string return "Bad query string - no image available" portlet = self.getPortletById(content, manager, key, name) if not portlet: raise InternalError("Portlet not found: %s %s" % (key, name)) image = getattr(portlet, imageId, None) if not image: # Ohops? raise InternalError("Image was empty: %s" % imageId) # Set content type and length headers set_headers(image, self.request.response) # Push data to the downstream clients return stream_data(image)
def PUT(self, REQUEST=None, RESPONSE=None): """PUT support""" # XXX we may want to make this more modular/pluggable at some point # to allow more content-types (+ transformations) if REQUEST is None: REQUEST = self.REQUEST if RESPONSE is None: RESPONSE = REQUEST.RESPONSE editable = self.get_editable() if editable is None: raise InternalError('No editable version available') content = REQUEST['BODYFILE'].read() content_type = self._get_content_type_from_request(REQUEST, content) if content_type not in ['text/html', 'application/xhtml+xml']: raise InternalError('Input format not supported') editable.set_document_xml_from(content, request=REQUEST)
def testCustomExceptionViewInternalError(self): from zExceptions import InternalError registerExceptionView(IException) environ = self._makeEnviron() start_response = DummyCallable() _publish = DummyCallable() _publish._raise = InternalError('argh') app_iter = self._callFUT(environ, start_response, _publish) body = b''.join(app_iter) self.assertEqual(start_response._called_with[0][0], '500 Internal Server Error') self.assertTrue(b'Exception View: InternalError' in body)
def badRequestError(self, name): self.setStatus(400) if re.match('^[A-Z_0-9]+$', name): raise InternalError(self._error_html( "Internal Error", "Sorry, an internal error occurred in this resource.")) raise BadRequest(self._error_html( "Invalid request", ("The parameter, <em>" + name + "</em>, " "was omitted from the request.<p>" "Make sure to specify all required parameters, " "and try the request again.</p>")))
def badRequestError(self, name): if re.match('^[A-Z_0-9]+$', name): self.setStatus(500) exc = InternalError(name) exc.title = 'Internal Error' exc.detail = 'Sorry, an internal error occurred in this resource.' raise exc self.setStatus(400) exc = BadRequest(name) exc.title = 'Invalid request' exc.detail = ('The parameter, <em>%s</em>, ' 'was omitted from the request.<p>' 'Make sure to specify all required parameters, ' 'and try the request again.</p>' % name) raise exc
def badRequestError(self, name): if re.match('^[A-Z_0-9]+$', name): self.setStatus(500) exc = InternalError(name) exc.title = 'Internal Error' exc.detail = 'Sorry, an internal error occurred in this resource.' raise exc self.setStatus(400) exc = BadRequest(name) exc.title = 'Invalid request' exc.detail = ( 'The parameter, <em>%s</em>, ' 'was omitted from the request.<p>' 'Make sure to specify all required parameters, ' 'and try the request again.</p>' % name) raise exc
def catch_all_response(self, exc): response = InternalError() response.detail = repr(exc) return response
def query(self, soup): self._get_buyables_in_context() req_group_id = self.request.get('group_by', 'email') # if no req group is set if len(req_group_id) == 0: req_group_id = 'email' if req_group_id not in vocabs.groups_vocab(): raise InternalError('Group not allowed!') # not pretty but, otherwise there a problems with vocab + soup attrs # that need many places to refactor to make it work if req_group_id == 'buyable': req_group_id = 'buyable_uid' group_index = soup.catalog[req_group_id] booking_uids = soup.catalog['uid'] req_from_date = self.request.get('from_date', '') req_to_date = self.request.get('to_date', '') req_text = self.request.get('search[value]', '') date_query = self._datetime_checker(req_from_date, req_to_date) text_query = self._text_checker(req_text) if date_query and not text_query: dummysize, bookings_set = soup.catalog.query(date_query) elif text_query and not date_query: dummysize, bookings_set = soup.catalog.query(text_query) elif date_query and text_query: query = date_query & text_query dummysize, bookings_set = soup.catalog.query(query) else: bookings_set = booking_uids._rev_index.keys() bookings_set = set(bookings_set) buyable_index = soup.catalog['buyable_uid'] buyables_set = set() # get all buyables for the current context/path for buyable_uid in self._get_buyables_in_context(): try: buyables_set.update(buyable_index._fwd_index[buyable_uid]) except KeyError: continue # filter bookings_set to only match the current context/path bookings_set = bookings_set.intersection(buyables_set) unique_group_ids = [] # for each booking which matches the query append the qroup id once for group_id, group_booking_ids in group_index._fwd_index.items(): if bookings_set.intersection(group_booking_ids): unique_group_ids.append(group_id) res = odict() size = len(unique_group_ids) # for each unique group id get the matching group booking ids for group_id in self.slice(unique_group_ids): res[group_id] = [] for group_booking_id in group_index._fwd_index[group_id]: if group_booking_id in bookings_set: res[group_id].append(soup.get(group_booking_id)) return size, res
def query(self, soup): self._get_buyables_in_context() req_group_id = self.request.get('group_by', 'email') # if no req group is set if len(req_group_id) == 0: req_group_id = 'email' if req_group_id not in vocabs.groups_vocab(): raise InternalError('Group not allowed!') # not pretty but, otherwise there a problems with vocab + soup attrs # that need many places to refactor to make it work if req_group_id == 'buyable': req_group_id = 'buyable_uid' group_index = soup.catalog[req_group_id] # TODO: This was the fastest produceable way for me to # have an empty query to start with and concenate the rest. queries = [] # fetch user vendor uids vendor_uids = get_vendor_uids_for() # filter by given vendor uid or user vendor uids vendor_uid = self.request.form.get('vendor') if vendor_uid: vendor_uid = uuid.UUID(vendor_uid) # raise if given vendor uid not in user vendor uids if vendor_uid not in vendor_uids: raise Unauthorized queries.append(Eq('vendor_uid', vendor_uid)) # filter by customer if given customer = self.request.form.get('customer') if customer: queries.append(Eq('creator', customer)) # Filter by state if given state = self.request.form.get('state') if state: queries.append(Eq('state', state)) # Filter by salaried if given salaried = self.request.form.get('salaried') if salaried: queries.append(Eq('salaried', salaried)) req_from_date = self.request.get('from_date', '') req_to_date = self.request.get('to_date', '') date_query = self._datetime_checker(req_from_date, req_to_date) if date_query: queries.append(date_query) req_text = self.request.get('search[value]', '') text_query = self._text_checker(req_text) if text_query: queries.append(text_query) if queries: # TODO: See the TODO above. query = queries[0] for q in queries[1:]: query = query & q dummysize, bookings_set = soup.catalog.query(query) else: booking_uids = soup.catalog['uid'] bookings_set = booking_uids._rev_index.keys() bookings_set = set(bookings_set) buyable_index = soup.catalog['buyable_uid'] buyables_set = set() # get all buyables for the current context/path for buyable_uid in self._get_buyables_in_context(): try: buyables_set.update(buyable_index._fwd_index[buyable_uid]) except KeyError: continue # filter bookings_set to only match the current context/path bookings_set = bookings_set.intersection(buyables_set) unique_group_ids = [] # for each booking which matches the query append the qroup id once for group_id, group_booking_ids in group_index._fwd_index.items(): if bookings_set.intersection(group_booking_ids): unique_group_ids.append(group_id) res = odict() size = len(unique_group_ids) # for each unique group id get the matching group booking ids for group_id in self.slice(unique_group_ids): res[group_id] = [] for group_booking_id in group_index._fwd_index[group_id]: if group_booking_id in bookings_set: res[group_id].append(soup.get(group_booking_id)) return size, res
def f(): raise InternalError("argh")