Esempio n. 1
0
 def response(self):
     if self.request.method == 'POST':
         max_id = max([art['id'] for art in ARTICLES])
         ARTICLES.append(
             {'id': max_id+1,
              'title': self.request.POST['title'],
              'content': self.request.POST['content']
              }
         )
         return Response(status=302, location='/')
     return Response(env.get_template('create.html').render(article=None))
Esempio n. 2
0
    def __iter__(self):
        if self.environ['REQUEST_METHOD'].upper() == 'POST':
            from urlparse import parse_qs
            values = parse_qs(self.environ['wsgi.input'].read())
            max_id = max([art['id'] for art in ARTICLES])
            ARTICLES.append({
                'id': max_id + 1,
                'title': values['title'].pop().decode('utf-8'),
                'content': values['content'].pop().decode('utf-8')
            })
            self.start('302 Found', [('Content-Type', 'text/html'),
                                     ('Location', '/')])
            return

        self.start('200 OK', [('Content-Type', 'text/html')])
        yield env.get_template('create.html').render(article=None)
Esempio n. 3
0
    def __iter__(self):
        if self.environ['REQUEST_METHOD'].upper() == 'POST':
            from urlparse import parse_qs
            values = parse_qs(self.environ['wsgi.input'].read())
            max_id = max([art['id'] for art in ARTICLES])
            ARTICLES.append({
                'id': max_id + 1,
                'title': values['title'].pop(),
                'content': values['content'].pop()
            })
            self.start('302 Found', [('Content-Type', 'text/html'),
                                     ('Location', '/')])
            return

        self.start('200 OK', [('Content-Type', 'text/html')])
        yield '<h1><a href="/">Simple Blog</a> -> CREATE</h1>'
        yield '''
Esempio n. 4
0
    def __iter__(self):
        if self.environ['REQUEST_METHOD'].upper() == 'POST':
            from urlparse import parse_qs
            values = parse_qs(self.environ['wsgi.input'].read())
            max_id = max([art['id'] for art in ARTICLES])
            ARTICLES.append(
                {'id': max_id+1,
                 'title': values['title'].pop().decode('utf-8'),
                 'content': values['content'].pop().decode('utf-8')
                 }
            )
            self.start('302 Found',
                       [('Content-Type', 'text/html'),
                        ('Location', '/')])
            return

        self.start('200 OK', [('Content-Type', 'text/html')])
        yield env.get_template('create.html').render(article=None)
Esempio n. 5
0
    def __iter__(self):
        if self.environ["REQUEST_METHOD"].upper() == "POST":
            from urlparse import parse_qs

            values = parse_qs(self.environ["wsgi.input"].read())
            max_id = max([art["id"] for art in ARTICLES])
            ARTICLES.append(
                {
                    "id": max_id + 1,
                    "title": values["title"].pop().decode("utf-8"),
                    "content": values["content"].pop().decode("utf-8"),
                }
            )
            self.start("302 Found", [("Content-Type", "text/html"), ("Location", "/")])
            return

        self.start("200 OK", [("Content-Type", "text/html")])
        yield env.get_template("create.html").render(article=None)
Esempio n. 6
0
    def __iter__(self):
        if self.environ['REQUEST_METHOD'].upper() == 'POST':
            from urlparse import parse_qs
            values = parse_qs(self.environ['wsgi.input'].read())
            max_id = max([art['id'] for art in ARTICLES])
            ARTICLES.append(
                {'id': max_id+1,
                 'title': values['title'].pop(),
                 'content': values['content'].pop()
                 }
            )
            self.start('302 Found',
                       [('Content-Type', 'text/html'),
                        ('Location', '/')])
            return

        self.start('200 OK', [('Content-Type', 'text/html')])
        yield '<h1><a href="/">Simple Blog</a> -> CREATE</h1>'
        yield '''
Esempio n. 7
0
 def response(self):
     if self.request.method == 'POST':
         submitted = self.request.POST.items()
         try:
             self.get_form().validate(submitted)
         except deform.ValidationFailure as e:
             return Response(
                 env.get_template('create.html').render(form=e.render()))
         max_id = max([art['id'] for art in ARTICLES])
         ARTICLES.append(
             {'id': max_id+1,
              'title': self.request.POST['title'],
              'content': self.request.POST['content']
              }
         )
         self.session = get_session(self.request).pop('csrf')
         return Response(status=302, location='/')
     return Response(env.get_template('create.html')
                     .render(form=self.get_form().render()))
Esempio n. 8
0
 def __iter__(self):
     self.start(
         '302 Found',  # '301 Moved Permanently',
         [('Content-Type', 'text/html'), ('Location', '/')])
     ARTICLES.pop(self.index)
     yield ''
Esempio n. 9
0
 def __iter__(self):
     self.start('302 Found',  # '301 Moved Permanently',
                [('Content-Type', 'text/html'),
                 ('Location', '/')])
     ARTICLES.pop(self.index)
     yield ''
Esempio n. 10
0
 def __iter__(self):
     self.start("302 Found", [("Content-Type", "text/html"), ("Location", "/")])  # '301 Moved Permanently',
     ARTICLES.pop(self.index)
     yield ""
Esempio n. 11
0
 def response(self):
     ARTICLES.pop(self.index)
     return Response(status=302, location='/')
Esempio n. 12
0
 def response(self):
     from webob import Response
     ARTICLES.pop(self.index)
     return Response(status=302, location='/')
Esempio n. 13
0
 def response(self):
     from webob import Response
     ARTICLES.pop(self.index)
     return Response(status=302, location='/')