コード例 #1
0
ファイル: views.py プロジェクト: youtaya/mothertree
def process_client_share(records_buffer, username, target_handle):

    jrecord = json.loads(records_buffer)
    logger.debug("jsons list: "+ str(jrecord))

    record = Dialog(handle=target_handle)

    record.content = safe_attr(jrecord, 'content')
    logger.debug('record username: '******'sender')
    record.link = safe_attr(jrecord, 'link')
    record.create_date = get_date(safe_attr(jrecord, 'date'))
    record.create_time = safe_attr(jrecord, 'time')
    record.content_type = safe_attr(jrecord, 'ctx')
    record.photo = safe_attr(jrecord, 'po')
    record.audio = safe_attr(jrecord, 'ao')
    record.deleted = (safe_attr(jrecord, 'del') == 1)

    record.save()
    logger.debug('Saved record: '+record.handle)
    push_data = {}
    push_data['sender'] = username
    push_data['linker'] = target_handle
    push_data['id'] = record.id
    jpush_send_message(push_data, target_handle, 1001)
コード例 #2
0
ファイル: views.py プロジェクト: youtaya/mothertree
def process_client_anonymous_share(records_buffer, username):

    jrecord = json.loads(records_buffer)
    logger.debug("jsons list: "+ str(jrecord))
    #select random target handle : not user or user's friends
    totalIds = User.objects.all().count() - 1
    if totalIds <= 1:
        return

    randomId = randint(0, totalIds)
    others = User.objects.get(id=randomId)
    if others.username == username or others.username == 'root':
        randomId = randint(0, totalIds)
        others = User.objects.get(id=randomId)
    target_handle = others.username
    logger.debug('target handle: ' + target_handle)

    record = Dialog(handle=target_handle)

    record.content = safe_attr(jrecord, 'content')
    logger.debug('record context: ' + record.content)
    logger.debug('record username: '******'sender')
    record.link = others.username
    record.create_date = get_date(safe_attr(jrecord, 'date'))
    record.create_time = safe_attr(jrecord, 'time')
    record.content_type = safe_attr(jrecord, 'ctx')
    record.photo = safe_attr(jrecord, 'po')
    record.audio = safe_attr(jrecord, 'ao')
    record.deleted = (safe_attr(jrecord, 'del') == 1)

    record.save()
    logger.debug('Saved record: '+record.handle)
    push_data = {}
    push_data['username'] = username
    push_date['id'] = record.id
    jpush_send_message(toJSON(push_data), target_handle, 1001)