Ejemplo n.º 1
0
def get_events_list(user_id, skip=0, count=-1):
    field = ["id", "activity_type", "content_id", "addtime"]
    items = []
    question_submit_count = 0
    answer_count = 0
    if not timeline_client.exists(USER_EVENT_TIME_LINE_PREFIX + str(user_id)):
        events = Event.objects.filter(user_id=user_id)
        for event in events:
            add_to_event_timeline(user_id,
                                  event.eventtype,
                                  event.contentid,
                                  event.addtime,
                                  event.id,
                                  add=True,
                                  update=False,
                                  lpush=False)
    event_id_list = timeline_client.lrange(
        USER_EVENT_TIME_LINE_PREFIX + str(user_id), skip, skip + count)
    for event_info_id in event_id_list:
        #import pdb;pdb.set_trace()
        info = timeline_client.hmget(
            USER_EVENT_PREFIX + "u:" + str(user_id) + event_info_id, field)
        item, question_submit_count, answer_count = get_event(
            int(info[1]), info[2], get_datetime(info[3]),
            question_submit_count, answer_count)
        items.append(item)
    return {
        "event_list": items,
        "statistics": {
            "submit_question": question_submit_count,
            "answer": answer_count
        }
    }
Ejemplo n.º 2
0
def save_event(userid,eventtype,content,contentid,add=True,update=True):
    #import pdb;pdb.set_trace()
    "保存个人动态"
    try:
        event=Event.objects.filter(user_id=userid,eventtype=eventtype,contentid=contentid)
        if add:
            if len(event)>0:
                event=event[0]
                event.save()
                update=True
            else:
                event=Event(user_id=userid,eventtype=eventtype,contentid=contentid)
                event.save()
                update=False
        else:
            if len(event)>0:
                event[0].delete()
                event=event[0]
        #import pdb;pdb.set_trace()
        if event:
            add_to_event_timeline(userid,eventtype,contentid,event.addtime,event.id,add=add,update=update)
        return True
    except Exception,e:
        print e
        raise Exception
        return False
Ejemplo n.º 3
0
def get_events_list(user_id,skip=0,count=-1):
    field=["id","activity_type","content_id","addtime"]
    items=[]
    question_submit_count=0
    answer_count=0
    if not timeline_client.exists(USER_EVENT_TIME_LINE_PREFIX+str(user_id)):
        events=Event.objects.filter(user_id=user_id)
        for event in events:
            add_to_event_timeline(user_id,event.eventtype,event.contentid,event.addtime,event.id,add=True,update=False,lpush=False)
    event_id_list=timeline_client.lrange(USER_EVENT_TIME_LINE_PREFIX+str(user_id),skip,skip+count)
    for event_info_id in event_id_list:
        #import pdb;pdb.set_trace()
        info=timeline_client.hmget(USER_EVENT_PREFIX+"u:"+str(user_id)+event_info_id,field)
        item,question_submit_count,answer_count=get_event(int(info[1]),info[2],get_datetime(info[3]),question_submit_count,answer_count)
        items.append(item)
    return {"event_list":items,"statistics":{"submit_question":question_submit_count,"answer":answer_count}}
Ejemplo n.º 4
0
def save_event(userid, eventtype, content, contentid, add=True, update=True):
    #import pdb;pdb.set_trace()
    "保存个人动态"
    try:
        event = Event.objects.filter(user_id=userid,
                                     eventtype=eventtype,
                                     contentid=contentid)
        if add:
            if len(event) > 0:
                event = event[0]
                event.save()
                update = True
            else:
                event = Event(user_id=userid,
                              eventtype=eventtype,
                              contentid=contentid)
                event.save()
                update = False
        else:
            if len(event) > 0:
                event[0].delete()
                event = event[0]
        #import pdb;pdb.set_trace()
        if event:
            add_to_event_timeline(userid,
                                  eventtype,
                                  contentid,
                                  event.addtime,
                                  event.id,
                                  add=add,
                                  update=update)
        return True
    except Exception, e:
        print e
        raise Exception
        return False