Пример #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))
Пример #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)
Пример #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 '''
Пример #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)
Пример #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)
Пример #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 '''
Пример #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()))
Пример #8
0
 def __iter__(self):
     self.start(
         '302 Found',  # '301 Moved Permanently',
         [('Content-Type', 'text/html'), ('Location', '/')])
     ARTICLES.pop(self.index)
     yield ''
Пример #9
0
 def __iter__(self):
     self.start('302 Found',  # '301 Moved Permanently',
                [('Content-Type', 'text/html'),
                 ('Location', '/')])
     ARTICLES.pop(self.index)
     yield ''
Пример #10
0
 def __iter__(self):
     self.start("302 Found", [("Content-Type", "text/html"), ("Location", "/")])  # '301 Moved Permanently',
     ARTICLES.pop(self.index)
     yield ""
Пример #11
0
 def response(self):
     ARTICLES.pop(self.index)
     return Response(status=302, location='/')
Пример #12
0
 def response(self):
     from webob import Response
     ARTICLES.pop(self.index)
     return Response(status=302, location='/')
Пример #13
0
 def response(self):
     from webob import Response
     ARTICLES.pop(self.index)
     return Response(status=302, location='/')