Beispiel #1
0
    def _do_edit_form_text(self, media_id):
        c.story = h.get_media_by_id(media_id)
        for key in request.POST.keys():
            if key.startswith('mceSimple'):
                body = request.POST.get(key, u'')
                break
        if not body:
            abort(400)

        cleaned = h.clean_html(body)

        c.story.text = cleaned
        meta.Session.commit()

        c.editable = True
        return dict(html=render('/media/story/item.mako'))
Beispiel #2
0
    def _do_new_form_text(self, almanac_slug, page_slug=None):
        c.almanac = h.get_almanac_by_slug(almanac_slug)
        page = self._retrieve_page(c.almanac, page_slug)
        for key in request.POST.keys():
            if key.startswith('mceSimple'):
                body = request.POST.get(key, u'')
                break
        if not body:
            abort(400)

        cleaned = h.clean_html(body)
        # Hack in akismet validation, although we don't have a FormEncode
        # form here.
        from communityalmanac.lib.validators import AkismetValidator
        akismet = AkismetValidator()
        from formencode.validators import Invalid
        user = self.ensure_user
        assert hasattr(user, 'username')
        field_dict = {'fullname': user.username,
                      'website': u'',
                      'email': user.email_address or u'',
                      'text': cleaned}
        try:
            akismet.validate_python(field_dict, state={})
            log.info("akismet says story is OK")
        except Invalid:
            # Not sure what else we can do here.
            abort(400)

        c.story = story = Story()
        story.text = cleaned
        story.page_id = page.id
        story.order = len(page.media)
        meta.Session.add(story)
        meta.Session.commit()

        c.editable = True
        return dict(html=render('/media/story/item.mako'))