Exemplo n.º 1
0
 def test_14(self, m='Deleted post should be deleted'):
     p = Post({"title": "Another original post", "contents":"This is the content", "tags":"music,guitar,test", "author":"*****@*****.**"})
     p.validate()
     p.save()
     retrieved_post = Post.get(p.pk())
     retrieved_post.delete()
     retrieved_post.is_deleted() |should| equal_to(True)
     Post.get(p.pk()) |should| equal_to(None)
Exemplo n.º 2
0
 def test_12(self, m="Post should be retrieved by it's pk"):
     p = Post({"title": "This is the second test", "contents":"This is the content", "tags":"music,guitar,test", "author":"*****@*****.**"})
     p.validate()
     p.is_new() |should| equal_to(True)
     p.save()
     p.is_new() |should_not| equal_to(True)
     retrieved_post = Post.get(p.pk())
     retrieved_post |should| equal_to(p)
     retrieved_post.is_new() |should| equal_to(False)
Exemplo n.º 3
0
 def edit(self, id=None, **kvals):
     post = Post.get(id)
     if len(kvals):
         post.update(kvals)
         post.validate()
         if post.is_valid():
             post.save()
             return self.redirect("/post/%s" % post.pk())
     return self.render("post/edit", post=post)
Exemplo n.º 4
0
def addURL():
    if not session["logged_in"]:
        return redirect(url_for("index"))
        
    if request.method == 'POST':
        url = request.form['url']
        post = Post(session["username"])
        count = len(post.get(user_id=session["user_id"]).all())

        if count < post.limit:
            status = post.add(url)
    
    return status
Exemplo n.º 5
0
	def save_from_form(self, save_status, save=True):
		"""
		Updates a post based on form values and notifies ping services
		if it is the first publication of the post
		"""
		do_notification = False
		
		tags = []
		for tag in self.params.get('tags', "").split(','):
			tags.append(tag.strip())
		
		if self.params.get('key'):
			# update if we have an id
			p = Post.get(self.params.get('key'))
			if save and p.status <> 'Published' and save_status == 'Published':
				do_notification = True
			p.content = self.params.get('content', None)
			p.title = self.params.get('title', None)
			p.status = save_status
			p.slug = self.params.get('slug', None)
			p.tags = tags
		else:
			# else we insert
			p = Post(
				content = self.params.get('content', None),
				title = self.params.get('title', None),
				status = save_status,
				slug = self.params.get('slug', None),
				tags = tags
			)
			if save and save_status == 'Published':
				do_notification = True
		if save:
			p.put()
			archive = 'archive_' + str(p.posted_on.year) + str(p.posted_on.month) + str(p.posted_on.day)
			ptitle = str(p.posted_on.year).rjust(2, '0') + str(p.posted_on.month).rjust(2, '0') + str(p.posted_on.day).rjust(2, '0') + '/' + p.slug
			self.invalidate_cache(['blog_last10', archive, ptitle])
		
		do_notification = False
		if do_notification:
			from external.notification import ping_all
			name = 'AlephNullPlex'
			base = 'http://alephnullplex.appspot.com/blog/'
			perm = base + 'view/' +  str(p.posted_on.year) + str(p.posted_on.month) + str(p.posted_on.day)+ '/' + p.slug
			feed = base + 'rss'
			errors = ping_all(name, base, perm, feed, '')
			if errors:
				self.error = '<br />'.join(errors)
		return p
Exemplo n.º 6
0
	def post(self):
		p = Post.get(self.params['post_key'])
		spam = self.params.get('spam_breaker', None)
		if not spam or spam.lower().find("purple") == -1:
			self.redirect('/blog/view/%s/%s' % (p.posted_on.strftime("%Y%m%d"), p.slug))
			return
			
		c = Comment(post=p,
					author=self.params['author'],
					email=self.params.get('email', None),
					url=self.params.get('url', None),
					content=self.params['comment'])
		c.put()
		mailer.new_comment(p, c)
		self.redirect('/blog/view/%s/%s' % (p.posted_on.strftime("%Y%m%d"), p.slug))
Exemplo n.º 7
0
def index():
    page = 'index.html'
    msg = request.args.get("msg")
    
    try:
        if session['logged_in']:
            page = 'manage.html'
            db = records.Database('sqlite:///{}'.format(dbname))
            
            post = Post(session["username"])
            limit = post.limit
            posts = post.get(user_id=session['user_id'])

            disableAddBtn = False
            if len(posts.all()) >= limit:
                disableAddBtn = True

            return render_template(page, posts=posts, disableAddBtn=disableAddBtn)
    except:
        pass

    return render_template(page)
Exemplo n.º 8
0
	def edit(self):
		self.require_admin()
		try:
			self.post = Post.get(self.params['id'])
		except KeyError:
			self.post = None
Exemplo n.º 9
0
def detail(blog_id):
    blog = Post.get(blog_id)
    return render_template('detail.html', blog=blog)
Exemplo n.º 10
0
 def default(self, post_id):
     post = Post.get(post_id)
     return self.render("/post/default", post=post)