Exemplo n.º 1
0
    def get(self):
        user = users.get_current_user()
        num_stories = len(Story.query().fetch(keys_only=True)) + 1

        if user:
            story = Story()
            story.user = user.user_id()
            story.title = "Untitled " + str(num_stories)
            story.subtitle = "A new story."
            story.summary = "An awesome story."
            key = model.story.update(story)
            self.redirect("/stories/modify?story_id=" + key.urlsafe())
        else:
            self.redirect("/")

        return
Exemplo n.º 2
0
    def post(self):
        try:
            id = self.request.GET['story_id']
        except:
            id = None

        if not id:
            self.redirect("/error?msg=missing id for modification")
            return

        user = users.get_current_user()
        story = None

        if user:
            # Get story by key
            try:
                story = ndb.Key(urlsafe=id).get()
            except:
                self.redirect("/error?msg=key does not exist")
                return

            story.title = self.request.get("title", "").strip()
            story.subtitle = self.request.get("subtitle", "").strip()
            story.summary = self.request.get("summary", "").strip()

            # Chk
            if len(story.title) < 1:
                self.redirect("/error?msg=Aborted modification: missing title")
                return

            # Chk title
            existing_stories = Story.query(Story.title == story.title)
            if (existing_stories and existing_stories.count() > 0
                    and existing_stories.get() != story):
                self.redirect("/error?msg=Story with title \"" +
                              story.title.encode("ascii", "replace") +
                              "\" already exists.")
                return

            # Save
            story.put()
            self.redirect("/info?msg=Story modified: \"" +
                          story.title.encode("ascii", "replace") +
                          "\"&url=/manage_stories")
        else:
            self.redirect("/")
Exemplo n.º 3
0
    def get(self):
        user = users.get_current_user()

        if user:
            user_name = user.nickname()
            stories = Story.query(
                Story.user == user.user_id()).order(-Story.added)
            access_link = users.create_logout_url("/")

            template_values = {
                "info": AppInfo,
                "user_name": user_name,
                "access_link": access_link,
                "stories": stories
            }

            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(
                jinja.render_template("stories.html", **template_values))
        else:
            self.redirect("/")
            return