Ejemplo n.º 1
0
    def comment(self, id, cancel=False, **data):
        link = self.data.get(id)
        if not link:
            raise cherrypy.NotFound()
        if cherrypy.request.method == 'POST':
            if cancel:
                raise cherrypy.HTTPRedirect('/info/%s' % link.id)
            form = CommentForm()
            try:
                data = form.to_python(data)
                markup = HTML(data['content']) | HTMLSanitizer()
                data['content'] = markup.render('xhtml')
                comment = link.add_comment(**data)
                if not ajax.is_xhr():
                    raise cherrypy.HTTPRedirect('/info/%s' % link.id)
                return template.render('_comment.html',
                                       comment=comment,
                                       num=len(link.comments))
            except Invalid as e:
                errors = e.unpack_errors()
        else:
            errors = {}

        if ajax.is_xhr():
            stream = template.render('_form.html', link=link, errors=errors)
        else:
            stream = template.render(link=link, comment=None, errors=errors)
        return stream | HTMLFormFiller(data=data)
Ejemplo n.º 2
0
 def feed(self, id=None):
     if id:
         link = self.data.get(id)
         if not link:
             raise cherrypy.NotFound()
         return template.render('info.xml', link=link)
     else:
         links = sorted(self.data.values(), key=operator.attrgetter('time'))
         return template.render(links=links)
Ejemplo n.º 3
0
 def feed(self, id=None):
     if id:
         link = self.data.get(id)
         if not link:
             raise cherrypy.NotFound()
         return template.render('info.xml', link=link)
     else:
         links = sorted(self.data.values(), key=operator.attrgetter('time'))
         return template.render(links=links)
Ejemplo n.º 4
0
    def submit(self, cancel=False, **data):
        if cherrypy.request.method == 'POST':
            if cancel:
                raise cherrypy.HTTPRedirect('/')
            form = LinkForm()
            try:
                data = form.to_python(data)
                link = Link(**data)
                self.data[link.id] = link
                raise cherrypy.HTTPRedirect('/')
            except Invalid as e:
                errors = e.unpack_errors()
        else:
            errors = {}

        return template.render(errors=errors) | HTMLFormFiller(data=data)
Ejemplo n.º 5
0
 def comment(self, id, cancel=False, **data):
     link = self.data.get(id)
     if not link:
         raise cherrypy.NotFound()
     if cherrypy.request.method == 'POST':
         if cancel:
             raise cherrypy.HTTPRedirect('/info/%s' % link.id)
         form = CommentForm()
         try:
             data = form.to_python(data)
             markup = HTML(data['content']) | HTMLSanitizer()
             data['content'] = markup.render('xhtml')
             comment = link.add_comment(**data)
             if not ajax.is_xhr():
                 raise cherrypy.HTTPRedirect('/info/%s' % link.id)
             return template.render('_comment.html', comment=comment,
                                    num=len(link.comments))
         except Invalid, e:
             errors = e.unpack_errors()
Ejemplo n.º 6
0
 def info(self, id):
     link = self.data.get(id)
     if not link:
         raise cherrypy.NotFound()
     return template.render(link=link)
Ejemplo n.º 7
0
 def index(self):
     links = sorted(self.data.values(), key=operator.attrgetter('time'))
     return template.render(links=links)
Ejemplo n.º 8
0
    def submit(self, cancel=False, **data):
        if cherrypy.request.method == 'POST':
            if cancel:
                raise cherrypy.HTTPRedirect('/')
            form = LinkForm()
            try:
                data = form.to_python(data)
                link = Link(**data)
                self.data[link.id] = link
                raise cherrypy.HTTPRedirect('/')
            except Invalid, e:
                errors = e.unpack_errors()
        else:
            errors = {}

        return template.render(errors=errors) | HTMLFormFiller(data=data)

    @cherrypy.expose
    @template.output('info.html')
    def info(self, id):
        link = self.data.get(id)
        if not link:
            raise cherrypy.NotFound()
        return template.render(link=link)

    @cherrypy.expose
    @template.output('comment.html')
    def comment(self, id, cancel=False, **data):
        link = self.data.get(id)
        if not link:
            raise cherrypy.NotFound()
Ejemplo n.º 9
0
 def info(self, id):
     link = self.data.get(id)
     if not link:
         raise cherrypy.NotFound()
     return template.render(link=link)
Ejemplo n.º 10
0
 def index(self):
     links = sorted(self.data.values(), key=operator.attrgetter('time'))
     return template.render(links=links)
Ejemplo n.º 11
0
    def submit(self, cancel=False, **data):
        if cherrypy.request.method == 'POST':
            if cancel:
                raise cherrypy.HTTPRedirect('/')
            form = LinkForm()
            try:
                data = form.to_python(data)
                link = Link(**data)
                self.data[link.id] = link
                raise cherrypy.HTTPRedirect('/')
            except Invalid, e:
                errors = e.unpack_errors()
        else:
            errors = {}

        return template.render(errors=errors) | HTMLFormFiller(data=data)

    @cherrypy.expose
    @template.output('info.html')
    def info(self, id):
        link = self.data.get(id)
        if not link:
            raise cherrypy.NotFound()
        return template.render(link=link)

    @cherrypy.expose
    @template.output('comment.html')
    def comment(self, id, cancel=False, **data):
        link = self.data.get(id)
        if not link:
            raise cherrypy.NotFound()