def init_Post_obj(json_obj):
    """Init Post() object."""
    post_obj = Post()

    post_acl = ACL()
    post_acl.set_public_write_access(False)
    post_acl.set_public_read_access(True)
    post_obj.set_acl(post_acl)

    post_obj.kind = 10
    post_obj.title = json_obj.get('title')
    post_obj.author = json_obj.get('author')
    post_obj.ID = long(json_obj.get('id'))    # use number not string

    brief_text = json_obj.get('brief')
    if brief_text is None:
        post_obj.brief = u''

    else:
        post_obj.brief = HTMLParser.HTMLParser().unescape(brief_text)

    print post_obj.author
    post_obj.createdAt = from_stamp_to_createdAt(json_obj.get('time'))
    print from_stamp_to_createdAt(json_obj.get('time'))
    #post_obj.html = get_remove_ad(json_obj.get('content'))  # remove advertisement
    post_obj.html = get_tag_and_removed_tag(json_obj.get('content'))  # remove advertisement
    return post_obj
def test_encode():  # type: () -> None
    Foo = Object.extend("Foo")
    obj = Foo()
    assert utils.encode(obj) == {
        "className": "Foo",
        "__type": "Pointer",
        "objectId": None,
    }

    acl = ACL()
    assert utils.encode(acl) == {}
    acl.set_read_access("xxx", True)
    assert utils.encode(acl) == {"xxx": {"read": True}}

    point = GeoPoint()
    assert utils.encode(point) == {
        "__type": "GeoPoint",
        "longitude": 0,
        "latitude": 0,
    }

    assert utils.encode([obj, acl, point]) == [
        {"className": "Foo", "__type": "Pointer", "objectId": None},
        {"xxx": {"read": True}},
        {"__type": "GeoPoint", "longitude": 0, "latitude": 0},
    ]

    assert utils.encode({"a": obj, "b": acl}) == {
        "a": {"className": "Foo", "__type": "Pointer", "objectId": None},
        "b": {"xxx": {"read": True}},
    }
Beispiel #3
0
def test_encode():
    Foo = Object.extend('Foo')
    obj = Foo()
    assert utils.encode(obj) == {
        'className': 'Foo',
        '__type': 'Pointer',
        'objectId': None,
    }

    acl = ACL()
    assert utils.encode(acl) == {}
    acl.set_read_access('xxx', True)
    assert utils.encode(acl) == {'xxx': {'read': True}}

    point = GeoPoint()
    assert utils.encode(point) == {
        '__type': 'GeoPoint',
        'longitude': 0,
        'latitude': 0,
    }

    assert utils.encode([obj, acl, point]) == [
        {
            'className': 'Foo',
            '__type': 'Pointer',
            'objectId': None,
        }, {
            'xxx': {'read': True}
        }, {
            '__type': 'GeoPoint',
            'longitude': 0,
            'latitude': 0,
        }
    ]

    assert utils.encode({'a': obj, 'b': acl}) == {
        'a': {
            'className': 'Foo',
            '__type': 'Pointer',
            'objectId': None,
        },
        'b': {
            'xxx': {'read': True}
        },
    }
Beispiel #4
0
def before_todo_save(todo):
    content = todo.get('content')
    if not content:
        raise LeanEngineError('内容不能为空')
    if len(content) >= 240:
        todo.set('content', content[:240] + ' ...')
    author = todo.get('author')
    if author:
        acl = ACL()
        acl.set_public_read_access(True)
        acl.set_read_access(author.id, True)
        acl.set_write_access(author.id, True)
        todo.set_acl(acl)
Beispiel #5
0
def init_Post_obj(json_obj):
    """Init Post() object."""
    post_obj = Post()

    post_acl = ACL()
    post_acl.set_public_write_access(False)
    post_acl.set_public_read_access(True)
    post_obj.set_acl(post_acl)

    post_obj.kind = 10
    post_obj.title = json_obj.get('title')
    post_obj.author = json_obj.get('author')
    post_obj.ID = long(json_obj.get('id'))    # use number not string

    brief_text = json_obj.get('brief')
    if brief_text is None:
        post_obj.brief = u''

    else:
        post_obj.brief = HTMLParser.HTMLParser().unescape(brief_text)

    print post_obj.author
    post_obj.createdAt = from_stamp_to_createdAt(json_obj.get('time'))
    print from_stamp_to_createdAt(json_obj.get('time'))
    #post_obj.html = get_remove_ad(json_obj.get('content'))  # remove advertisement
    post_obj.html = get_tag_and_removed_tag(json_obj.get('content'))  # remove advertisement
    return post_obj
Beispiel #6
0
def new_post():
    author = User.get_current()
    title, content = request.form['title'], request.form['content']
    tag_names = parse_tag_names(request.form['tags'])

    f = request.files['featuredImage']
    if f.filename == '':
        featuredImage = None
    else:
        featuredImage = Attachment(f.filename, data=f.stream)
    if featuredImage and not allowed_file(featuredImage.extension):
        flash('warning', 'Upload a proper image.')
        return redirect(url_for('post_form'))

    post = Post()
    post.title = title
    post.content = content
    post.markedContent = markdown(content)
    post.author = author
    if featuredImage:
        post.featuredImage = featuredImage

    acl = ACL()
    acl.set_public_read_access(True)
    acl.set_write_access(author.id, True)
    post.set_acl(acl)

    post.save()

    tags = []
    for name in tag_names:
        tag = Tag.get_by_name(name)
        if not tag:
            tag = Tag()
            tag.name = name
        tags.append(tag)
    for tag in tags:
        m = TagPostMap()
        m.set({'tag': tag, 'post': post})
        m.save()
        tag.increment('post_count')
    Tag.save_all(tags)

    return redirect(url_for('show_post', post_id=post.id))
Beispiel #7
0
def test_acl():
    acl = ACL()
    f = File('blah', buffer('xxx'))
    f.set_acl(acl)
    assert f.get_acl() == acl
Beispiel #8
0
def test_acl():  # type: () -> None
    acl_ = ACL()
    f = File('Blah', io.BytesIO(b'xxx'))
    assert_raises(TypeError, f.set_acl, 'a')
    f.set_acl(acl_)
    assert f.get_acl() == acl_
Beispiel #9
0
def test_acl():  # type: () -> None
    acl_ = ACL()
    f = File("Blah", io.BytesIO(b"xxx"))
    assert_raises(TypeError, f.set_acl, "a")
    f.set_acl(acl_)
    assert f.get_acl() == acl_
Beispiel #10
0
def test_acl():
    acl = ACL()
    f = File('Blah', buffer_type(b'xxx'))
    assert_raises(TypeError, f.set_acl, 'a')
    f.set_acl(acl)
    assert f.get_acl() == acl