def get(cls, post_id=None, as_json=False): render = cls._render_json if as_json else cls._render_html post = get_or_404(PostManager.get_by_id, post_id) attachment = get_or_404(post.get_attachment) metadata = attachment.get_metadata() previous, next = PostManager.get_adjacent_by_id(post_id) return render(post, attachment, metadata, previous, next)
def get(cls, since_id=None, until_id=None, as_json=False): if since_id is not None and until_id is not None: abort(400) render = cls._render_json if as_json else cls._render_html mode = IndexView.MODE_SINCE if since_id is not None else IndexView.MODE_UNTIL posts, has_next = get_or_404(PostManager.get_all, since_id=since_id, until_id=until_id, limit=cls.ITEM_LIMIT) return render(posts, has_next, mode)
def get(attachment_id=None, dimensions=''): if dimensions in current_app.config['ALLOWED_DIMENSIONS']: width, height, allow_crop = AttachmentManager.decode_dimensions(dimensions) else: current_app.logger.debug('`%s` is not in ALLOWED_DIMENSIONS', dimensions) allow_crop = True width = height = None attachment = get_or_404(AttachmentManager.get_by_id, attachment_id) derivative = attachment.get_derivative(width, height, allow_crop=allow_crop) if current_app.debug: response = make_response(derivative.get_data()) else: response = make_response() response.headers['X-Accel-Redirect'] = derivative.get_sendfile_url() response.headers['Content-Type'] = derivative.mime_type return response