Exemplo n.º 1
0
 def get_my_activities(self, db, user, startindex):
     my_activities = []
     activities_list = self.client.lrange("my:%s"%user, startindex, startindex+feed_number-1)
     index = startindex + 1
     for activity in activities_list:
         acttype, act_userid, actto = activity.split(":")
         act_username,act_domain,act_uuid = get_namedomainuuid_by_id(db, self.client, act_userid)
         if acttype == 'status':
             real_activity = self.client.hmget(activity, ["time",'status','comm'])
             real_activity.append(actto)
         if acttype == 'note':
             real_activity = self.client.hmget(activity, ["time","title","content","status",'comm'])
             real_activity.append(actto)
         elif acttype == 'link':
             real_activity = self.client.hmget(activity, ["time","url","title","summary",'status','comm'])
             real_activity.append(actto)
         elif acttype == 'doc':
             real_activity = self.client.hmget(activity, ["time","docid","title","summary",'status','comm'])
             real_activity.append(actto)
         if acttype == 'follow':
             actto_username,actto_domain,actto_uuid = get_namedomainuuid_by_id(db, self.client, actto)
             real_activity = self.client.hmget(activity, ["time",])
             real_activity.append(actto)
             real_activity.append(actto_username)
             real_activity.append(actto_domain)
             real_activity.append(actto_uuid)
         real_activity.append(act_userid)
         real_activity.append(act_username)
         real_activity.append(act_domain)
         real_activity.append(act_uuid)
         real_activity.append(acttype)
         real_activity.append(index)
         index = index + 1
         my_activities.append(real_activity)
     return my_activities
Exemplo n.º 2
0
 def get_all_activities(self, db, startindex, ispoll):
     all_activities = []
     startindex = 0 if ispoll else startindex
     lastindex = ispoll - 1 if ispoll else startindex + feed_number - 1
     activities_list = self.client.lrange("all", startindex, lastindex)
     index = startindex + 1
     for activity in activities_list:
         acttype, act_userid, actto = activity.split(":")
         act_username, act_domain, act_uuid = get_namedomainuuid_by_id(
             db, self.client, act_userid)
         if acttype == 'status':
             real_activity = self.client.hmget(activity,
                                               ["time", 'status', 'comm'])
         elif acttype == 'note':
             real_activity = self.client.hmget(
                 activity, ["time", "title", "content", "status", 'comm'])
         elif acttype == 'link':
             real_activity = self.client.hmget(
                 activity,
                 ["time", "url", "title", "summary", 'status', 'comm'])
         elif acttype == 'doc':
             real_activity = self.client.hmget(
                 activity,
                 ["time", "docid", "title", "summary", 'status', 'comm'])
         real_activity.append(actto)
         real_activity.append(act_userid)
         real_activity.append(act_username)
         real_activity.append(act_domain)
         real_activity.append(act_uuid)
         real_activity.append(acttype)
         real_activity.append(index)
         index = index + 1
         all_activities.append(real_activity)
     return all_activities
Exemplo n.º 3
0
 def get_all_activities(self, db, startindex, ispoll):
     all_activities = []
     startindex = 0 if ispoll else startindex
     lastindex = ispoll-1 if ispoll else startindex+feed_number-1
     activities_list = self.client.lrange("all", startindex, lastindex)
     index = startindex + 1
     for activity in activities_list:
         acttype, act_userid, actto = activity.split(":")
         act_username,act_domain,act_uuid = get_namedomainuuid_by_id(db, self.client, act_userid)
         if acttype == 'status':
             real_activity = self.client.hmget(activity, ["time",'status','comm'])
         elif acttype == 'note':
             real_activity = self.client.hmget(activity, ["time","title","content","status",'comm'])
         elif acttype == 'link':
             real_activity = self.client.hmget(activity, ["time","url","title","summary",'status','comm'])
         elif acttype == 'doc':
             real_activity = self.client.hmget(activity, ["time","docid","title","summary",'status','comm'])
         real_activity.append(actto)
         real_activity.append(act_userid)
         real_activity.append(act_username)
         real_activity.append(act_domain)
         real_activity.append(act_uuid)
         real_activity.append(acttype)
         real_activity.append(index)
         index = index + 1
         all_activities.append(real_activity)
     return all_activities
Exemplo n.º 4
0
 def get_my_activities(self, db, user, startindex):
     my_activities = []
     activities_list = self.client.lrange("my:%s" % user, startindex,
                                          startindex + feed_number - 1)
     index = startindex + 1
     for activity in activities_list:
         acttype, act_userid, actto = activity.split(":")
         act_username, act_domain, act_uuid = get_namedomainuuid_by_id(
             db, self.client, act_userid)
         if acttype == 'status':
             real_activity = self.client.hmget(activity,
                                               ["time", 'status', 'comm'])
             real_activity.append(actto)
         if acttype == 'note':
             real_activity = self.client.hmget(
                 activity, ["time", "title", "content", "status", 'comm'])
             real_activity.append(actto)
         elif acttype == 'link':
             real_activity = self.client.hmget(
                 activity,
                 ["time", "url", "title", "summary", 'status', 'comm'])
             real_activity.append(actto)
         elif acttype == 'doc':
             real_activity = self.client.hmget(
                 activity,
                 ["time", "docid", "title", "summary", 'status', 'comm'])
             real_activity.append(actto)
         if acttype == 'follow':
             actto_username, actto_domain, actto_uuid = get_namedomainuuid_by_id(
                 db, self.client, actto)
             real_activity = self.client.hmget(activity, [
                 "time",
             ])
             real_activity.append(actto)
             real_activity.append(actto_username)
             real_activity.append(actto_domain)
             real_activity.append(actto_uuid)
         real_activity.append(act_userid)
         real_activity.append(act_username)
         real_activity.append(act_domain)
         real_activity.append(act_uuid)
         real_activity.append(acttype)
         real_activity.append(index)
         index = index + 1
         my_activities.append(real_activity)
     return my_activities
Exemplo n.º 5
0
 def get_top_activities(self, user, db, isself, startindex, item_num):
     Activity_list = []
     Activity_key = 'u:%s:%s' % (self.Activity_KEY, user)
     All_Activity_list = self.client.lrange(Activity_key, startindex, -1)
     index = 0
     for sub_activity_key in All_Activity_list:
         acttype, actuser, actto = sub_activity_key.split(":")
         if acttype == 'follow':
             sub_activity = self.client.hmget(sub_activity_key, [
                 "time",
             ])
             username, domain, uuid = get_namedomainuuid_by_id(
                 db, self.client, actto)
             sub_activity.append(username)  #follow who
             sub_activity.append(domain)  #domain
             sub_activity.append(actto)  #actto id
             sub_activity.append(uuid)  #actto uuid
             sub_activity.append(0)  #type:0
         elif acttype == 'status':
             sub_activity = self.client.hmget(sub_activity_key,
                                              ["time", "status"])
             sub_activity.append(actto)  #actto
             sub_activity.append(1)  #type:1
         elif acttype == 'note':
             sub_activity = self.client.hmget(
                 sub_activity_key, ["time", "title", "content", "status"])
             if not isself and sub_activity[3] != '0':
                 continue
             sub_activity.append(actto)  #actto
             sub_activity.append(2)  #type:2
         elif acttype == 'link':
             sub_activity = self.client.hmget(
                 sub_activity_key, ["time", "url", "title", "status"])
             if not isself and sub_activity[3] != '0':
                 continue
             sub_activity.append(actto)  #actto
             sub_activity.append(3)  #type:3
         elif acttype == 'doc':
             sub_activity = self.client.hmget(
                 sub_activity_key, ["time", "docid", "title", "status"])
             if not isself and sub_activity[3] != '0':
                 continue
             sub_activity.append(actto)  #actto
             sub_activity.append(4)  #type:4
         Activity_list.append(sub_activity)
         index = index + 1
         if index == item_num:
             break
     return Activity_list
Exemplo n.º 6
0
 def post(self):
     noteid = self.get_argument("id",None)
     notetype = self.get_argument("notetype",None)
     notetitle = self.get_argument("notetitle",None)
     notecontent = self.get_argument("notecontent",None)
     #status_:{0:public,1:private,2:delted
     rednotecontent = notecontent
     if len(notecontent) > 150:
         rednotecontent = notecontent[:140] + " ..."
     status_ = int(notetype)
     user_id = self.current_user.id
     rev_user = get_namedomainuuid_by_id(self.db,self.rd,str(user_id))
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     if noteid:
         noteid = decode(noteid)
         note_user = self.db.get("select user_id from fd_Note where id = %s", noteid)
         if not note_user or note_user.user_id != user_id:
             raise tornado.web.HTTPError(404)
         self.db.execute("update fd_Note set title = %s, note = %s,"
                 "status_ = %s where id = %s", notetitle, notecontent, status_, noteid)
         rev_num = int(self.db.get("select max(rev_num) as rev_num from fd_NoteHistory where note_id = %s", noteid).rev_num)
         self.db.execute("insert into fd_NoteHistory(note_id,title,note,rev_num,rev_user_id,"
                 "rev_user_name,rev_user_domain,revdate) values (%s,%s,%s,%s,%s,%s,%s,%s)", noteid, notetitle,
                 notecontent, rev_num+1, user_id, rev_user[0], rev_user[1], pubdate)
         note_key = "note:%s:%s" % (user_id, noteid)
         actdict = {'title':notetitle, 'content':rednotecontent, 'status':status_}
         if self.rd.hmset(note_key, actdict):
             self.write("right")
         else:
             self.write("wrong")
     else:
         redpubdate = pubdate[4:] if pubdate[3] == '0' else pubdate[3:]
         note_id = self.db.execute("insert into fd_Note (user_id, title, "
                 "note, pubdate, status_) values (%s,%s,%s,%s,%s)", user_id,
                 notetitle, notecontent, pubdate, status_)
         if note_id:
             self.db.execute("insert into fd_NoteHistory(note_id,title,note,rev_num,rev_user_id,"
                     "rev_user_name,rev_user_domain,revdate) values (%s,%s,%s,%s,%s,%s,%s,%s)", note_id, notetitle,
                     notecontent, 1, user_id, rev_user[0], rev_user[1], pubdate)
             actdict = {'time':redpubdate, 'title':notetitle, 
                     'content':rednotecontent, 'status':status_}
             addresult = add_activity(self.rd, user_id, note_id, 2, actdict)
             if addresult:
                 self.write(encode(str(note_id)))
                 #self.write("right")
             else:
                 self.write("wrong")
Exemplo n.º 7
0
 def get_top_activities(self, user, db, isself, startindex, item_num):
     Activity_list = []
     Activity_key = 'u:%s:%s' % (self.Activity_KEY, user)
     All_Activity_list = self.client.lrange(Activity_key, startindex, -1)
     index = 0
     for sub_activity_key in All_Activity_list:
         acttype,actuser,actto = sub_activity_key.split(":")
         if acttype == 'follow':
             sub_activity = self.client.hmget(sub_activity_key, ["time",])
             username,domain,uuid = get_namedomainuuid_by_id(db, self.client, actto)
             sub_activity.append(username)#follow who
             sub_activity.append(domain)#domain
             sub_activity.append(actto)#actto id
             sub_activity.append(uuid)#actto uuid
             sub_activity.append(0)#type:0
         elif acttype == 'status':
             sub_activity = self.client.hmget(sub_activity_key, ["time","status"])
             sub_activity.append(actto)#actto
             sub_activity.append(1)#type:1
         elif acttype == 'note':
             sub_activity = self.client.hmget(sub_activity_key, ["time","title","content","status"])
             if not isself and sub_activity[3] != '0':
                 continue
             sub_activity.append(actto)#actto
             sub_activity.append(2)#type:2
         elif acttype == 'link':
             sub_activity = self.client.hmget(sub_activity_key, ["time","url","title","status"])
             if not isself and sub_activity[3] != '0':
                 continue
             sub_activity.append(actto)#actto
             sub_activity.append(3)#type:3
         elif acttype == 'doc':
             sub_activity = self.client.hmget(sub_activity_key, ["time","docid","title","status"])
             if not isself and sub_activity[3] != '0':
                 continue
             sub_activity.append(actto)#actto
             sub_activity.append(4)#type:4
         Activity_list.append(sub_activity)                    
         index = index + 1
         if index == item_num:
             break
     return Activity_list
Exemplo n.º 8
0
 def get(self, prop):
     template_values = {}
     startindex = self.get_argument("lastindex", None)
     startindex = int(startindex)
     if prop in ["home", "myhome"]:
         if prop == "home":
             template_values['all_activities'] = self.uag.get_all_activities(self.db, startindex, False)
         elif prop == "myhome":
             template_values['all_activities'] = self.uag.get_my_activities(self.db, self.current_user.id, startindex)
         template_values['lastindex'] = startindex + feed_number
         template_values['hasnext'] = 1
         if template_values['lastindex'] >= self.uag.count_all_activity():
             template_values['hasnext'] = 0
         self.render("modules/home_activities.html", template_values=template_values)
     elif prop in ["city", "college", "major"]:
         name = self.get_argument("name", None)
         region = prop
         if region == "college":
             region_get = self.db.get("SELECT id,image_path FROM fd_College where name = %s", name)
         elif region == "city":
             region_get = self.db.get("SELECT id FROM fd_City where name = %s", name)
         elif region == "major":
             region_get = self.db.get("SELECT id FROM fd_Major where name = %s", name)
         if not region_get: raise tornado.web.HTTPError(404)
         region_id = region_get.id
         if region == "city": 
             people = self.db.query("SELECT SQL_CALC_FOUND_ROWS id,name,domain,uuid_ FROM fd_People WHERE (city_id=%s and college_type=1) or (ss_city_id=%s and college_type=2) or (bs_city_id=%s and college_type=3) limit %s,%s", region_id, region_id, region_id, startindex, people_number) 
         elif region == "college":
             people = self.db.query("SELECT SQL_CALC_FOUND_ROWS id,name,domain,uuid_ FROM fd_People WHERE (college_id=%s and college_type=1) or (ss_college_id=%s and college_type=2) or (bs_college_id=%s and college_type=3) limit %s,%s", region_id, region_id, region_id, startindex, people_number)
         elif region == "major":
             people = self.db.query("SELECT SQL_CALC_FOUND_ROWS id,name,domain,uuid_ FROM fd_People WHERE (major_id=%s and college_type=1) or (ss_major_id=%s and college_type=2) or (bs_major_id=%s and college_type=3) limit %s,%s", region_id, region_id, region_id, startindex, people_number) 
         people_count = self.db.get("select found_rows() as length").length
         for i in range(len(people)):
             people[i].is_follow = self.ufg.is_follow(self.current_user.id, people[i].id) if self.current_user else False
             people[i].image = self.avatar("m", people[i].id, people[i].uuid_)
             if not self.current_user or self.current_user and self.current_user.id != people[i].id:
                 people[i].is_self = False
             else:
                 people[i].is_self = True
         template_values['people'] = people
         template_values['lastindex'] = startindex + people_number
         template_values['hasnext'] = 1
         if template_values['lastindex'] >= people_count:
             template_values['hasnext'] = 0
         self.render("modules/follow_people.html", template_values=template_values)
     elif prop in ["following", "follower"]:
         follow_type = prop
         people_id = self.get_argument("name", None)
         if follow_type == 'following':
             follows = self.ufg.get_follows(people_id)
         elif follow_type == 'follower':
             follows = self.ufg.get_followers(people_id)
         follow_people = []
         for i in range(startindex, startindex+people_number):
             if i >= len(follows):
                 break
             follows[i] = int(follows[i])
         if len(follows) - startindex == 1:
             follow_people = self.db.query("SELECT id,name,domain,uuid_ from fd_People where id = %s", follows[startindex]) 
         else:
             orderstr = str(follows[startindex:startindex+people_number])[1:-1].replace(" ","")
             follow_people = self.db.query("SELECT id,name,domain,uuid_ from fd_People where id in %s order by find_in_set(id, %s)", tuple(follows[startindex:startindex+people_number]), orderstr) 
         for i in range(len(follow_people)):
             follow_people[i].is_follow = self.ufg.is_follow(self.current_user.id, follow_people[i].id) if self.current_user else False
             follow_people[i].image = self.avatar("m", follow_people[i].id, follow_people[i].uuid_)
             if not self.current_user or self.current_user and self.current_user.id != follow_people[i].id:
                 follow_people[i].is_self = False 
             else:
                 follow_people[i].is_self = True
         template_values['people'] = follow_people 
         template_values['lastindex'] = startindex + people_number
         template_values['hasnext'] = 1
         if template_values['lastindex'] >= len(follows):
             template_values['hasnext'] = 0
         self.render("modules/follow_people.html", template_values=template_values)
     elif prop in ["activity", "status", "note", "link", "doc"]:
         activities = ["activity","status","note","link","doc"]
         people_id = self.get_argument("name", None)
         isself = self.get_argument("isself", None)
         if isself == "True": isself = True
         elif isself == "False": isself = False
         else: raise tornado.web.HTTPError(404)
         username,domain,uuid = get_namedomainuuid_by_id(self.db, self.rd, people_id)
         template_values['domain'] = domain
         template_values['username'] = username
         if prop == "activity":
             activity_count = self.uag.count_activity(people_id)
             template_values['activities'] = self.uag.get_top_activities(people_id, self.db, isself, startindex, activity_number) 
         else:
             activity_count = self.uag.count_sub_activity(people_id, activities.index(prop)) 
             template_values['activities'] = self.uag.get_top_sub_activities(people_id, activities.index(prop), isself, startindex, activity_number) 
         template_values['activity_type'] = prop
         template_values['lastindex'] = startindex + activity_number
         template_values['hasnext'] = 1
         if template_values['lastindex'] >= activity_count:
             template_values['hasnext'] = 0
         self.render("modules/people_activities.html", template_values=template_values)