예제 #1
0
파일: item.py 프로젝트: sinreal/miihui
 def GET(self,id):
    page=int(web.input().get('page','1'))
    item=Node.objects(ID=int(id)).first()
    #todo 分页 or ajax
    comments=Tweet.objects(Q(SubjectID=int(id))&Q(flag__ne=1)).order_by("-ID") 
    #flag=1 means share 
    next=None
    if Auth.is_login():
         user=User.objects(id=Auth.uid()).first()
         mycollect=user.nodes_follow
         if item.ID in mycollect:
            collected=True
         else:
           collected=False
    else:
         user=None
         collected=False
    if item and  item.creatorID:
        creator=User.objects(ID=item.creatorID).first()
    else:
        creator =None
    datalist=[]
    for comment in comments:
       datalist.append((User.objects(ID=comment.AutherID).first(),comment))
    if user==creator :
            editble=True
    else:
           editble=False
    if  user and ( user.email=="*****@*****.**" or user.email=="*****@*****.**"  ):
            editble=True
    return render.item(editble=editble,user=user,creator=creator,item=item,datalist=datalist,collected=collected)
예제 #2
0
파일: profile.py 프로젝트: sinreal/miihui
 def POST(self):
        uid=Auth.uid()
        user=User.objects(id=uid).first()
        _file= web.input(avatar={})
        if _file['avatar'].filename!="" and  _file['avatar'].filename[-3:]=="jpg":
              fileimg=_file['avatar'].value 
              _filename=TEMP+"/"+str(user.ID)+".jpg"
              open(_filename,"wb").write(fileimg)
              im = Image.open(_filename)
              (width,height)=im.size
              if width<=height:
                im_new=im.resize((100,int(height*100.0/width)),Image.ANTIALIAS)
                im_new.transform((100,100),Image.EXTENT ,(0,0,100,100),Image.BILINEAR).save('m'+uid+".jpg",quality = 95)
                im_new.transform((50,50),Image.EXTENT,(0,0,100,100)).save(STATIC_FILE+'/s'+uid+".jpg",quality = 95)
                im_new.save(STATIC_FILE+'/b'+uid+".jpg",quality = 95)   
              else:    
                im_new=im.resize((int(width*100.0/height),100))
                im_new.transform((100,100),Image.EXTENT,(0,0,100,100),Image.BILINEAR).save('m'+uid+".jpg",quality = 95)
                im_new.transform((50,50),Image.EXTENT,(0,0,100,100)).save(STATIC_FILE+'/s'+uid+".jpg",quality = 95)
                im_new.save(STATIC_FILE+'/b'+uid+".jpg",quality = 95)
              user.avatar="s"+uid+".jpg"
              user.avatar_big="b"+uid+".jpg"                          
              user.save()
        else:
            render.profile_avatar(is_login=True,user=user,content=u"请上传JPG文件")      
        return  render.profile_avatar(is_login=True,user=user,content=u"更新头像成功")
예제 #3
0
파일: user.py 프로젝트: sinreal/miihui
  def GET(self,uid):
      myuid=Auth.uid()
      page=int(web.input().get("page","1")) 
      thisguy=User.objects(ID=int(uid)).first()
      if not thisguy:
          return  render.notfound()
      thisguy.tweet_count=Tweet.objects(AutherID=thisguy.ID).count()
      counts = thisguy.followings_count,thisguy.followed_count,thisguy.tweet_count
      
      #update count
      if page*20<counts[2]:
         next=page+1
      elif page*20-counts[2]>20 :
         return  web.notfound()
      else:  
         next=None

      if Auth.is_login():
          me=User.objects(id=Auth.uid()).first()
      else:
          me=None
          
      if not me:
           relation=None
      elif me==thisguy:
          relation="self"
      elif thisguy.ID in me.followings:
           relation="ifollowhim"
      else:
           relation=None
      # do i follow that people?
      datalist=[]
      posts=Tweet.objects(AutherID=thisguy.ID).order_by("-ID")[(page-1)*20:page*20]
  
      for p in posts:
          if p.SubjectID>0:
              if p.flag==1:
                 datalist.append(("share" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))
              elif p.flag==-1:
                  pass   
              else:   
                 datalist.append(("comment" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))
          elif p.flag==-1:
                  pass
          else: 
                datalist.append(("say",p,friendly_time(p.created).decode("utf-8")))  
      return  render.user(user=me,thisguy=thisguy,counts=counts,next=next,datalist=datalist,relation=relation)
예제 #4
0
파일: profile.py 프로젝트: sinreal/miihui
 def POST(self):
        uid=Auth.uid()
        intro=web.input().get("intro")
        user=User.objects(id=uid).first()
        if intro!=user.intro:
            user.intro=intro                      
        user.save()    
        return  render.profile(is_login=True,user=user,content=u"更新信息成功")
예제 #5
0
파일: profile.py 프로젝트: sinreal/miihui
 def POST(self):
        uid=Auth.uid()
        passwd=web.input().get("password")
        passwd1=web.input().get("password1")
        user=User.objects(id=uid).first()
        if passwd and (passwd!=passwd1):
            return render.profile_password(is_login=True,user=user,content=u"两次密码不同,请再次输入")
        return  render.profile_password(is_login=True,user=user,content=u"更新密码成功")
예제 #6
0
파일: app.py 프로젝트: sinreal/miihui
 def GET(self):
   if Auth.is_login():
      user=User.objects(id=Auth.uid()).first()
   else:
      user=None
   nodes=Node.objects(score=20).order_by("-ID")
   if nodes.count()>20:
        nodes=nodes[0:20]
   return render.index(user=user,nodes=nodes)           
예제 #7
0
파일: app.py 프로젝트: sinreal/miihui
 def GET(self,uid): 
   if Auth.is_login():
       user=User.objects(id=Auth.uid()).first()
   else:
       user=None
   thisguy=User.objects(ID=uid).first()    
   datalist=[]    
   shares=Share_items.objects(creatorID=int(uid))
   counts=(0,0,0)
   for p in shares:
          datalist.append(("share" ,Node.objects(ID=p.itemID).first(),p, friendly_time(p.created).decode("utf-8")))
   return render.share_items(user=user,thisguy=thisguy,datalist=datalist,counts=counts)
예제 #8
0
파일: item.py 프로젝트: sinreal/miihui
 def GET(self):
     user=User.objects(id=Auth.uid()).first()  
     if web.input().get("count",None):             
          count=web.input().get("count",None)
          piclist=[]
          for i in range(int(count)):
               piclist.append(web.input().get("u"+str(i)))
          title=web.input().get("title")
          #print title
          url=web.input().get("fromurl")
          store=get_store(url).decode("utf-8")
          des=web.input().get("d",None)
          return render.share_bm(user=user,piclist=piclist,store=store,title=title,url=url,des=des)
     return render.share(is_login=True,user=user)
예제 #9
0
파일: user.py 프로젝트: sinreal/miihui
 def POST(self):
   unfoid=web.input().get("unfollow")
   thisguy=User.objects(ID=int(unfoid)).first()
   user=User.objects(id=Auth.uid()).first()
   followings=user.followings
   _id=int(unfoid)
   if _id in followings:
      followings.remove(_id)
      user.followings=followings
      user.followings_count-=1
      thisguy.followed_count-=1
      user.save()
      thisguy.save()
      return "Unfollow_success"
   return "cant unfollow"
예제 #10
0
파일: app.py 프로젝트: sinreal/miihui
 def POST(self):
     user=User.objects(id=Auth.uid()).first()
     if user.role!=2:
         return "blocked"
     content=web.input().get('txt')
     typet=web.input().get('type')
     subtopID=int(web.input().get('stID','0'))
     if not content:
        return "Content_empty"
     if typet=="post":
         tweet=Tweet(ID=Tweet.objects.count()+101,AutherID=user.ID,SubjectID=subtopID,content=content)
         user.tweet_count+=1
         tweet.save()
         user.save()
     return "Success"
예제 #11
0
파일: user.py 프로젝트: sinreal/miihui
 def GET(self,uid):
     #关注我的人 should keep it in  a list ?
     if Auth.is_login():
             me=User.objects(id=Auth.uid()).first()
     else:
            me=None
     user=User.objects(ID=int(uid)).first()
     followeds=User.objects(followings=user.ID)
     page=int(web.input().get("page","1"))
     count=user.followed_count
     if page*10<count:
        next=page+1
     else:
        next=None      
     return render.followeds(user=me,thisguy=user,count=count,next=next,followeds=followeds)
예제 #12
0
파일: user.py 프로젝트: sinreal/miihui
 def GET(self,uid):
     #关注的人
     if Auth.is_login():
            me=User.objects(id=Auth.uid()).first()
     else:
            me=None
     user=User.objects(ID=int(uid)).first()
     followings_ids=user.followings
     followings=[User.objects(ID=idd).first() for idd in followings_ids] 
     page=int(web.input().get("page","1"))
     count=user.followings_count
     if page*10<count:
        next=page+1
     else:
        next=None      
     return  render.followings(user=me,thisguy=user,count=count,next=next,followings=followings)
예제 #13
0
파일: app.py 프로젝트: sinreal/miihui
 def GET(self,userID):
   thisguy=User.objects(ID=userID).first()
   c= thisguy.nodes_follow
   if not  c:
     collections=[]
   else:
      collections=[]
      #取最新的收藏
      for _id in c:
        collections.append(Node.objects(ID=_id).first())
   if Auth.is_login():
          me=User.objects(id=Auth.uid()).first()
   else:
         me=None
   counts = thisguy.followings_count,thisguy.followed_count,thisguy.tweet_count      
   return render.usercollections(user=me,thisguy=thisguy, collections=collections, counts =counts)
예제 #14
0
파일: app.py 프로젝트: sinreal/miihui
 def  POST(self):
      user=User.objects(id=Auth.uid()).first()
      itemid=web.input().get("itemid")
      # print itemid
      #数据结构为 item,收藏此item的ID
      c=Collect.objects(ID=int(itemid))
      if len(c)!=0:
          c.update_one(push__userlist=user.ID)
          user.update(push__nodes_follow=int(itemid))
          user.save()
          c.first().save()
      else:
         c=Collect(ID=user.ID,userlist=[itemid])
         user.update(push__nodes_follow=int(itemid))
         user.save()
         c.save()
      return None
예제 #15
0
파일: user.py 프로젝트: sinreal/miihui
 def POST(self):
   myuid=Auth.uid()
   foid=web.input().get("follow")
   if myuid==str(User.objects(ID=foid).first().id):
       return "not_allowed"
   print str(myuid)==str(User.objects(ID=foid).first().id)
   user=User.objects(id=myuid).first()
   thisguy=User.objects(ID=int(foid)).first()
   if thisguy.ID not in user.followings:
       ids=user.followings
       ids.append(thisguy.ID)
       user.ids=ids
       user.followings_count+=1
       thisguy.followed_count+=1
       user.save()
       thisguy.save()
       return "success"
   return "failed"
예제 #16
0
파일: item.py 프로젝트: sinreal/miihui
 def POST(self):   
     
     name=web.input().get("name")
     _tags=web.input().get("tags")
     source=web.input().get("source")                 
     if _tags:
          tags=[x for x in  _tags.split(",")]
     else:
          tags=[]
     user=User.objects(id=Auth.uid()).first()     
     creatorID=user.ID     
     intro=web.input().get("intro")
     picurl=web.input().get("picurl",None)
     price=web.input().get("price")
     link=web.input().get("source")
     store=get_store("store")
     price=web.input().get("price")
     buyinfo=Buy_info(link=link,store=store,price=price)
     #check if none 
     pic=urllib2.urlopen(picurl).read()
     ID=Node.objects.count()+1
     open(str(ID)+".jpg","wb").write(pic)
     u = UpYun(BUCKETNAME,USER,PASSWORD)
     data = open(str(ID)+".jpg",'rb')
     u.setContentMD5(md5file(data))
     a = u.writeFile('/o'+str(ID)+'.jpg',data)
     if not a:
       return "get picture erro"
     #cut_item_picture(STATIC_FILE,ID,str(ID)+".jpg")  
     node=Node(creatorID=creatorID,ID=ID,name=name,des=intro,picurl=picurl,tags=tags,buy_info=[buyinfo])
     node.picinfo=101    #a out sidelink
     node.save()
     share=Share_items(ID=Share_items.objects.count()+1,creatorID=user.ID,itemID=ID,flag=1,content="")
     share.save()
     #加入到shareitem中
     #todo count更新
     tweet=Tweet(ID=Tweet.objects.count()+1,AutherID=user.ID,SubjectID=ID,flag=1,content=str(ID))
     tweet.save()
     return web.seeother("/item/"+str(ID)+"/")
예제 #17
0
파일: item.py 프로젝트: sinreal/miihui
 def POST(self):
          picurl=web.input().get("check")
          name=web.input().get("name")
          _tags=web.input().get("tags")
          source=web.input().get("source")                 
          if _tags:
            tags=[x for x in  _tags.split(",")]
          else:
            tags=[]
          user=User.objects(id=Auth.uid()).first()     
          creatorID=user.ID     
          intro=web.input().get("intro")
          price=web.input().get("price")
          link=web.input().get("source")
          store=web.input().get("store")
          #store=get_store(link).decode("utf-8")
          price=web.input().get("price")
          buyinfo=Buy_info(link=link,store=store,price=price)
          pic=urllib2.urlopen(picurl).read()
          ID=Node.objects.count()+1
          open(str(ID)+".jpg","wb").write(pic)
          u = UpYun(BUCKETNAME,USER,PASSWORD)
          data = open(str(ID)+".jpg",'rb')
          u.setContentMD5(md5file(data))
          a = u.writeFile('/o'+str(ID)+'.jpg',data)
          if not a:
              return "get picture erro"
          #cut_item_picture(STATIC_FILE,ID,str(ID)+".jpg")  
          node=Node(creatorID=creatorID,ID=ID,name=name,des=intro,picurl=picurl,tags=tags,buy_info=[buyinfo])
          node.picinfo=101    #a out sidelink
          node.save()
          share=Share_items(ID=Share_items.objects.count()+1,creatorID=user.ID,itemID=ID,flag=1,content="")
          share.save()
          content=u'''<h1>发布成功</h1><p>你可以<a href="/item/%s/">去看看</a>或者
          <a href="%s">回到刚才的逛的</a>'''%(str(ID),source)
          return render.info(content=content)
          return web.seeother("/item/"+str(ID)+"/")
예제 #18
0
파일: app.py 프로젝트: sinreal/miihui
  def GET(self):
      page=int(web.input().get("page","1")) 
      me=User.objects(id=Auth.uid()).first()
      #todo ..
      me.tweet_count=Tweet.objects(AutherID=me.ID).count()
      counts = me.followings_count,me.followed_count,me.tweet_count
      c= me.nodes_follow
      if not  c:
         collections=[]
      else:
          collections=[]
          #取最新的收藏
          for _id in c:
            collections.append(Node.objects(ID=_id).first())
      if len(collections)>6:
         collections=collections[0:6]
      print counts[2]   
      if page*20<counts[2]:
         next=page+1
      elif page*20-counts[2]>20 :
         return  web.notfound()
      else:  
         next=None
      datalist=[]
      posts=Tweet.objects(AutherID=me.ID).order_by("-ID")[(page-1)*20:page*20]

      for p in posts:
          if p.SubjectID>0:
              if p.flag==1:
                   datalist.append(("share" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))  
              else:
                  datalist.append(("comment" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))
          else:
              datalist.append(("say",p,friendly_time(p.created).decode("utf-8")))
              
      return render.home(datalist=datalist,user=me,counts=counts,next=next,collections=collections)
예제 #19
0
파일: profile.py 프로젝트: sinreal/miihui
 def GET(self):
        uid=Auth.uid()
        user=User.objects(id=uid).first()
        
        return render.profile_avatar(is_login=True,user=user)