Exemple #1
0
def upload(request):
    
    shuo=request.POST['shuo']
    shuo=urllib2.unquote(shuo)
    shuo=json.loads(shuo)
    
    print(shuo['feed'][1])
    print(shuo['owner'])
    peo=people(qq=int(shuo['owner']))
    peo.save()
    for x in shuo['people']:
        ppeo=people(qq=int(x))
        ppeo.save()

    for x in shuo['feed']:
        try:
            peo=people(qq=int(x['userID']))
            fe=feed(feedID=x['feedID'],info=x['info'],likeNum=int(x['likeNum']),time=int(x['time']),userID=peo,visitTime=int(x['visitTime']),commentNum=int(x['commentNum']))
            fe.save()
        except :
            print("error in save feed")

    for x in shuo['comment']:
        fe=feed(feedID=x['parent'])
        peo_come=people(qq=int(x['from']))
        peo_to=people(qq=int(x['to']))
        comm=comment(IDinFeed=x['IDinFeed'],parent=fe,come=peo_come,to=peo_to,rootID=x['rootID'],time=int(x['time']),info=x['info'])
        comm.save()
Exemple #2
0
def upload(request):
    print('1111111111111')
    shuo=request.POST["shuo"]
    shuo=urllib2.unquote(shuo)
    shuo=json.loads(shuo)
    
    print(shuo['feed'][0])
    print(shuo['owner'])
    people(pk=int(shuo['owner'])).save();
    people(pk=int(shuo['visitor'])).save();

   # people.objects.get_or_create(pk=int(shuo['owner']))
   
    notInpeoples=filter(lambda x : not people.objects.filter(pk=x).exists(),shuo['people'])
    allpeople=map(lambda x: people(pk=x),notInpeoples)
    people.objects.bulk_create(allpeople)

    notInfeeds=filter(lambda x:not feed.objects.filter(pk=x["feedID"]).exists(),shuo['feed'])
    allfeed=map(lambda x:feed(feedID=x["feedID"],info=x['info'],likeNum=int(x['likeNum']),time=int(x['time']),userID_id=int(x["userID"]),visitTime=int(x['visitTime']),commentNum=int(x['commentNum'])),notInfeeds)
    feed.objects.bulk_create(allfeed)

    notIncomments=filter(lambda x : not comment.objects.filter(IDinFeed=x['IDinFeed'],parent_id=x['parent'],come_id=x['from'],to_id=x['to']).exists(),shuo['comment'])
    allcomment=map(lambda x:comment(IDinFeed=x['IDinFeed'],parent_id=x['parent'],come_id=int(x['from']),to_id=int(x['to']),rootID=x['rootID'],time=int(x['time']),info=x['info']),notIncomments)
    comment.objects.bulk_create(allcomment)

    

    #若visitor 为0,则用户未登录,此时是用户默认昵称
    visitor=int(shuo['visitor'])
    map(lambda x:people.objects.get_or_create(qq=x[0]),shuo['nick'].items())
    notInnicks=filter(lambda x : not nick.objects.filter(host__pk=visitor,guest__pk=x[0],nick=x[1]).exists(),shuo['nick'].items())
    Innicks=filter(lambda x : nick.objects.filter(host__pk=visitor,guest__pk=x[0]).exists(),shuo['nick'].items())
    allnick=map(lambda x: nick(host_id=visitor,guest_id=x[0],nick=x[1]),notInnicks)
    map(lambda x:nick.objects.filter(host__pk=visitor,guest__pk=x[0]).update(nick=x[1]),Innicks)
    nick.objects.bulk_create(allnick)

    '''
Exemple #3
0
def upload(request):
    print('1111111111111')
    shuo = request.POST["shuo"]
    shuo = urllib2.unquote(shuo)
    shuo = json.loads(shuo)

    print(shuo['feed'][0])
    print(shuo['owner'])
    people(pk=int(shuo['owner'])).save()
    people(pk=int(shuo['visitor'])).save()
    pattern = re.compile(r'(\d+)+')
    now = timezone.now()

    def protime(x):
        if x == "NULL":
            return None
        al = map(lambda y: int(y), re.findall(pattern, x))
        return now.replace(al[0], al[1], al[2], al[3], al[4], 0)

# people.objects.get_or_create(pk=int(shuo['owner']))

    notInpeoples = filter(lambda x: not people.objects.filter(pk=x).exists(),
                          shuo['people'])
    allpeople = map(lambda x: people(pk=x), notInpeoples)
    people.objects.bulk_create(allpeople)

    notInfeeds = filter(
        lambda x: not feed.objects.filter(pk=x["feedID"]).exists(),
        shuo['feed'])
    allfeed = map(
        lambda x: feed(feedID=x["feedID"],
                       info=x['info'],
                       likeNum=int(x['likeNum']),
                       time=protime(x['time']),
                       userID_id=int(x["userID"]),
                       visitTime=protime(x['visitTime']),
                       commentNum=int(x['commentNum'])), notInfeeds)
    feed.objects.bulk_create(allfeed)

    notIncomments = filter(
        lambda x: not comment.objects.filter(IDinFeed=x['IDinFeed'],
                                             parent_id=x['parent'],
                                             come_id=x['from'],
                                             to_id=x['to']).exists(),
        shuo['comment'])
    allcomment = map(
        lambda x: comment(IDinFeed=x['IDinFeed'],
                          parent_id=x['parent'],
                          come_id=int(x['from']),
                          to_id=int(x['to']),
                          rootID=x['rootID'],
                          time=protime(x['time']),
                          info=x['info']), notIncomments)
    comment.objects.bulk_create(allcomment)

    #若visitor 为0,则用户未登录,此时是用户默认昵称
    visitor = int(shuo['visitor'])
    map(lambda x: people.objects.get_or_create(qq=x[0]), shuo['nick'].items())
    notInnicks = filter(
        lambda x: not nick.objects.filter(
            host__pk=visitor, guest__pk=x[0], nick=x[1]).exists(),
        shuo['nick'].items())
    Innicks = filter(
        lambda x: nick.objects.filter(host__pk=visitor, guest__pk=x[0]).exists(
        ), shuo['nick'].items())
    allnick = map(lambda x: nick(host_id=visitor, guest_id=x[0], nick=x[1]),
                  notInnicks)
    map(
        lambda x: nick.objects.filter(host__pk=visitor, guest__pk=x[0]).update(
            nick=x[1]), Innicks)
    nick.objects.bulk_create(allnick)
    '''
    try:
        host=people.objects.get(qq=owner)
        guest=people.objects.get(qq=int(x))
        ni=nick(host=host,guest=guest,nick=y)
        ni.save()
    except:
        pass
    '''

    return HttpResponse('OKKKKK')