Exemple #1
0
def update(post, user, title=None, content=None, tags=None, active=None):
    from decanter.api.interface import tag as TagInterface

    if not post.author == user:
        # This should really be a group perms check.
        raise UnauthorizedObjectAccessError()

    post.title = title if (title is not None) else post.title

    if tags is not None:
        for tag in tags:
            if tag not in post.tags:
                TagInterface.add(post, tag)

    if content is not None:
        app.content.version_copy(post.slug, post.format,
                                 post.domain, 'draft', 'backup')
        app.content.save(post.slug, 'draft',
                         post.format, content, post.domain)
        post.pending_update = True

    fields = (title, tags, active, content)
    changed = any([f is not None for f in fields])
    if changed:
        db.session.add(post)
        db.session.commit()
    return post
Exemple #2
0
def create(user, slug, title, content, format, subtitle=None, domain=None, tags=None):
    from decanter.api.interface import tag as TagInterface
    if domain is None:
        domain = app.config.get('DEFAULT_CONTENT_DOMAIN')

    version = 'draft'
    app.content.save(slug, version, format, content, domain)

    p = Post()
    p.author_id = user.id
    p.title = title
    p.slug = slug
    p.format = format
    p.version = version
    p.domain = domain
    p.location = app.content.url(slug, 'published', format, domain)
    p.draft = app.content.url(slug, version, format, domain)

    if subtitle is not None:
        p.subtitle = subtitle

    db.session.add(p)

    if tags is not None:
        for tag in tags:
            TagInterface.add(p, tag)

    db.session.commit()

    return p