本文整理汇总了Python中models.Post.text方法的典型用法代码示例。如果您正苦于以下问题:Python Post.text方法的具体用法?Python Post.text怎么用?Python Post.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.text方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_crud_methods
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def test_post_crud_methods(self):
message = 'Test message'
user = UserFactory.create(remote_id=TRAVIS_USER_ID)
mock_post = PostFactory.create(text=message, wall_owner=user)
#create by objects api
post = Post.objects.create(
**PostFactory.get_mock_params_dict(
mock_post, commit_remote=True)
)
self.assertTrue(post.remote_id > 0)
self.assertEqual(post.text, message)
fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
self.assertEqual(fetched_post.text, post.text)
# Update
edited_message = 'Edited message with CRUD'
post = Post.objects.get(id=post.id)
post.text = edited_message
post.save(commit_remote=True)
self.assertEqual(post.text, edited_message)
fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
self.assertEqual(fetched_post.text, edited_message)
# Delete
post.delete()
post1 = Post.objects.get(id=post.id)
self.assertTrue(post1.archived)
fetched_post = Post.remote.fetch(ids=[post.remote_id])
self.assertFalse(fetched_post)
# Restore
post.restore()
post1 = Post.objects.get(id=post.id)
self.assertFalse(post1.archived)
fetched_post = Post.remote.fetch(ids=[post1.remote_id])
self.assertTrue(fetched_post)
post.delete()
# Create with save()
post = Post()
post.__dict__.update(PostFactory.get_mock_params_dict(mock_post))
post.text = message + message
post.save(commit_remote=True)
self.assertTrue(post.remote_id > 0)
self.assertEqual(post.text, message + message)
fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
self.assertEqual(fetched_post.text, post.text)
post.delete()
示例2: test_post_crud_methods
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def test_post_crud_methods(self):
group = GroupFactory(remote_id=GROUP_CRUD_ID)
user = UserFactory(remote_id=USER_AUTHOR_ID)
def assert_local_equal_to_remote(post):
post_remote = Post.remote.fetch(ids=[post.remote_id])[0]
self.assertEqual(post_remote.remote_id, post.remote_id)
self.assertEqual(post_remote.text, post.text)
self.assertEqual(Post.objects.count(), 0)
# create
post = Post(text='Test message', wall_owner=group, author=user, date=datetime.now())
post.save(commit_remote=True)
self.objects_to_delete += [post]
self.assertEqual(Post.objects.count(), 1)
self.assertNotEqual(len(post.remote_id), 0)
assert_local_equal_to_remote(post)
# create by manager
post = Post.objects.create(text='Test message created by manager', wall_owner=group, author=user, date=datetime.now(), commit_remote=True)
self.objects_to_delete += [post]
self.assertEqual(Post.objects.count(), 2)
self.assertNotEqual(len(post.remote_id), 0)
assert_local_equal_to_remote(post)
# create by manager on user's wall
post = Post.objects.create(text='Test message', wall_owner=user, author=user, date=datetime.now(), commit_remote=True)
self.objects_to_delete += [post]
self.assertEqual(Post.objects.count(), 3)
self.assertNotEqual(len(post.remote_id), 0)
assert_local_equal_to_remote(post)
# update
post.text = 'Test message updated'
post.save(commit_remote=True)
self.assertEqual(Post.objects.count(), 3)
assert_local_equal_to_remote(post)
# delete
post.delete(commit_remote=True)
self.assertEqual(Post.objects.count(), 3)
self.assertTrue(post.archived)
self.assertEqual(Post.remote.fetch(ids=[post.remote_id]).count(), 0)
# restore
post.restore(commit_remote=True)
self.assertFalse(post.archived)
self.assertEqual(Post.objects.count(), 3)
assert_local_equal_to_remote(post)
示例3: create_or_update_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def create_or_update_post(post_id, title, text, want_publish):
post = Post()
if post_id != None and post_id > 0:
post = get_post(post_id)
post.title = title
post.text = text
if want_publish and post.online is False:
post.online = True
post.save()
return post
示例4: submit_entry
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def submit_entry():
heekPost = PostRoot(key_name='heek', version=2)
post = Post(parent=heekPost)
post.text = request.form['message'][0:128]
post.datetime = datetime.now()
post.put()
return redirect(url_for('index'))
示例5: save
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def save():
my_form = CreateForm(csrf_enabled=False)
my_post = None
if not my_form.post_id.data and my_form.validate_on_submit():
my_post = Post(my_form.title.data, my_form.text.data)
db.session.add(my_post)
if my_form.post_id.data and my_form.validate_on_submit():
my_post = Post.query.get(my_form.post_id.data)
my_post.title = my_form.title.data
my_post.text = my_form.text.data
db.session.commit()
return redirect(url_for('view', post_id=my_post.post_id))
示例6: add_blog_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def add_blog_post(request):
if request.method == "POST":
post = Post()
post.title = request.POST.get('title')
post.text = request.POST.get('text')
if not post.title or not post.text:
return HttpResponse("400 Bad Request You need to specify a title and message")
post.date = datetime.datetime.now()
post.save()
return json_response(request, 'Success')
else:
return HttpResponse("405 Method Not Allowed")
示例7: new_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def new_post():
if not g.site.domain == g.user:
abort(403)
p = Post()
if request.method == "POST":
reqfile = request.files.get("file")
if reqfile:
f = File()
f.site = g.site.domain
f.name = reqfile.filename
f.content_type = reqfile.mimetype
f.slug, f.content_length = save_file(reqfile, blog.config["UPLOAD_FOLDER"])
f.save()
import datetime
p.site = g.site.domain
p.name = request.form.get("name")
p.created = datetime.datetime.utcnow()
p.year = p.created.year
p.month = p.created.month
p.day = p.created.day
slugs = [
__j.slug
for __j in Post.objects.filter(site=g.site.domain, year=p.year, month=p.month, day=p.day, slug=p.slug)
]
counter = 1
slug = slugify(p.name)
__slug = slug
while __slug in slugs:
counter += 1
__slug = "%s_%d" % (slug, counter)
p.slug = __slug
p.text = request.form.get("text")
if reqfile:
p.image_slug = f.slug
p.save()
return redirect(url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug))
return render_template("edit_post.html", post=p)
示例8: create_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def create_posts():
names = [u"news", u"article", u"interview", u"test", u"review", u"témoignage"]
titles = [
u"voici un super post", u"un article trop cool", u"une bonne idée",
u"nouvel article", u"un petit article", u"regardez ca !", u"petit retour"]
for index in range(12):
post = Post(mode="text")
title = random.choice(titles)
title = LocalizedString(value=title, lang=u"fr")
post.title = title
post.state = "published"
post.publication_date = datetime.datetime.now()
text = generate_lorem_ipsum()
text = LocalizedText(value=text, lang=u"fr")
post.text = text
abstract = generate_lorem_ipsum(n=1, max=60)
abstract = LocalizedText(value=abstract, lang=u"fr")
post.abstract = abstract
db.session.add(post)
db.session.commit()
tags_count = Tag.query.count()
print "tags_count : ", tags_count
tag_id = random.randint(1,tags_count)
print "tag_id : ", tag_id
tag = Tag.query.get(tag_id)
tag.posts.append(post)
db.session.commit()
print post
print tag
示例9: getPosts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def getPosts(blog):
if blog.url.endswith('persianblog.ir'):
url = "http://%s/rss.xml" % (blog.url)
else:
url = "http://%s/rss" % (blog.url)
print "going to parse: ", url
feed = feedparser.parse(url)
for entry in feed.entries:
if postExists(entry['link']):
continue
post = Post()
post.title = entry['title']
post.text = clean_html(entry['description'])
if hasattr(entry, 'published_parsed'):
post.date = datetime.fromtimestamp(mktime(entry['published_parsed']))
elif hasattr(entry, 'updated_parsed'):
post.date = datetime.fromtimestamp(mktime(entry['updated_parsed']))
else:
post.date = datetime.now()
post.url = entry['link']
post.blog = blog
post.save()
return feed
示例10: answer
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def answer(request):
"""Adds an answer from a user to a topic."""
try:
topic_pk = request.GET["sujet"]
except KeyError:
raise Http404
# Retrieve current topic.
g_topic = get_object_or_404(Topic, pk=topic_pk)
if not g_topic.forum.can_read(request.user):
raise PermissionDenied
# Making sure posting is allowed
if g_topic.is_locked:
raise PermissionDenied
# Check that the user isn't spamming
if g_topic.antispam(request.user):
raise PermissionDenied
last_post_pk = g_topic.last_message.pk
# Retrieve 10 last posts of the current topic.
posts = \
Post.objects.filter(topic=g_topic) \
.prefetch_related() \
.order_by("-pubdate"
)[:10]
# User would like preview his post or post a new post on the topic.
if request.method == "POST":
data = request.POST
newpost = last_post_pk != int(data["last_post"])
# Using the « preview button », the « more » button or new post
if "preview" in data or newpost:
form = PostForm(g_topic, request.user, initial={"text": data["text"
]})
form.helper.form_action = reverse("zds.forum.views.answer") \
+ "?sujet=" + str(g_topic.pk)
return render_template("forum/post/new.html", {
"text": data["text"],
"topic": g_topic,
"posts": posts,
"last_post_pk": last_post_pk,
"newpost": newpost,
"form": form,
})
else:
# Saving the message
form = PostForm(g_topic, request.user, request.POST)
if form.is_valid():
data = form.data
post = Post()
post.topic = g_topic
post.author = request.user
post.text = data["text"]
post.text_html = emarkdown(data["text"])
post.pubdate = datetime.now()
post.position = g_topic.get_post_count() + 1
post.ip_address = get_client_ip(request)
post.save()
g_topic.last_message = post
g_topic.save()
#Send mail
subject = "ZDS - Notification : " + g_topic.title
from_email = "Zeste de Savoir <{0}>".format(settings.MAIL_NOREPLY)
followers = g_topic.get_followers_by_email()
for follower in followers:
receiver = follower.user
if receiver == request.user:
continue
pos = post.position - 1
last_read = TopicRead.objects.filter(
topic=g_topic,
post__position=pos,
user=receiver).count()
if last_read > 0:
message_html = get_template('email/notification/new.html') \
.render(
Context({
'username': receiver.username,
'title':g_topic.title,
'url': settings.SITE_URL + post.get_absolute_url(),
'author': request.user.username
})
)
message_txt = get_template('email/notification/new.txt').render(
Context({
'username': receiver.username,
'title':g_topic.title,
'url': settings.SITE_URL + post.get_absolute_url(),
#.........这里部分代码省略.........
示例11: new
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def new(request):
"""Creates a new topic in a forum."""
try:
forum_pk = request.GET["forum"]
except KeyError:
raise Http404
forum = get_object_or_404(Forum, pk=forum_pk)
if not forum.can_read(request.user):
raise PermissionDenied
if request.method == "POST":
# If the client is using the "preview" button
if "preview" in request.POST:
form = TopicForm(initial={"title": request.POST["title"],
"subtitle": request.POST["subtitle"],
"text": request.POST["text"]})
return render_template("forum/topic/new.html",
{"forum": forum,
"form": form,
"text": request.POST["text"]})
form = TopicForm(request.POST)
data = form.data
if form.is_valid():
# Treat title
(tags, title) = get_tag_by_title(data["title"])
# Creating the thread
n_topic = Topic()
n_topic.forum = forum
n_topic.title = title
n_topic.subtitle = data["subtitle"]
n_topic.pubdate = datetime.now()
n_topic.author = request.user
n_topic.save()
# add tags
n_topic.add_tags(tags)
n_topic.save()
# Adding the first message
post = Post()
post.topic = n_topic
post.author = request.user
post.text = data["text"]
post.text_html = emarkdown(request.POST["text"])
post.pubdate = datetime.now()
post.position = 1
post.ip_address = get_client_ip(request)
post.save()
n_topic.last_message = post
n_topic.save()
# Follow the topic
follow(n_topic)
return redirect(n_topic.get_absolute_url())
else:
form = TopicForm()
return render_template("forum/topic/new.html", {"forum": forum, "form": form})
示例12: parse_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import text [as 别名]
def parse_post(self, content, wall_owner):
from models import Post
from vkontakte_users.models import User
remote_id = content['id'][4:]
try:
instance = Post.objects.get(remote_id=remote_id)
except Post.DoesNotExist:
instance = Post(remote_id=remote_id)
post_text = content.find('div', {'class': 'wall_post_text'})
if post_text:
instance.text = post_text.text
# date
instance.date = self.parse_container_date(content)
# likes
instance.likes = self.parse_container_likes(content, 'post_like_count fl_l')
# comments
show_comments = content.find('div', {'class': 'wrh_text'})
if show_comments:
comments_words = show_comments.text.split(' ')
if len(comments_words) in [3,4]:
# Показать все 95 комментариев
# Показать 91 комментарий
instance.comments = int(comments_words[-2])
elif len(comments_words) == 6:
# Показать последние 100 комментариев из 170
instance.comments = int(comments_words[-1])
else:
raise VkontakteParseError("Error number of words in show all comments message: '%s'" % show_comments.text.encode('utf-8'))
else:
instance.comments = len(content.findAll('div', {'class': 'reply_text'}))
# author
owner_slug = content.find('a', {'class': 'author'})['href'][1:]
if wall_owner and wall_owner.screen_name == owner_slug:
instance.author = wall_owner
else:
# author is someone else,
# possible user, becouse the group can post only on it's own wall, where wall_owner is defined
avatar = content.find('a', {'class': 'post_image'}).find('img')['src']
name_parts = content.find('a', {'class': 'author'}).text.split(' ')
user = get_object_by_slug(owner_slug)
if user:
user.first_name = name_parts[0]
if len(name_parts) > 1:
user.last_name = name_parts[1]
user.photo = avatar
user.save()
instance.author = user
instance.fetched = datetime.now()
if wall_owner:
instance.wall_owner = wall_owner
#<td>
# <div class="published_by_title"><a class="published_by" href="/yullz">Yulya Tsareva</a> </div>
# <div class="published_by_date"><a class="published_by_date" href="/wall59124156_8301" onclick="return showWiki({w: 'wall59124156_8301'}, false, event);" >29 янв 2013 в 15:51</a></div>
#</td>
try:
slug = content.find('a', {'class': 'published_by'})['href'][1:]
post_link = content.find('a', {'class': 'published_by_date'})
instance.copy_owner = get_object_by_slug(slug)
instance.copy_post = Post.objects.get_or_create(remote_id=content.find('a', {'class': 'published_by_date'})['href'][5:], defaults={
'wall_owner': instance.copy_owner,
'date': self.parse_date(post_link.text)
})[0]
except:
pass
# <div class="published_comment wall_post_text">дядька молодец</div>
copy_text = content.find('div', {'class': 'published_comment wall_post_text'})
if copy_text:
instance.copy_text = copy_text.text
post_parsed.send(sender=Post, instance=instance, raw_html=str(content))
return instance