本文整理汇总了Python中models.post.Post类的典型用法代码示例。如果您正苦于以下问题:Python Post类的具体用法?Python Post怎么用?Python Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: new_post
def new_post(self, title, content, date=datetime.datetime.utcnow()):
post = Post(blog_id=self._id,
title=title,
content=content,
author=self.author,
created_date=date)
post.save_to_mongo()
开发者ID:marciodasilva,项目名称:blogsite,代码行数:7,代码来源:blog.py
示例2: post
def post(self, authorized, fields):
"""
Endpoint for creating new Posts
"""
post = Post(**fields)
# Fetch location name if not present and valid lat lon exists
if post.location_lon is not None and post.location_lat is not None and post.location_name is None:
post._fetch_friendly_location()
# Save post
result = _save_post(post, 201)
# Check if the post was saved OK
if result[1] != 201:
return result
# Tweet if public post
if post.public:
try:
tweet = post_post_as_tweet(post)
except Exception as e:
return result
post.tweet_id = tweet.id_str
# Over-write result to new save of tweet_id
result = _save_post(post, 201)
return result
开发者ID:davidhariri,项目名称:api,代码行数:30,代码来源:posts.py
示例3: get_old_post
def get_old_post(self, today):
#Lets try to put in an old post...
old_post = None
old_type = ''
#First try a year ago...
if today.day == 29 and today.month == 2:
old_post = None
else:
year_ago = datetime.date(today.year-1, today.month, today.day)
old_post = Post.query(Post.date == year_ago).get()
old_type = 'year'
if not old_post:
#lets try a month ago...
last_day_of_last_month = datetime.date(today.year, today.month, 1) + datetime.timedelta(days=-1)
if last_day_of_last_month.day >= today.day:
month_ago = datetime.date(last_day_of_last_month.year, last_day_of_last_month.month, today.day)
old_post = Post.query(Post.date == month_ago).get()
old_type = 'month'
if not old_post:
week_ago = today + datetime.timedelta(days=-7)
old_post = Post.query(Post.date == week_ago).get()
old_type = 'week'
if not old_post:
return None, None
else:
return old_post, old_type
开发者ID:vojnovski,项目名称:MyLife,代码行数:30,代码来源:dailymail.py
示例4: get
def get(self):
settings = Settings.get() #Force email address update...
posts = Post.query().order(-Post.date).fetch(1)
is_newest = True
if posts:
post = posts[0]
is_oldest = post.date == Post.min_date()
else:
post = None
is_oldest = True
#See if this is the very first time we've been here. In that case
#send an email immediately to get people started...
first_time = False
if not Slug.query().get() and not Post.query().get():
first_time = True
DailyMail().send(True)
self.response.write(get_template('frontpage.html').render(
{
"page":"frontpage",
"post":post,
"is_oldest" : is_oldest,
"is_newest" : is_newest,
"first_time" : first_time,
"email" : settings.email_address
}))
开发者ID:einaregilsson,项目名称:MyLife,代码行数:29,代码来源:frontpage.py
示例5: new_post
def new_post(self, title, content, date=datetime.datetime.utcnow()):
''' create new post inside blog model'''
post = Post(blogId=self._id,
title=title,
content=content,
createdDate=date,
author=self.author)
post.save_to_mongo()
开发者ID:tuannvm,项目名称:flask,代码行数:8,代码来源:blog.py
示例6: new_post
def new_post(self):
title = input("Enter post title: ")
content = input("Enter post content: ")
post = Post(blog_id=self.id,
title=title,
content=content,
author=self.author,
date=datetime.datetime.utcnow())
post.save_to_db()
开发者ID:kggiorno,项目名称:pythonLearnPublic,代码行数:9,代码来源:blog.py
示例7: post
def post(self):
title = self.get_argument("title", None)
content = self.get_argument("content", None)
#post = PostService.add(title, content)
ps = Post()
ps.title = title
ps.content = content
ps.save()
self.write('good')
开发者ID:CanGuangZeng,项目名称:tornado_test,代码行数:9,代码来源:index.py
示例8: create_test_anon_post
def create_test_anon_post(**kwargs):
user = kwargs['user']
group = kwargs['group']
post = Post('content', 1)
post.group_id = group.id
post.user_id = user.id
db.session.add(post)
db.session.commit()
return post
开发者ID:rafagonc,项目名称:share,代码行数:9,代码来源:helper.py
示例9: new_post
def new_post(self):
title = input("Enter post title:")
content = input("Enter content:")
date = datetime.datetime.utcnow()
post = Post(author=self.author,
blog_id=self.id,
content=content,
title=title,
created_date=date)
post.save_to_mongo()
开发者ID:LifeOnAFarm,项目名称:command-line-blog,代码行数:10,代码来源:blog.py
示例10: get
def get(self):
burger_string = self.fetch_burger_string()
if(burger_string != ''):
post = Post(content=burger_string)
post.put()
logging.info("UpdateHandler::get() - Created new post with id: %s",
post.key().id())
else:
logging.error('UpdateHandler::get() - fetch_burger_string()' +
'returned an empty string, no post created')
开发者ID:polym0rph,项目名称:TastyBurger,代码行数:11,代码来源:update.py
示例11: post
def post(self):
subject = self.request.get('subject')
content = self.request.get('content')
if subject and content:
b = Post(parent=blog_key(), subject=subject, content=content,
author=self.user.name)
b.put()
self.redirect('/blog/%s' % str(b.key().id()))
else:
error = "We need both a subject and some content"
self.render_front(subject, content, error)
开发者ID:pribala,项目名称:udacity_projects,代码行数:11,代码来源:newpost.py
示例12: get_single_post
def get_single_post(post_id=None, via_comment=None):
if post_id is not None:
post = Post.get_by_id(post_id)
else:
post_id = via_comment.post.id()
post = Post.get_by_id(post_id)
try:
content = (post, map(lambda x: x.voter_id, post.voters))
except AttributeError:
abort(404)
return content
开发者ID:Roasbeef,项目名称:FlaskrNews,代码行数:12,代码来源:api.py
示例13: create_new_post
def create_new_post(blog_id):
if request.method == 'GET':
return render_template('new_post.html', blog_id=blog_id)
else:
title = request.form['title']
content = request.form['content']
user = User.get_by_email(session['email'])
new_post = Post(blog_id, title, content, user.email)
new_post.save_to_mongo()
return make_response(blog_posts(blog_id))
开发者ID:asimonia,项目名称:web-blog,代码行数:12,代码来源:app.py
示例14: create
def create(parameters):
parameters["body"] = parameters["body"].replace("\n", "<br>")
user = current_user(parameters)
if user:
parameters.update({"author_id": user.id})
new_post = Post(Post.cxn, "posts", parameters)
new_post.save()
parameters.update({"id": str(new_post.id)})
return show(parameters)
else:
page = "<html><head></head><body><h2>{0}</h2>{1}</body></html>".format("You must be logged in to submit a new post", "<a href='/'><em>(home)</em></a>")
return page
开发者ID:zackmdavis,项目名称:Wires,代码行数:12,代码来源:posts_controller.py
示例15: post
def post(self):
subject = self.request.get('subject')
content = self.request.get('content')
if subject and content:
post = Post(subject = subject, content = content)
post.put()
post_id = str(post.key().id())
self.redirect('/%s' % post_id)
else:
error = 'You should write both subject and content.'
self.render_form(subject, content, error)
开发者ID:m-education,项目名称:google-app-engine-blog,代码行数:13,代码来源:newpost_handler.py
示例16: new_post
def new_post(self):
title = input("Enter post title: ")
content = input("Enter post content: ")
date = input("Enter post date, or leave blank for today (in format DDMMYYYY): ")
if date == "":
date = datetime.datetime.utcnow()
else:
date = datetime.datetime.strptime(date, "%d%m%Y")
post = Post(blog_id=self.id,
title=title,
content=content,
author=self.author,
date=date)
post.save_to_mongo()
开发者ID:asimonia,项目名称:mongo-blog,代码行数:14,代码来源:blog.py
示例17: test_kind
def test_kind(db_conn, posts_table):
"""
Expect a post to have a kind.
"""
post = Post({
'user_id': 'A',
'topic_id': 'B',
'body': 'C',
})
del post['kind']
post, errors = post.save()
assert len(errors) == 1
post['kind'] = 'post'
post, errors = post.save()
assert len(errors) == 0
开发者ID:Folashade,项目名称:sagefy,代码行数:16,代码来源:test_models_post.py
示例18: post
def post(self):
"""Handles post request to store the blog post information into database"""
title = self.request.get("subject")
content = self.request.get("content")
if self.authenticated():
if title and content:
a = Post(title = title, content = content, author = self.user)
a.put()
self.redirect("/blog/%s" % (a.key().id()))
else:
error = "Both title and art needed for submitting !"
self.render("new.html",subject = title, content = content, error = error)
else:
# if the user is not autheticated it redirects to login page
self.login_redirect()
开发者ID:harikrish00,项目名称:blogit,代码行数:16,代码来源:new_post.py
示例19: generate_posts_json
def generate_posts_json(update = False):
mc_key = "JSON_POSTS"
news_dict, age = age_get(mc_key)
if update or news_dict is None:
q = Post.all().order('-pubDate')
posts = list(q.fetch(limit=20))
news_dict = dict()
for newstype in urllist:
news_dict[newstype] = []
news_dict["carousel_posts"] = []
for p in posts:
news_dict[p.newstype].append({
"TITLE":p.title,
"DESCRIPTION":p.description,
"PUBDATE":p.pubDate.isoformat(),
"LINK":p.link,
"IMAGE":p.image,
"SRC":p.src,
"NEWSTYPE":p.newstype #remove later
})
carousel_posts = list(q.filter('srckey IN', [1, 6, 10]).fetch(limit=6))
for p in carousel_posts:
news_dict["carousel_posts"].append({
"TITLE":p.title,
"DESCRIPTION":p.description,
"PUBDATE":p.pubDate.strftime("%X, %x"),
"LINK":p.link,
"IMAGE":p.image,
"SRC":p.src,
"NEWSTYPE":p.newstype #remove later
})
news_dict = json.dumps(news_dict)
age_set(mc_key, news_dict)
logging.info("DB QUERY!!")
return news_dict, age
开发者ID:mehmettekn,项目名称:news_parser,代码行数:35,代码来源:news.py
示例20: get
def get(self, post_id):
post = Post.get_by_id(int(post_id))
if post:
self.render('post.html', post = post)
else:
self.error(404)
开发者ID:m-education,项目名称:google-app-engine-blog,代码行数:7,代码来源:post_handler.py
注:本文中的models.post.Post类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论