Example #1
0
 def post(self):
     from_user = self.get_argument("from_user",None)
     to_user = self.get_argument("to_user",None)
     if from_user == to_user or from_user == 0 or to_user == 0: raise tornado.web.HTTPError(405)
     if self.ufg.follow(from_user, to_user):
         acttime = time.strftime('%y-%m-%d %H:%M', time.localtime())
         redacttime = acttime[4:] if acttime[3] == '0' else acttime[3:]
         actto = self.db.get("select name from fd_People where id = %s", to_user).name
         actdict = {'time':redacttime}
         add_activity(self.rd, from_user, to_user, 0, actdict)
     else:
         self.write('already')
Example #2
0
 def post(self):
     status = self.get_argument("statustext", None)
     if not status: raise tornado.web.HTTPError(405)
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     redpubdate = pubdate[4:] if pubdate[3] == '0' else pubdate[3:]
     user_id = self.current_user.id
     status_id = self.db.execute(
         "insert into fd_Status (user_id, "
         " status, pubdate) values (%s,%s,%s)", user_id, status, pubdate)
     #redis
     if status_id:
         actdict = {'time': redpubdate, 'status': status}
         addresult = add_activity(self.rd, user_id, status_id, 1, actdict)
         if addresult:
             self.write(''.join([
                 encode(str(status_id)), ',',
                 self.avatar('m', self.current_user.id,
                             self.current_user.uuid_), ',',
                 self.br(
                     self.at(
                         linkify(
                             status,
                             extra_params="target='_blank' rel='nofollow'"))
                 )
             ]))
         else:
             self.write("Something wrong...")
Example #3
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")
Example #4
0
 def post(self):
     status = self.get_argument("statustext",None)
     if not status: raise tornado.web.HTTPError(405)
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     redpubdate = pubdate[4:] if pubdate[3] == '0' else pubdate[3:]
     user_id = self.current_user.id
     status_id = self.db.execute("insert into fd_Status (user_id, "
                 " status, pubdate) values (%s,%s,%s)", user_id, 
                 status, pubdate)
     #redis
     if status_id:
         actdict = {'time':redpubdate, 'status':status}
         addresult = add_activity(self.rd, user_id, status_id, 1, actdict)
         if addresult:
             self.write(''.join([encode(str(status_id)), ',', self.avatar('m',self.current_user.id,self.current_user.uuid_),',', self.br(self.at(linkify(status, extra_params="target='_blank' rel='nofollow'")))]))
         else:
             self.write("Something wrong...")
Example #5
0
 def post(self):
     url = self.get_argument("linkurl",None)
     title = self.get_argument("linktitle",None)
     summary = self.get_argument("linksummary",None)
     tag = self.get_argument("linktag",None)
     oldtag = self.get_argument("oldtag",None)
     linktype = self.get_argument("linktype",None)
     pubtype = self.get_argument("pubtype",0)
     linkid = self.get_argument("linkid",None)
     pubtype = int(pubtype)
     if linkid:
         linkid = decode(linkid)
         link_user = self.db.get("select user_id from fd_Link where id = %s", linkid)
         if not link_user or link_user.user_id != self.current_user.id:
             raise tornado.web.HTTPError(404)
     if not url:
         raise tornado.web.HTTPError(500)
     url = url[7:] if url.startswith("http://") else url
     url = url[8:] if url.startswith("https://") else url
     if linkid:
         link_sql = ["update fd_Link set url = '{0}',".format(url.replace('%','%%'))]
     else:
         link_sql = ["insert into fd_Link set url = '{0}',".format(url.replace('%','%%'))]
     if title:
         link_sql.append("title = '{0}',".format(title.replace("'", "''").replace('%','%%')))
     if summary:
         link_sql.append("summary = '{0}',".format(summary.replace("'", "''").replace('%','%%')))
     if tag:
         tag = tag.strip().replace(' ',',')
         tag = tag.strip().replace(',',',')
         tags = tag.split(",")
         taglists = []
         for t in tags:
             if t in taglists:
                 continue
             taglists.append(t)
         newtag = " ".join(taglists)
         if not (pubtype == 2 and newtag == oldtag):
             link_sql.append("tags = '{0}',".format(newtag.replace("'", "''").replace('%','%%')))
     pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
     redpubdate = pubdate[4:] if pubdate[3] == '0' else pubdate[3:]
     if pubtype == 2:
         link_sql.append("status_ = {0} where id = {1}".format(linktype,linkid))
     else:
         link_sql.append("user_id = {0},pubdate = '{1}',status_ = {2}".format(self.current_user.id,pubdate,linktype))
     fd_link_sql = "".join(link_sql)
     link_id = self.db.execute(fd_link_sql)
     if tag:
         if pubtype != 2 or pubtype == 2 and newtag != oldtag:
             for t in taglists:
                 tag_id = self.db.get("select id from fd_Tag where tag = %s", t)
                 if tag_id:
                     tag_id = tag_id.id
                 else:
                     tag_id = self.db.execute("insert into fd_Tag (tag) values (%s)", t)
                 if linkid:
                     with_link_id = linkid
                 elif link_id:
                     with_link_id = link_id
                 ltag_id = self.db.execute("insert into fd_Ltag (link_id,tag_id) values (%s,%s)", with_link_id, tag_id)
     if linkid: 
         link_key = "link:%s:%s" % (self.current_user.id, linkid)
         actdict = {'url':url, 'status':linktype}
         if title:
             actdict['title'] = title
         if summary:
             actdict['summary'] = summary
         if self.rd.hmset(link_key, actdict):
             self.write("/")
     elif link_id:
         actdict = {'time':redpubdate, 'url':url, 'status':linktype}
         if title:
             actdict['title'] = title
         if summary:
             actdict['summary'] = summary
         addresult = add_activity(self.rd, self.current_user.id, link_id, 3, actdict)
         if addresult:
             self.write("http://" + url)
Example #6
0
    def post(self):
        template_values = {}
        title = self.get_argument("title", None)
        summary = self.get_argument("summary", None)
        tag = self.get_argument("tag", None)
        secret = self.get_argument("secret", None)
        endocid = self.get_argument("docid", None)
        oldtag = self.get_argument("oldtag", None)
        errors = 0
        title_error = 0
        title_error_messages = ['',
                u'请输入标题',
                ]
        if not endocid:
            name = self.get_argument("doc.name", None)
            content_type = self.get_argument("doc.content_type", None)
            path = self.get_argument("doc.path", None)
            md5 = self.get_argument("doc.md5", None)
            size = self.get_argument("doc.size", None)
        if not title or len(title) == 0:
            errors = errors + 1
            title_error = 1
            template_values['title_error'] = title_error
            template_values['title_error_message'] = title_error_messages[title_error]
        else:
            doc_error = 0
            doc_error_messages = ['',
                    u'请选择文档',
                    u'暂时不支持该文档格式',
                    u'文档不能大于20M',
                    u"该文档已被上传过",
                    ]
            if not endocid:
                if not (name and path and md5 and size):
                    errors = errors + 1
                    doc_error = 1
                else:
                    if name.split(".").pop().lower() not in ["doc", "docx", "ppt", "pptx", "pdf", "xls"]:
                        os.remove(path)
                        errors = errors + 1
                        doc_error = 2
                    else:
                        if int(size) > 1024*1024*20:
                            os.remove(path)
                            errors = errors + 1
                            doc_error = 3
                        else:
                            predoc = self.db.get("select * from fd_Doc where md5 = %s and status_ = 0", md5)
                            if predoc:
                                os.remove(path)
                                errors = errors + 1
                                doc_error = 4
                            else:
                                usrpath = u"/data/static/usrdoc/%s/" % self.current_user.id
                                staticpath = u"/work/Dormforge/static/usrdoc/%s/" % self.current_user.id
                                if not os.path.exists(usrpath):
                                    os.makedirs(usrpath)
                                if not os.path.exists(staticpath):
                                    os.makedirs(staticpath)
                                docid = "".join([path.split("/").pop(), str(time.time()).split(".")[0]])
                                doctype = name.split(".").pop().lower()
                                usrdoc = ''.join([usrpath, docid, '.', doctype])
                                shutil.move(path, usrdoc)
                                if name.split(".").pop().lower() != 'pdf':
                                    usrpdf = ''.join([usrpath, docid, ".pdf"])
                                    usrjpg = ''.join([staticpath, docid, ".jpg"])
                                    usrswf = ''.join([staticpath, docid, ".swf"])
                                    if os.path.exists("/opt/libreoffice3.5/program/python"):
                                        os.system("/opt/libreoffice3.5/program/python /work/Dormforge/util/DocumentConverter.py %s %s" % (usrdoc, usrpdf))
                                    else:
                                        os.system("python /work/Dormforge/util/DocumentConverter.py %s %s" % (usrdoc, usrpdf))
                                    os.system("convert -sample 150x150 %s[0] %s" % (usrpdf, usrjpg))
                                    os.system("pdf2swf %s -o %s -f -T 9 -t -s storeallcharacters" % (usrpdf, usrswf))
                                    os.remove(usrpdf)
                                else:
                                    usrjpg = ''.join([staticpath, docid, ".jpg"])
                                    usrswf = ''.join([staticpath, docid, ".swf"])
                                    os.system("convert -sample 150x150 %s[0] %s" % (usrdoc, usrjpg))
                                    os.system("pdf2swf %s -o %s -f -T 9 -t -s storeallcharacters" % (usrdoc, usrswf))

            if doc_error != 0:
                template_values['doc_error'] = doc_error
                template_values['doc_error_message'] = doc_error_messages[doc_error]
            else:
                if endocid:
                    doc_sql = ["update fd_Doc set "]
                else:
                    if os.path.exists(usrjpg) and os.path.exists(usrswf):
                        doc_sql = ["insert into fd_Doc set doc_id = '%s',name = '%s',content_type = '%s',md5 = '%s', docsize = %s," % (docid,name.replace("'", "''").replace("%", "%%"),content_type,md5,int(size))]
                doc_sql.append("title = '%s'," % title.replace("'", "''").replace("%", "%%"))
                if summary:
                    doc_sql.append("summary = '%s'," % summary.replace("'", "''").replace("%", "%%"))
                if tag:
                    tag = tag.strip().replace(' ',',')
                    tag = tag.strip().replace(',',',')
                    tags = tag.split(",")
                    taglists = []
                    for t in tags:
                        if t in taglists:
                            continue
                        taglists.append(t)
                    newtag = " ".join(taglists)
                    if not (endocid and newtag == oldtag):
                        doc_sql.append("tags = '%s'," % newtag.replace("'", "''").replace("%", "%%"))
                pubdate = time.strftime('%y-%m-%d %H:%M', time.localtime())
                redpubdate = pubdate[4:] if pubdate[3] == '0' else pubdate[3:]
                doctype = 0
                if secret and secret == "on":
                    doctype = 1
                if endocid:
                    doc_sql.append("status_ = %s where id = %s" % (doctype, decode(endocid)))
                else:
                    doc_sql.append("user_id = %s,pubdate = '%s',status_ = %s" % (self.current_user.id,pubdate,doctype))
                doc_id = self.db.execute("".join(doc_sql))
                if tag:
                    if (not endocid) or (endocid and newtag != oldtag):
                        for t in taglists:
                            tag_id = self.db.get("select id from fd_Doctag where tag = %s", t)
                            if tag_id:
                                tag_id = tag_id.id
                            else:
                                tag_id = self.db.execute("insert into fd_Doctag (tag) values (%s)", t)
                            if endocid:
                                with_doc_id = decode(endocid)
                            elif doc_id:
                                with_doc_id = doc_id
                            dtag_id = self.db.execute("insert into fd_Dtag (doc_id,tag_id) values (%s,%s)", with_doc_id, tag_id)
                if endocid:
                    doc_key = "doc:%s:%s" % (self.current_user.id, decode(endocid))
                    actdict = {'status':doctype}
                elif doc_id:
                    actdict = {'time':redpubdate, 'docid':docid, 'status':doctype}#docid not doc_id
                if title:
                    actdict['title'] = title
                if summary:
                    actdict['summary'] = summary
                if endocid:
                    if self.rd.hmset(doc_key, actdict):
                        self.redirect("/doc/" + endocid)
                elif doc_id:
                    addresult = add_activity(self.rd, self.current_user.id, doc_id, 4, actdict)
                    if addresult:
                        self.redirect("/doc/" + encode(str(doc_id)))

        if errors != 0:
            if title:
                template_values['title'] = title
            if summary:
                template_values['summary'] = summary
            if tag:
                template_values['tag'] = tag
            self.render("editdoc.html", template_values=template_values)