예제 #1
0
    def get(self, topic, year, month, slug, post_uuid):
        printable_view = self.get_arguments('printable')

        idx = self.meta.search_index

        meta_post, related_posts = yield get_one_document(idx, post_uuid)

        if meta_post is None:
            # could not find the blog post entry
            # by the uuid in the url bar..give a 404
            # for now, work on a redirection strategy later.
            self.send_error(status_code=404)

        else:
            meta, post = meta_post, meta_post.results[0]
            self.render_html('pages/blog_post.html',
                     post=post, meta=meta, related=related_posts, printable=printable_view)
예제 #2
0
    def get(self, form=None):
        # are we looking at a single document, or a list of documents?
        by_id = self.get_argument('post_id', None)

        all_posts = yield get_all_documents(self.meta.search_index)

        if form is None:
            form = BlogPostForm()

        if by_id:
            post, _ = yield get_one_document(self.meta.search_index, by_id=by_id)
            post = post.results[0]
            if post:

                for f in FIELDS:
                    getattr(form, f, f).data = post[f]

        else:
            post = None

        new_doc = by_id is None

        self.render_html('pages/create.html', all_posts=all_posts, new_doc=new_doc,
                         form=form, post=post, errors=form.errors)
예제 #3
0
    def post(self):
        # validate the form
        form = BlogPostForm(self.request.arguments)

        if not form.validate():
            self.set_status(400)
            logger.error(form.errors)
            self.get(form)
            return

        by_id = self.get_argument('post_id', None)
        idx = self.meta.search_index

        if by_id:
            # updating document
            post, _ = yield get_one_document(self.meta.search_index, by_id=by_id)
            fields = post.results[0]
        else:
            # document doesn't exist, potentially
            fields = get_default_schema(idx.schema)

        # clean missing fields
        if fields['pmeta'] is None: fields['pmeta'] = '{}'
        if fields['created'] is None: fields['created'] = fields['modified']

        fields.update({f:self.get_argument(f) for f in FIELDS})
        for f in LOWER_FIELDS:
            fields[f] = fields[f].lower()

        clear_statics = self.get_arguments('clear_statics') == 'y'
        clear_banner = self.get_arguments('clear_banner') == 'y'

        if clear_statics:
            fields['statics'] = None

        if clear_banner:
            fields['banner'] = None

        banner_file = self.request.files.get('banner', None)

        # there was a file upload with this post
        if banner_file:
            for f in banner_file:
                fields['banner'] = process_banner_file(f, self.meta.settings.media, by_id)

        redirect_url = '/admin/create'
        is_delete = fields['title'] in ('DELETE',)

        if by_id:
            fields['uuid'] = by_id
            # should we delete this post?
            yield update_index(idx, is_delete, **fields)

        else:
            # we need the ID from uuid, because this is a new
            # post, as opposed to setting the UUID from the id
            # generated from the "all results" search request.
            by_id = fields['uuid']
            yield write_index(idx, **fields)

        if not is_delete:
            redirect_url += '?post_id=%s' % by_id

        return self.redirect(redirect_url)