本文整理汇总了Python中models.Post.user方法的典型用法代码示例。如果您正苦于以下问题:Python Post.user方法的具体用法?Python Post.user怎么用?Python Post.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.user方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user [as 别名]
def convert_posts(self, board_id=181):
start_time = time.time()
cursor = connection.cursor()
cursor.execute("SELECT * FROM smf_messages WHERE id_board=%d ORDER BY id_msg ASC" % board_id)
rows = cursor.fetchall()
for row in rows:
try:
try:
profile = Profile.objects.get(old_user_id=row[4])
except Profile.DoesNotExist, e:
if not row[4] == 0:
print "Profile does not exist for %s" % (row[4])
profile = None
try:
topic = Topic.objects.get(old_topic_id=row[1])
except Topic.DoesNotExist, e:
print "Topic %s does not exist" % (row[1])
post = Post()
post.topic = topic
post.old_post_id = row[0]
if profile == None:
post.user = None
else:
post.user = profile.user
post.legacy_username= row[7]
post.created = self.fix_epoch(row[3])
post.updated = self.fix_epoch(row[11])
post.subject = row[6]
post.body = self.clean(row[13])
post.body_html = self.markup(self.clean(row[13]))
post.user_ip = row[9]
post.save()
post.topic.save()
示例2: new_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user [as 别名]
def new_post(request, thread, user, result=None):
"""
Handle the new post form data when it gets posted
"""
if not result:
result = Result()
postform = PostForm(request.POST)
result.postform = postform
if not result.captcha_success:
captcha_error = get_captcha_error(request)
if captcha_error:
result.captcha_error = captcha_error
return result
if postform.is_valid():
data = postform.cleaned_data
post = Post(body=data['body'], thread=thread)
#######
if data['spam_prevent']:
# if the spam prevent field is not blank, assume the post was made
# by a spambot
return HttpResponse('plz go away spambot thx')
#######
if not user.is_authenticated() or data['as_anon']:
# anonymously posted messages are annotated with the poster's
# IP address so they can edit them later
post.ip = request.META['REMOTE_ADDR']
post.as_anon = True
else:
#post.ip = "0.0.0.0"
post.user = user
post.as_anon = False
########
if data['as_admin']:
# this post was made by an admin and the post will be displayed
# ina way that lets everyone know that this person is an admin
post.as_admin = True
########
post.save()
result.post = post
return result
示例3: marks
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user [as 别名]
def marks(request):
form = Post()
if request.method == 'POST': # If the form has been submitted...
form.title = request.POST['title']
form.body = request.POST['body']
form.lon = float(request.POST['lon'])
form.lat = float(request.POST['lat'])
form.img = request.FILES.get('file', False)
form.user = request.user
form.save()
return redirect('/')
示例4: add_initial_data
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user [as 别名]
def add_initial_data():
"""Insert initial data into the database"""
# open database session
db_session = DB(db).get_session()
# ask user for an admin username and password
username = raw_input('Please enter the admin username: ')
password = getpass.getpass(prompt='Please enter the admin password: ')
# add user to database
u = User(username, encrypt_password(app.config['SECRET_KEY'], password))
db_session.add(u)
# create statuses
s1 = Status('draft')
s2 = Status('private')
s3 = Status('public')
db_session.add(s1)
db_session.add(s2)
db_session.add(s3)
# create formats
f = Format('rest')
f2 = Format('markdown')
db_session.add(f)
db_session.add(f2)
# Tags
t1 = Tag('imposter')
t2 = Tag('weblog')
# build initial post and put it in the database
initial_post_summary = """
Installed Correctly!
"""
initial_post_content = """
Imposter was installed correctly!
This is just a sample post to show Imposter works.
**Have a lot of fun blogging!**
"""
p1 = Post('Welcome to Imposter!', initial_post_summary, initial_post_content)
p1.slug = slugify(p1.title)
p1.createdate = datetime.now()
p1.lastmoddate = datetime.now()
p1.pubdate = datetime.now()
p1.format = f
p1.status = s3
p1.user = u
p1.tags = [t1, t2]
p1.compile()
db_session.add(p1)
db_session.commit()
示例5: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user [as 别名]
def post(self,user_id):
vals = myweb.get_post_vars()
if (len(vals) == 0):
vals = myweb.get_get_vars()
ret = ""
if len(vals) > 0:
for i in vals:
ret += str(i) + ":" + str(vals[i]) + ", "
apost = Post()
apost.post = ret
apost.user = user_id
apost.put()
示例6: post_add
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user [as 别名]
def post_add():
p = Post(request.get_json())
p.user = current_user()
p.save()
post = p.post_row()
log('post add, dict: ', post)
t = post.get('time', '')
ft = formatted_time(t)
response_data = {
'id': post.get('id', ''),
'link': post.get('link', ''),
'time': ft,
'part_content': post.get('part_content', ''),
'author_link': post.get('author_link', ''),
'is_author': True,
}
return json.dumps(response_data, indent=2)
示例7: post_add
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import user [as 别名]
def post_add():
user = current_user()
if user is None:
return redirect(url_for('login_view'))
else:
p = Post(request.json)
p.user = user
p.save()
# cid = p.channel_id
post = p.post_row()
log('post add, dict: ', post)
response_data = {
'id': post.get('id', ''),
'link': post.get('link', ''),
'time': post.get('time', ''),
'part_content': post.get('part_content', ''),
'author_link': post.get('author_link', ''),
'is_author': True,
}
j = json.dumps(response_data, indent=2)
log('json dumps post: ', j)
return json.dumps(response_data, indent=2)