def create_blog_post(title, blurb, content):

    published = datetime.now() + timedelta(days=-random.randint(1, 50))
    p = BlogPost(title=title, blurb=blurb, content=content, published=published)
    p.put()

    for i in range(0, random.randint(0, 5)):
        random_comment(p)
Exemple #2
0
    def test_label(self):
        for feed_item in None, {}:
            bp = BlogPost(id='x', feed_item=feed_item)
            bp.put()
            self.assertEqual('BlogPost x [no url]', bp.label())

        bp = BlogPost(id='x', feed_item={'permalinkUrl': 'http://perma/link'})
        bp.put()
        self.assertEqual('BlogPost x http://perma/link', bp.label())
Exemple #3
0
  def test_label(self):
    for feed_item in None, {}:
      bp = BlogPost(id='x')
      bp.put()
      self.assertEquals('BlogPost x [no url]', bp.label())

    bp = BlogPost(id='x', feed_item={'permalinkUrl': 'http://perma/link'})
    bp.put()
    self.assertEquals('BlogPost x http://perma/link', bp.label())
Exemple #4
0
  def submitApost(self):
      returnedTags=[]
 
      def Tagupdate (tag):
          #logging.info(self.tags.filter('tag',tag).count())
          if  tag!="" and self.tags.filter('tag',tag).count()==0:#tag does not exist
              return(Tag(tag=tag).put())
          else:
              return(self.tags.filter('tag',tag)[0].key())#otherwise find its key
          
      posttagkeys=[]
     
      if not self.tags:#Tags are empty therefore insert new tags
          posttagkeys=[Tag(tag=tag).put() for tag in self.posttags  if tag!=""]
      elif self.posttags[0]!="": posttagkeys=map(Tagupdate ,self.posttags)
      for key in posttagkeys:
          obj=db.get(key)
          returnedTags.append({"tag":obj.tag,"tagid":obj.key().id()})  
      catnames=[]
      catkeys=[]
      if self.categories:   #categories exist make list of them 
          [catnames.append(catobj.category) for catobj in self.categories]
          [catkeys.append(catobj.key()) for catobj in self.categories]
          catobjs=dict(zip(catnames,catkeys))
          if  self.postcategory in catobjs.keys():catkey=catobjs[self.postcategory]
          else:#this post has a new category
              newcatobj=Category()
              newcatobj.category=self.postcategory 
              newcatobj.put()
              catkey=newcatobj.key()
      else:
          newcatobj=Category()
          newcatobj.category=self.postcategory
          newcatobj.put()
          catkey=newcatobj.key()
   
            
      
      post=BlogPost()
      post.title=self.title
      post.body=self.body
      post.tags=posttagkeys
      post.category=catkey
      post.put()
     
      self.deleteMemcache(self)
      self.refetch(self)
      return(post.key(),returnedTags)
Exemple #5
0
    def post(self):
        subject = self.request.get("subject")
        content = self.request.get("content")
        uid = self.get_user_id()

        if self.user:
            if subject and content:
                new_post = BlogPost(subject=subject,
                                    content=content,
                                    author=uid)
                new_post.put()
                new_id = new_post.key().id()
                self.redirect('/blog/' + str(new_id))
            else:
                error = "Please enter a subject and blog content"
                self.render("newpost.html", error=error)
        else:
            self.redirect("/login")
Exemple #6
0
    def post(self):
        params = {}

        subject = self.request.get("subject")
        blog_content = self.request.get("blog_content").replace('\n', '<br/>')

        params['subject'] = subject
        params['blog_content'] = blog_content

        if subject and blog_content:
            b = BlogPost(subject=subject,
                         blog_content=blog_content,
                         author=self.user.username,
                         likes=0)
            b.put()
            self.redirect('/post/{0}'.format(b.key().id()))
        else:
            params['error'] = "subject and content, please!"
            self.render_new_post(**params)
Exemple #7
0
def make_post():
    loaded_message = request.get_json()

    body = loaded_message["body"]
    title = loaded_message["title"]

    the_time = datetime.datetime.now()
    fixed_time = the_time.strftime("%B %d, %Y")
    author = "*****@*****.**"

    insert_payload = BlogPost(
        time=fixed_time,
        body=body,
        title=title,
        author=author,
    )

    insert_payload.put()
    return jsonify(success=True)
Exemple #8
0
def db_build():
    """ Convert all markdown file in ./data/blog into
        html and put them in the datastore.
    """
    
    # turn on code fencing...and pyshell
    md = markdown2.Markdown(extras=['fenced-code-blocks', 'pyshell'])

    # grab all markdown files and convert them to html
    for filename in get_files_of_type('md', './data/blog'):

        with open(filename, 'r') as f:
            md_text = f.read()
            html = md.convert(md_text)
            title = os.path.basename(filename).rsplit('.', 1)[0].lower()

            post = BlogPost(title=title, markdown=md_text, html=html)
            post.put()

            logging.info("Putting blogpost '{}' into datastore...".format(title))
Exemple #9
0
 def post(self):
     name = self.request.get('name')
     user = users.get_current_user()
     if name:
         prof = Profile(
             name=name,
             user=user
         )
         prof.put()
     category_link = self.request.get('category')
     category = Category.all().filter('link = ', category_link).get()
     p = BlogPost(
         title=self.request.get('title'),
         body=self.request.get('body'),
         category=category
     )
     p.teaser = self.makeTeaser(p.body)
     user_name, prof_id = self.getUserNameAndID(user)
     p.author_name = user_name
     p.put()
     self.redirect('/')
Exemple #10
0
    def post(self):
        subject = self.request.get("subject")
        content = self.request.get("content")

        # check if both subject and content exist
        if not (subject and content):
            error = "Please enter both subject and content."
            self.render("newpost.html",
                        error=error,
                        subject=subject,
                        content=content)
        else:
            user = self.validate_user()
            # redirect to login if cookie wrong
            if not user:
                return self.redirect("/blog/login")
            # create BlogPost instance for current user
            blog = BlogPost(subject=subject, content=content, user=user)
            blog.put()  # insert into db
            id = blog.key().id()
            self.redirect("/blog/" + str(id))  # redirect to permalink
Exemple #11
0
 def post(self):
     subject = self.request.get("subject")
     content = self.request.get("content")
     if subject and content:
         newpost = BlogPost(subject=subject, content=content)
         key = newpost.put()
         memcache.set("front_page", None)
         self.redirect("/unit3/blog/%s" % key.id())
     else:
         self.write(
             blog_post_form,
             {"subject": subject, "content": content, "error": "Both subject and content are required."},
         )