def dev_site(): """ Deploys a "hello world" demo site with default settings """ init_db() meta = Meta() # fix up a default user username = u'admin' password = u'password' hash = hash_it(username, password) email = u'*****@*****.**' user = User(username=u'admin', hashedpassword=hash, email=email) user.first_name = u'Joe' user.last_name = u'Schmoe' user.save() # fix up a hello post content = u""" **This** is an example post for the wonderful site of %s. This is a simple dev-post. Ready to be deleted at your leisure. [This](http://example.com/#) is a link. """ % (meta.domain) html_content = markdown(content, extensions) title = u"Hello, World!" post = Post(title=title,content=content, html_content=html_content, author=user) post.slugid = slugidfy() post.slug = slugfy(title) post.published = datetime.datetime.now() post.created = datetime.datetime.now() post.is_published = True post.save()
def index(): meta = Meta() posts = Post.objects() # posts = Post.live() users = User.objects() images = Image.objects() return dict(meta=meta, users=users, posts=posts, images=images)
def post_by_slugid(slugid, slug=None, year=None, month=None, day=None): meta = Meta() try: post = Post.objects(slugid=slugid).get() except: return abort(404) if slug == None or year == None or month == None or day == None: return redirect( url_for( "post_by_slugid", slugid=slugid, slug=post.slug, year=post.created.year, month=post.created.month, day=post.created.day, ) ) post["created"] = datetime.datetime.strftime(post.created, "%y-%m-%d @ %H:%m") updated = [] if post.updated: for date in post.updated: updated.append(datetime.datetime.strftime(date, "%y-%m-%d @ %H:%m")) post["updated"] = updated showedit = True return render_template("text_post.html", meta=meta, text_post=post, showedit=showedit)
def delete_post(slugid): try: asset = Post.objects(slugid=slugid).get() except: error(404) try: slugid = asset.slugid title = asset.title asset.delete() flash("Post '%s'. With slugid '%s' was deleted." % (title, slugid)) except: error(404) return redirect(url_for('admin_index'))
def reset_db(): try: posts = Post.objects() sites = Site.objects() users = User.objects() images = Image.objects() deps = Dependency.objects() flatpages = FlatPage.objects() posts.delete() sites.delete() users.delete() deps.delete() flatpages.delete() return "all images, posts, sites, and users deleted successfully!" except: print "There was an error..."
def atom_feed(): def make_external(url): return urljoin(request.url_root, url) meta = Meta() feed = AtomFeed(u"%s feed" % meta.site, feed_url=request.url, url=request.url_root) posts = Post.live() for post in posts: feed.add( post.title, unicode(post.html_content), content_type="html", author=post.author.username, url=make_external(url_for("post_by_slugid", slugid=post.slugid)), updated=post.updated[0], published=post.created, ) return feed.get_response()
def manage(): flats = FlatPage.objects() posts = Post.objects() images = Image.objects() return dict(posts=posts, images=images, flats=flats)