Example #1
0
def parse_article_post(request):
    missing = []
    collected = {}
    title = get_post_field(request.POST, "title", missing, collected)
    content = get_post_field(request.POST, "content", missing, collected)

    if missing:
        error_message = MISSING_FIELDS_ERROR % ", ".join(missing)
        return ParsePostResult(None, error_message, collected)

    art = Article(title=title, content=content, rendered=html_from(content), author=request.user)
    return ParsePostResult(art)
def parse_comment_post(art, post_data):
    missing = []
    collected = {}
    name = get_post_field(post_data, 'name', missing, collected)
    email = get_post_field(post_data, 'email', missing, collected)
    content = get_post_field(post_data, 'content', missing, collected)
    title = get_post_field(post_data, 'title', missing, collected, False)

    if missing:
        error_message = MISSING_FIELDS_ERROR % ', '.join(missing)
        return ParsePostResult(None, error_message, collected)

    art_comment = ArticleComment(
        article=art,
        user_name=name,
        user_email=email,
        content=content,
        rendered=html_from(content),
        title=title
    )
    return ParsePostResult(art_comment)