Example #1
0
 def POST(self, slug):
     entry, p = self.getEntry(slug)
     f = commentForm()
     if f.validates():
         comment = Comment(entry.id, f.username.value, f.email.value,
                           f.url.value, f.comment.value)
         entry.comment_num = entry.comment_num + 1
         entry.view_num = entry.view_num - 1
         web.ctx.orm.add(comment)
         emails = ['*****@*****.**']
         message = u'<p>您在&lt;泥泞的沼泽&gt;上回复的日志 "' + entry.title + u'" 又有新的回复了, 请您去看看.</p><p>' \
             u'<a href="http://davidx.me/entry/' + slug + u'/#comments">点击查看回复</a></p>'
         for c in entry.comments:
             emails.append(c.email)
         for e in set(emails):
             try:
                 web.sendmail(
                     '*****@*****.**',
                     e,
                     '您在"泥泞的沼泽"上回复的日志又有新的回复了!'.encode('utf-8'),
                     message,
                     headers={'Content-Type': 'text/html;charset=utf-8'})
             except:
                 pass
         raise web.seeother('/entry/%s/' % slug)
     else:
         d['p'] = p
         d['entry'] = entry
         d['f'] = f
         d['usedTime'] = time.time() - d['startTime']
         return render.entry(**d)
Example #2
0
 def POST(self, slug):
     entry, p = self.getEntry(slug)
     f = commentForm()
     if f.validates():
         comment = Comment(entry.id, f.username.value, f.email.value, f.url.value, f.comment.value)
         entry.comment_num = entry.comment_num + 1
         entry.view_num = entry.view_num - 1
         web.ctx.orm.add(comment)
         emails = ['*****@*****.**']
         message = u'<p>您在&lt;泥泞的沼泽&gt;上回复的日志 "' + entry.title + u'" 又有新的回复了, 请您去看看.</p><p>' \
             u'<a href="http://davidx.me/entry/' + slug + u'/#comments">点击查看回复</a></p>'
         for c in entry.comments:
             emails.append(c.email)
         for e in set(emails):
             try:
                 web.sendmail('*****@*****.**', e,
                     '您在"泥泞的沼泽"上回复的日志又有新的回复了!'.encode('utf-8'), message,
                     headers={'Content-Type':'text/html;charset=utf-8'})
             except:
                 pass
         raise web.seeother('/entry/%s/' % slug)
     else:
         d['p'] = p
         d['entry'] = entry
         d['f'] = f
         d['usedTime'] = time.time() - d['startTime']
         return render.entry(**d)
Example #3
0
def comment(request):        
    if request.POST :
        commentform = commentForm(request.POST) # A form bound to the POST data
        if 'comment_parent' in request.POST :
            if commentform.is_valid :
                try:
                    commentpush = commentform.save(commit = False)
                    commentpush.type = 3
                    commentpush.owner = request.user
                    commentpush.pushimage = image.objects.get(title="_noimage")
                    r= []
                    agree = image.objects.filter(title= '_agree')[0]
                    disagree = image.objects.filter(title= '_disagree')[0]
                    r.append({'name':LANGUAGE['agree'] , 'image':agree})
                    r.append({'name':LANGUAGE['disagree'] , 'image':disagree})
                    commentpush.ballotdata = r
                    commentpush.save()
                    commentpush.ballotdata = []
                    commentpush.comment.add(pushitem.objects.get(id=request.POST['comment_parent']))
                    comment.title = "Comment" # not using comment titles in UI, but can't be blank or null
                    commentpush.save()
                    return commentpush
                except Exception, ex:
                    logging.debug('salcat.views.comment: Exception: %s' % ex)
            else:
                logging.debug("Invalid Comment: %s" % commentform)
Example #4
0
 def GET(self, slug):
     entry, p = self.getEntry(slug)
     entry.view_num = entry.view_num + 1
     f = commentForm()
     d['p'] = p
     d['entry'] = entry
     d['f'] = f
     d['usedTime'] = time.time() - d['startTime']
     return render.entry(**d)
Example #5
0
 def GET(self, slug):
     entry, p = self.getEntry(slug)
     entry.view_num = entry.view_num + 1
     f = commentForm()
     d['p'] = p
     d['entry'] = entry
     d['f'] = f
     d['usedTime'] = time.time() - d['startTime']
     return render.entry(**d)
Example #6
0
 def POST(self, slug):
     f = commentForm()
     entry = self.get_entry(slug)
     i = web.input()
     if f.validates():
         if i.url == "":
             i.url = "#"
             #createdTime = datetime.now().strftime("%Y-%m-%d %H:%M")
             #db.insert('comments', entryId=i.entryId, email=i.email, username=i.username, url=i.url, comment=i.comment,createdTime=createdTime)
             #db.update('entries', where = 'id=%s' % entry.entryId, commentNum = entry.commentNum + 1)
         comment = Comment(i.email, i.username, i.url, i.comment, entry.id)
         web.ctx.orm.add(comment)
         entry.commentNum = entry.commentNum + 1
         raise web.seeother('/entry/%s/' % slug)
     else:
         d['f'] = f
         d['entry'] = entry
         return render.entry(**d)
Example #7
0
 def POST(self, slug):
     f = commentForm()
     entry = self.get_entry(slug)
     i = web.input()
     if f.validates():
         if i.url == "":
             i.url = "#"
             #createdTime = datetime.now().strftime("%Y-%m-%d %H:%M")
             #db.insert('comments', entryId=i.entryId, email=i.email, username=i.username, url=i.url, comment=i.comment,createdTime=createdTime)
             #db.update('entries', where = 'id=%s' % entry.entryId, commentNum = entry.commentNum + 1)
         comment = Comment(i.email, i.username, i.url, i.comment, entry.id)
         web.ctx.orm.add(comment)
         entry.commentNum = entry.commentNum + 1
         raise web.seeother('/entry/%s/' % slug)
     else:
         d['f'] = f
         d['entry'] = entry
         return render.entry(**d)
Example #8
0
    def GET(self, slug):
        #entry = list(db.select('entries', where="slug=$slug", vars={'slug': slug}))
        #entry = list(db.query("select en.id AS entryId, en.title AS entry_title, en.slug AS entry_slug, en.content AS entry_content, en.createdTime AS entry_created_time, c.name AS entry_category, en.commentNum from entries en LEFT JOIN categories c ON en.categoryId = c.id where en.slug=$slug", vars={'slug': slug}))
        #entry[0].tags = db.query("select * from tags t LEFT JOIN entry_tag et ON t.id = et.tagId WHERE et.entryId = $id", vars={'id': entry[0].entry_id})
        ##for one in entry:
        ##    one.tags = db.query("select * from tags t left join entry_tag et on et.tagId=t.id where et.entryId=$id", vars={'id':one.entry_id})
        #comments = db.query("SELECT * FROM comments c WHERE c.entryId=$id", vars={'id': entry[0].entry_id})
        #if len(comments) > 0:
        #    d['comments'] = comments
        f = commentForm()
        entry = self.get_entry(slug)
        if entry:
            # select the previous and next entry of current entry.
            #preEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                         max(id) FROM entries WHERE id < %d)' % int(entry.id)))
            # preEntry is a tuple.
            preEntry = web.ctx.orm.query(Entry).filter(
                Entry.id < entry.id).order_by("entries.id desc").all()
            #print preEntry[0][1].id, preEntry[0][1].slug
            nextEntry = web.ctx.orm.query(Entry).filter(
                Entry.id > entry.id).order_by(Entry.id).all()
            #print nextEntry[0][1].id, nextEntry[0][1].title, entry.id
            #nextEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                          min(id) FROM entries WHERE id > %d)' % int(entry.id)))
            # update the viewNum
            entry.viewNum = entry.viewNum + 1
            #db.query('UPDATE entries SET viewNum = viewNum + 1 WHERE id=%d' % int(entry.id))
            #preEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            #posEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            d['entry'] = entry
            if preEntry:
                d['preEntry'] = preEntry[0]
            else:
                d['preEntry'] = None

            if nextEntry:
                #d['nextEntry'] = nextEntry[0][1]
                d['nextEntry'] = nextEntry[0]
            else:
                d['nextEntry'] = None
            d['f'] = f
            return render.entry(**d)
        else:
            return render.pageNotFound(**d)
Example #9
0
    def GET(self, slug):
        #entry = list(db.select('entries', where="slug=$slug", vars={'slug': slug}))
        #entry = list(db.query("select en.id AS entryId, en.title AS entry_title, en.slug AS entry_slug, en.content AS entry_content, en.createdTime AS entry_created_time, c.name AS entry_category, en.commentNum from entries en LEFT JOIN categories c ON en.categoryId = c.id where en.slug=$slug", vars={'slug': slug}))
        #entry[0].tags = db.query("select * from tags t LEFT JOIN entry_tag et ON t.id = et.tagId WHERE et.entryId = $id", vars={'id': entry[0].entry_id})
        ##for one in entry:
        ##    one.tags = db.query("select * from tags t left join entry_tag et on et.tagId=t.id where et.entryId=$id", vars={'id':one.entry_id})
        #comments = db.query("SELECT * FROM comments c WHERE c.entryId=$id", vars={'id': entry[0].entry_id})
        #if len(comments) > 0:
        #    d['comments'] = comments
        f = commentForm()
        entry = self.get_entry(slug)
        if entry:
            # select the previous and next entry of current entry.
            #preEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                         max(id) FROM entries WHERE id < %d)' % int(entry.id)))
            # preEntry is a tuple.
            preEntry = web.ctx.orm.query(Entry).filter(Entry.id < entry.id).order_by("entries.id desc").all()
            #print preEntry[0][1].id, preEntry[0][1].slug
            nextEntry = web.ctx.orm.query(Entry).filter(Entry.id > entry.id).order_by(Entry.id).all()
            #print nextEntry[0][1].id, nextEntry[0][1].title, entry.id
            #nextEntry = list(db.query('SELECT slug FROM entries WHERE id = (SELECT \
            #                          min(id) FROM entries WHERE id > %d)' % int(entry.id)))
            # update the viewNum
            entry.viewNum = entry.viewNum + 1
            #db.query('UPDATE entries SET viewNum = viewNum + 1 WHERE id=%d' % int(entry.id))
            #preEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            #posEntry = db.select('entries', what='slug', where='id=%d' % (int(entry.id) + 1))
            d['entry'] = entry
            if preEntry:
                d['preEntry'] = preEntry[0]
            else:
                d['preEntry'] = None

            if nextEntry:
                #d['nextEntry'] = nextEntry[0][1]
                d['nextEntry'] = nextEntry[0]
            else:
                d['nextEntry'] = None
            d['f'] = f
            return render.entry(**d)
        else:
            return render.pageNotFound(**d)