Beispiel #1
0
def checkIfConfirmationCodeMatches(**params):
    print "check if confirmation code matches starts"
    if 'email' in params and 'code' in params:
        try:
            email = params['email']
            print "email: " + email
            code = params['code']
            print "code: " + code
            ConfirmationCode = Object.extend('ConfirmationCode')
            twentyMinutesAgo = datetime.datetime.now() - datetime.timedelta(
                minutes=20)
            print(twentyMinutesAgo)
            query1 = ConfirmationCode.query
            query2 = ConfirmationCode.query
            query3 = ConfirmationCode.query
            query1.equal_to('email', email)
            query2.equal_to('code', code)
            query3.greater_than_or_equal_to('updatedAt', twentyMinutesAgo)
            query12 = Query.and_(query1, query2)
            query = Query.and_(query12, query3)
            query_list = query.find()
            print "check if confirmation code matches ends"

            if len(query_list) == 0:
                return False
            else:
                return True
        except Exception as e:
            print e
            print "check if confirmation code matches ends"
            raise LeanEngineError('系统错误:无法验证验证码')
    else:
        print "email and code cannot be empty"
        print "check if confirmation code matches ends"
        raise LeanEngineError('邮箱以及验证码都不能为空')
Beispiel #2
0
def after_event_save(event):
    print("after event save started")
    institution = event.get('institution')
    print "institution:" + institution
    Conversation = Object.extend('_Conversation')
    query1 = Conversation.query
    query2 = Conversation.query
    query1.equal_to('name', institution)
    query2.equal_to('sys', True)
    query = Query.and_(query1, query2)
    query_list = query.find()
    if len(query_list) == 0:
        raise LeanEngineError('没有找到系统对话')
    else:
        conversation = query_list[0]
        conversation_id = conversation.get('objectId')
        print "conversationId:" + conversation_id
        eventId = event.get('objectId')
        headers = {'Content-Type': 'application/json', \
            'X-LC-Id': APP_ID, \
            'X-LC-Key': MASTER_KEY + ',master'}
        data = {"from_peer": "sys", \
                "message": "{\"_lctype\":-1,\"_lctext\":\"eventCreated\", \
                \"_lcattrs\":{\"snType\":"                                           + str(snEventCreated) + \
                ",\"eventId\": \"" + eventId + "\"}}", \
                 "conv_id": conversation_id}
        requests.post(subscriber_url, data=json.dumps(data), headers=headers)
    print("after event save ended")
def test_or_and_query():
    q1 = Query(GameScore).greater_than('score', 5)
    q2 = Query(GameScore).less_than('score', 10)

    q = Query.and_(q1, q2)
    assert q.dump() == {'where': {'$and': [{'score': {'$gt': 5}}, {'score': {'$lt': 10}}]}}

    q = Query.or_(q1, q2)
    assert q.dump() == {'where': {'$or': [{'score': {'$gt': 5}}, {'score': {'$lt': 10}}]}}
Beispiel #4
0
def test_or_and_query(): # type: () -> None
    q1 = Query(GameScore).greater_than('score', 5)
    q2 = Query(GameScore).less_than('score', 10)
    q3 = Query(GameScore).equal_to('playerName', 'foobar')

    q = Query.and_(q1, q2, q3)
    assert q.dump() == {'where': {'$and': [{'score': {'$gt': 5}}, {'score': {'$lt': 10}}, {'playerName': 'foobar'}]}}

    q = Query.or_(q1, q2, q3)
    assert q.dump() == {'where': {'$or': [{'score': {'$gt': 5}}, {'score': {'$lt': 10}}, {'playerName': 'foobar'}]}}
Beispiel #5
0
def test_or_and_query():
    q1 = Query(GameScore).greater_than("score", 5)
    q2 = Query(GameScore).less_than("score", 10)
    q3 = Query(GameScore).equal_to("playerName", "foobar")

    q = Query.and_(q1, q2, q3)
    assert q.dump() == {"where": {"$and": [{"score": {"$gt": 5}}, {"score": {"$lt": 10}}, {"playerName": "foobar"}]}}

    q = Query.or_(q1, q2, q3)
    assert q.dump() == {"where": {"$or": [{"score": {"$gt": 5}}, {"score": {"$lt": 10}}, {"playerName": "foobar"}]}}
Beispiel #6
0
def test_or_and_query(): # type: () -> None
    q1 = Query(GameScore).greater_than('score', 5)
    q2 = Query(GameScore).less_than('score', 10)
    q3 = Query(GameScore).equal_to('playerName', 'foobar')

    q = Query.and_(q1, q2, q3)
    assert q.dump() == {'where': {'$and': [{'score': {'$gt': 5}}, {'score': {'$lt': 10}}, {'playerName': 'foobar'}]}}

    q = Query.or_(q1, q2, q3)
    assert q.dump() == {'where': {'$or': [{'score': {'$gt': 5}}, {'score': {'$lt': 10}}, {'playerName': 'foobar'}]}}
Beispiel #7
0
def after_event_update(event):
    print("after event update called...")
    institution = event.get('institution')
    print "institution:" + institution
    Conversation = Object.extend('_Conversation')
    query1 = Conversation.query
    query2 = Conversation.query
    query1.equal_to('name', institution)
    query2.equal_to('sys', True)
    query = Query.and_(query1, query2)
    query_list = query.find()
    if len(query_list) == 0:
        raise LeanEngineError('没有找到系统对话')
    else:
        conversation = query_list[0]
        conversation_id = conversation.get('objectId')
        print "conversationId:" + conversation_id
        eventId = event.get('objectId')
        headers = {'Content-Type': 'application/json', \
            'X-LC-Id': APP_ID, \
            'X-LC-Key': MASTER_KEY + ',master'}
        data = {"from_peer": "sys", \
                "message": "{\"_lctype\":-1,\"_lctext\":\"eventUpdated\", \
                \"_lcattrs\":{\"snType\":"                                           + str(snEventUpdated) + \
                ",\"eventId\": \"" + eventId + "\"}}", \
                 "conv_id": conversation_id}
        requests.post(subscriber_url, data=json.dumps(data), headers=headers)

        # if event is finalized, send finalized message
        remain_people = event.get('remainingSeats')
        if remain_people <= 0:
            conversationPointer = event.get('conversation')
            conversation_id = conversationPointer.get('objectId')
            conversation = Query('_Conversation').get(conversation_id)
            if conversation.has(key_of_finalized_message) == False:
                finalizedMessage = "微活动约定成功!系统已经将对话设为私有。"
                finalizedMessage += "这条信息以下只有队员才可以发言!【日常小管家】"
                headers = {'Content-Type': 'application/json', \
                    'X-LC-Id': APP_ID, \
                    'X-LC-Key': MASTER_KEY + ',master'}
                data = {"from_peer": admin, \
                        "message": "{\"_lctype\":-1,\"_lctext\": \"" + finalizedMessage + "\", \
                        \"_lcattrs\":{\"reason\": \"finalized\"}}"                                                                  , \
                         "conv_id": conversation_id, "transient": False}
                requests.post(messages_url,
                              data=json.dumps(data),
                              headers=headers)
                conversation.set(key_of_finalized_message, True)
                conversation.save()
def test_or_and_query():  # type: () -> None
    q1 = Query(GameScore).greater_than("score", 5)
    q2 = Query(GameScore).less_than("score", 10)
    q3 = Query(GameScore).equal_to("playerName", "foobar")

    q = Query.and_(q1, q2, q3)
    assert q.dump() == {
        "where": {
            "$and": [
                {
                    "score": {
                        "$gt": 5
                    }
                },
                {
                    "score": {
                        "$lt": 10
                    }
                },
                {
                    "playerName": "foobar"
                },
            ]
        }
    }

    q = Query.or_(q1, q2, q3)
    assert q.dump() == {
        "where": {
            "$or": [
                {
                    "score": {
                        "$gt": 5
                    }
                },
                {
                    "score": {
                        "$lt": 10
                    }
                },
                {
                    "playerName": "foobar"
                },
            ]
        }
    }
Beispiel #9
0
def monitorEventStatus():
    print 'monitor event status starts'
    Event = Object.extend('Event')
    query1 = Event.query
    query2 = Event.query
    now_stamp = time.time()
    last_minute_stamp = now_stamp - 60
    query1.greater_than_or_equal_to('due', last_minute_stamp)
    query2.less_than('due', now_stamp)
    query = Query.and_(query1, query2)
    query.include('conversation')
    query_list = query.find()
    for event in query_list:
        conversation = event.get('conversation')
        if conversation.has(key_of_finalized_message) == False:
            max_people = event.get('maximumAttendingPeople')
            min_people = event.get('minimumAttendingPeople')
            remain_people = event.get('remainingSeats')
            due_stamp = event.get('due')
            # test if event is finalized
            if (due_stamp > now_stamp and remain_people <= 0) or (
                    due_stamp <= now_stamp
                    and max_people - remain_people >= min_people):
                conversation_id = conversation.get('objectId')
                finalizedMessage = "微活动约定成功!系统已经设定此对话为私有对话。"
                finalizedMessage += "这条信息以下只有队员才可以发言!【日常小管家】"
                headers = {'Content-Type': 'application/json', \
                    'X-LC-Id': APP_ID, \
                    'X-LC-Key': MASTER_KEY + ',master'}
                data = {"from_peer": admin, \
                        "message": "{\"_lctype\":-1,\"_lctext\": \"" + finalizedMessage + "\", \
                        \"_lcattrs\":{\"reason\": \"finalized\"}}"                                                                  , \
                         "conv_id": conversation_id, "transient": False}
                requests.post(messages_url,
                              data=json.dumps(data),
                              headers=headers)
                conversation.set(key_of_finalized_message, True)
                conversation.save()
    print 'monitor event status ends'
Beispiel #10
0
def subscribeToSystemConversation(**params):
    print "subscribe to system conversation starts"
    if 'clientId' in params and 'institution' in params:
        try:
            client_id = params['clientId']
            print "clientId:" + client_id
            institution = params['institution']
            print "institution:" + institution
            Conversation = Object.extend('_Conversation')
            query1 = Conversation.query
            query2 = Conversation.query
            query1.equal_to('name', institution)
            query2.equal_to('sys', True)
            query = Query.and_(query1, query2)
            query_list = query.find()
            if len(query_list) == 0:
                raise LeanEngineError('没有找到系统对话')
            else:
                conversation = query_list[0]
                conversation_id = conversation.get('objectId')
                print "conversationId:" + conversation_id

                headers = {'Content-Type': 'application/json', \
                    'X-LC-Id': APP_ID, \
                    'X-LC-Key': MASTER_KEY + ',master'}
                data = {"conv_id": conversation_id, "client_id": client_id}
                requests.post(subscription_url,
                              data=json.dumps(data),
                              headers=headers)
            print "subscribe to system conversation ends"
            return True
        except Exception as e:
            print e
            print "subscribe to system conversation ends"
            raise LeanEngineError('订阅系统通知失败,请稍后重试')
    else:
        print "client id and institution must not be empty"
        print "subscribe to system conversation ends"
        raise LeanEngineError('client id and institution must be not empty')
Beispiel #11
0
def createSystemConversationIfNotExists(**params):
    print "create system conversation if not exists starts"
    if 'email' in params:
        try:
            email = params['email']
            print "email:" + email
            suffix = email[email.find('@') + 1:]
            print "suffix:" + suffix
            institution = suffix[:suffix.find('.')]
            print "institution:" + institution
            Conversation = Object.extend('_Conversation')
            query1 = Conversation.query
            query2 = Conversation.query
            query1.equal_to('name', institution)
            query2.equal_to('sys', True)
            query = Query.and_(query1, query2)
            query_list = query.find()
            if len(query_list) == 0:
                headers = {'Content-Type': 'application/json', \
                    'X-LC-Id': APP_ID, \
                    'X-LC-Key': APP_KEY}
                data = {"name": institution, \
                        "sys": True}
                requests.post(conversation_url,
                              data=json.dumps(data),
                              headers=headers)
            print "create system conversation if not exists ends"
            return True
        except Exception as e:
            print e
            print "create system conversation if not exists ends"
            raise LeanEngineError('创建系统对话失败,请稍后重试')
    else:
        print "email cannot be empty"
        print "create system conversation if not exists ends"
        raise LeanEngineError('邮箱不能为空')
Beispiel #12
0
def test_and_(): # type: () -> None
    q1 = Query(GameScore).greater_than('score', 2)
    q2 = Query(GameScore).greater_than('score', 3)
    result = Query.and_(q1, q2).ascending('score').find()
    eq_([i.get('score') for i in result], list(range(4, 10)))
Beispiel #13
0
def test_and_():
    q1 = Query(GameScore).greater_than('score', 2)
    q2 = Query(GameScore).greater_than('score', 3)
    result = Query.and_(q1, q2).ascending('score').find()
    eq_([i.get('score') for i in result], list(range(4, 10)))
Beispiel #14
0
def test_and_():
    q1 = Query(GameScore).greater_than("score", 2)
    q2 = Query(GameScore).greater_than("score", 3)
    result = Query.and_(q1, q2).ascending("score").find()
    eq_([i.get("score") for i in result], range(4, 10))
def test_and_():  # type: () -> None
    q1 = Query(GameScore).greater_than("score", 2)
    q2 = Query(GameScore).greater_than("score", 3)
    result = Query.and_(q1, q2).ascending("score").find()
    eq_([i.get("score") for i in result], list(range(4, 10)))