コード例 #1
0
ファイル: main.py プロジェクト: mattbasta/minutegram
    def post(self):
        data = self.request.get("url")
        if not data.startswith("data:"):
            self.error(400)
            return
        data = data[5:]
        try:
            metadata, body = data.split(",")
            if not metadata.startswith("image/png"):
                raise ValueError("Image of wrong MIME type.")

            imagedata = base64.standard_b64decode(body)
            if len(imagedata) > 500000:
                raise ValueError("Image too big.")

            image = images.Image(imagedata)
            image.resize(300, 300 / image.width * 300)

            sub = Submission(submitter=str(self.request.remote_addr) or "")
            sub.image = db.Blob(image.execute_transforms())
            sub.put()

        except ValueError:
            self.error(400)
            return

        self.response.write("{error:false}")
コード例 #2
0
ファイル: submissions.py プロジェクト: tiffanyhan/poetry-blog
    def post(self):
        '''
        creates a new submission instance and inserts it into the db.
        then redirects the user to the blog entry permalink page.
        both subject and content are required to make a blog entry.
        '''
        subject = self.request.get("subject")
        content = self.request.get("content")

        if subject and content:
            submission = Submission(parent=blog_key(),
                                    user=self.user,
                                    subject=subject,
                                    content=content)
            submission.put()
            time.sleep(0.1)

            self.redirect('/%s' % str(submission.key().id()))

        else:
            error = "You must enter both a subject and content"
            self.render("submissions/new.html",
                        subject=subject,
                        content=content,
                        error=error)
コード例 #3
0
ファイル: main.py プロジェクト: inl1ne/fairlight
 def add(self):
     submission = Submission(
         contents=self.request.body,
         mime_type=self.request.content_type,
         submitted_by=users.get_current_user()
     )
     key = submission.put()
     return webapp2.Response(key.urlsafe())