Example #1
0
def decode(key, value):
    if isinstance(value, get_dumpable_types()):
        return value

    if isinstance(value, (tuple, list)):
        return [decode(key, x) for x in value]

    if not isinstance(value, dict):
        return value

    if '__type' not in value:
        return dict([(k, decode(k, v)) for k, v in iteritems(value)])

    _type = value['__type']

    if _type == 'Pointer':
        value = copy.deepcopy(value)
        class_name = value['className']
        pointer = leancloud.Object.create(class_name)
        if 'createdAt' in value:
            value.pop('__type')
            value.pop('className')
            pointer._update_data(value)
        else:
            pointer._update_data({'objectId': value['objectId']})
        return pointer

    if _type == 'Object':
        value = copy.deepcopy(value)
        class_name = value['className']
        value.pop('__type')
        value.pop('className')
        obj = leancloud.Object.create(class_name)
        obj._update_data(value)
        return obj

    if _type == 'Date':
        return arrow.get(iso8601.parse_date(value['iso'])).to('local').datetime

    if _type == 'GeoPoint':
        return leancloud.GeoPoint(latitude=value['latitude'], longitude=value['longitude'])

    if key == 'ACL':
        if isinstance(value, leancloud.ACL):
            return value
        return leancloud.ACL(value)

    if _type == 'Relation':
        relation = leancloud.Relation(None, key)
        relation.target_class_name = value['className']
        return relation

    if _type == 'File':
        f = leancloud.File(value['name'])
        meta_data = value.get('metaData')
        if meta_data:
            f._metadata = meta_data
        f._url = value['url']
        f.id = value['objectId']
        return f
Example #2
0
def test_init():  # type: () -> None
    acl = leancloud.ACL()
    role = leancloud.Role("xxx", acl)
    assert role
    assert role.get_name() == "xxx"
    assert role.get_acl() == acl
    assert role.users
    assert role.roles
Example #3
0
 def __init__(self, name=None, acl=None):
     super(Role, self).__init__()
     if name:
         self.set_name(name)
     if acl is None:
         acl = leancloud.ACL()
         acl.set_public_read_access(True)
     self.set_acl(acl)
Example #4
0
def find_conversation():
  conversation = leancloud.Conversation.query.get('5beb903860d9007f7ba8423f')
  print(conversation.members)
  acl = leancloud.ACL()
  acl.set_public_read_access(True)
  print(acl.dump())
  conversation.set_acl(acl)
  conversation.save()
def test_query_acl():  # type: () -> None
    TestACLObject = leancloud.Object.extend("TestACLObject")
    o = TestACLObject(content="xxx")
    acl = leancloud.ACL()
    acl.set_public_read_access(True)
    acl.set_public_write_access(True)
    acl.set_write_access("xxxxx", True)
    o.set_acl(acl)
    o.save()
    acl_data = o.get_acl().dump()
    o = TestACLObject.query.include_acl().equal_to("objectId", o.id).first()
    assert_equal(acl_data, o.get_acl().dump())
    o.destroy()
Example #6
0
def mark_comment(obj_id, mark_spam=False, hide=True):
    try:
        c = query.get(obj_id)
        if mark_spam:
            c.set('isSpam', True)
        else:
            c.set('isSpam', False)
        acl = lc.ACL()
        acl.set_public_read_access(not hide)
        c.set_acl(acl)
        c.save()
        return True, '成功!'
    except Exception as e:
        return False, str(e)
Example #7
0
def send_emails(lst):
    if len(lst) == 0:
        return
    prepare_smtp_server()
    for c in lst:
        if akismet_enabled:
            logging('正在通过 akismet 验证垃圾评论: %s' %
                    c.get('comment')[:-1])  # 最后一个字符是 \n
            if akismet.check(config['site_url'], c.get('ip'),
                             c.get('ua'), config['site_url'] + c.get('url'),
                             c.get('comment'), c.get('nick'), c.get('mail'),
                             c.get('link')):
                logging('检测到垃圾评论,跳过发送邮件')
                acl = lc.ACL()
                acl.set_public_read_access(False)
                c.set_acl(acl)
                c.set('isSpam', True)
                c.save()
                continue
        if c.get('pid') == None:
            # notify the blogger
            func = send_admin_email
            logging('正在通知博主: objectId = %s' % c.id)
        else:
            # notify the author of the comment be replied
            func = send_replay_email
            logging('正在通知被回复者: objectId = %s' % c.id)
        if func(c):
            logging('邮件发送成功!')
            c.set('isNotified', True)
            c.save()
        else:
            logging('邮件发送失败!', level='error', prnt=True)
            exit(1)
    logging('登出 SMTP 服务器...', prnt=True)
    server.quit()
Example #8
0
def test_get_set_acl():  # type: () -> None
    acl = leancloud.ACL()
    album = Album()
    album.set_acl(acl)
    assert album.get_acl() == acl
from xiaobandeng.config import load_config
from xiaobandeng.lean_cloud import init
from xiaobandeng.config import CONFIG
import leancloud

env = 'product'
load_config(env)
init(CONFIG)

CLASS_NAME = 'EditorTask'

lean_cloud_class = leancloud.Object.extend(CLASS_NAME)

query = lean_cloud_class.query
query.add_ascending("createdAt")
query.limit(1000)

obj_list = query.find()
print 'total:', len(obj_list)

# obj = obj_list[0]

for obj in obj_list:
    acl = leancloud.ACL()
    acl.set_public_read_access(True)
    acl.set_public_write_access(True)

    obj.set_acl(acl)
    obj.save()
    print obj.id
Example #10
0
def test_init():
    acl = leancloud.ACL()
    role = leancloud.Role('xxx', acl)
    assert role
    assert role.get_name() == 'xxx'
    assert role.get_acl() == acl
Example #11
0
def decode(key, value):
    if isinstance(value, get_dumpable_types()):
        return value

    if isinstance(value, (tuple, list)):
        return [decode(key, x) for x in value]

    if not isinstance(value, dict):
        return value

    if key == "ACL":
        if isinstance(value, leancloud.ACL):
            return value
        return leancloud.ACL(value)

    if "__type" not in value:
        return dict([(k, decode(k, v)) for k, v in six.iteritems(value)])

    _type = value["__type"]

    if _type == "Pointer":
        value = copy.deepcopy(value)
        class_name = value["className"]
        pointer = leancloud.Object.create(class_name)
        if "createdAt" in value:
            value.pop("__type")
            value.pop("className")
            pointer._update_data(value)
        else:
            pointer._update_data({"objectId": value["objectId"]})
        return pointer

    if _type == "Object":
        value = copy.deepcopy(value)
        class_name = value["className"]
        value.pop("__type")
        value.pop("className")
        obj = leancloud.Object.create(class_name)
        obj._update_data(value)
        return obj

    if _type == "Date":
        return arrow.get(iso8601.parse_date(value["iso"])).to("local").datetime

    if _type == "GeoPoint":
        return leancloud.GeoPoint(
            latitude=value["latitude"], longitude=value["longitude"]
        )

    if _type == "Relation":
        relation = leancloud.Relation(None, key)
        relation.target_class_name = value["className"]
        return relation

    if _type == "File":
        f = leancloud.File(value["name"])
        meta_data = value.get("metaData")
        if meta_data:
            f._metadata = meta_data
        f._url = value["url"]
        f.id = value["objectId"]
        return f
Example #12
0
def test_get_set_acl():
    acl = leancloud.ACL()
    album = Album()
    album.set_acl(acl)
    assert album.get_acl() == acl