예제 #1
0
파일: page.py 프로젝트: ergatea/gitpub2
    def post(self, mid):
        is_shared = self.get_argument("is_shared", "off")
        is_shared = True if is_shared == "on" else False
        content = self.get_argument("content")
        source_mid = self.get_argument("source_mid")
        upper = Reply.getObjectByObjectId(mid)
        source = Topic.getObjectByObjectId(source_mid)
        if upper and source:
            reply = Reply.save_reply(source=source, content=content, owner=self.current_user, upper=upper)
            names_list = get_usernames(content)
            for username in names_list:
                send_mentions(sender=self.current_user, username=username, reply=reply)

            if is_shared:
                url = getattr(self.opts, "%s_update_url" %self.current_user.port)
                source_url = "%s/r/%s" %(self.prefix_url, reply.mid)
                status = "%s\n%s" %(content.replace("#%s" %self.current_user.port, ""), source_url)
                
                message_request(
                    url, 
                    self.current_user.port, 
                    self.current_user.access_token, 
                    status,
                    app_key=getattr(self.opts, "%s_key" %self.current_user.port),
                    openid=self.current_user.oauth_id,
                    client_ip=self.request.remote_ip)
      
            self.finishedMsg(status="success", info="post reply success", next=self.request.path)
        else:
            self.finishedMsg(status="error", info="topic not found")  
예제 #2
0
파일: page.py 프로젝트: ergatea/gitpub2
 def get(self, mid):
     topic = Topic.getObjectByObjectId(mid)
     if topic:
         topic.incr_views()
         self.render("page/topic.html", topic=topic)
     else:
         self.write_error(404)
예제 #3
0
파일: page.py 프로젝트: ergatea/gitpub2
    def post(self, mid):
        content = self.get_argument("content", None)
        is_shared = self.get_argument("is_shared", "off")
        is_shared = True if is_shared == "on" else False
        if content and mid:
            if 5 < len(content) < 280:
                topic = Topic.getObjectByObjectId(mid)
                if topic:
                    reply = Reply.save_reply(
                        source=topic,
                        content=content, 
                        owner=self.current_user,
                        topic=topic
                    )

                    # Update level if level=1
                    self.current_user.upgrade_level(xp=1)

                    # Send mention for @username format notification
                    names_list = get_usernames(content)
                    for username in names_list:
                        send_mentions(sender=self.current_user, username=username, reply=reply)
                    
                    if is_shared:
                        url = getattr(self.opts, "%s_update_url" %self.current_user.port)
                        source_url = "%s/t/%s" %(self.prefix_url, topic.mid)                        
                        status = "%s\n%s" %(content.replace("#%s" %self.current_user.port, ""), source_url)
                        attachments = self.dumpsJson(title="GitPub", 
                            href="%s/t/%s" %(self.prefix_url, topic.mid), description="From GitPub: ")
                        message_request(
                            url, 
                            self.current_user.port, 
                            self.current_user.access_token, 
                            status,
                            app_key=getattr(self.opts, "%s_key" %self.current_user.port),
                            openid=self.current_user.oauth_id,
                            client_ip=self.request.remote_ip,
                            attachments=attachments)
                                          
                    self.finishedMsg(status="success", info="post reply success", next=self.request.path)
                else:
                    self.finishedMsg(status="error", info="wrong topic shorted")
            else:
                self.finishedMsg(status="error", info="reply too long or too short")
        else:
            self.finishedMsg(status="error", info="incorrect arguments")