当前位置: 首页>>代码示例>>Python>>正文


Python Post.save方法代码示例

本文整理汇总了Python中models.Post.save方法的典型用法代码示例。如果您正苦于以下问题:Python Post.save方法的具体用法?Python Post.save怎么用?Python Post.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Post的用法示例。


在下文中一共展示了Post.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_new

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def post_new():
    p = Post(request.form)
    p.save()
    # print('post_new: ', p)
    cid = p.channel_id
    # print('Post_new channel_id', cid)
    return redirect(url_for('channel_view', id=cid))
开发者ID:zjryan,项目名称:Forum-Gua,代码行数:9,代码来源:app.py

示例2: new_thread

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def new_thread(request, directory_id):



    form = NewThreadForm(request.POST)


    if request.method == 'POST':

        if form.is_valid():

           title = form.cleaned_data['title']
           body = form.cleaned_data['body']


           directory = Directory.objects.get(pk=directory_id)

           new_thread = Thread(name=title, creator=request.user, directory=directory)
           new_thread.save()

           new_post = Post(body=body, creator=request.user, index=1, thread=new_thread)

           #new_thread.latest_post_ref = new_post

           new_post.save()

           new_thread.directory = directory
           new_thread.latest_post = new_post
           new_thread.post_count = 1
           new_thread.save()

           return HttpResponseRedirect(reverse('main:view_thread', args=[new_thread.pk]))


    return render(request, 'main/new_thread.html', {'form': form, 'directory_id': directory_id})
开发者ID:DrewDos,项目名称:forum,代码行数:37,代码来源:views.py

示例3: sub_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def sub_post(request, id_num): #for nested posts
    pform = PostForm(request.POST or None)
    parent = get_object_or_404(Post, pk=id_num)
    if (request.method == 'POST'
        and request.user.is_authenticated()):
        if pform.is_valid():
            title = pform.cleaned_data["title"]
            check = Post.objects.filter(title=title).order_by("-identifier")
            check_int = 0
            if len(check) > 0:
                check_int = check[0].identifier + 1
            post = Post(title=title,
                        body=pform.cleaned_data["body"],
                        parent=parent,
                        user=request.user,
                        identifier=check_int)
            post.save()
            messages.success(request, "Post submitted correctly")
        else:
        ### meaningful errors here would be helpful
        ### messages.error(request, pform.errors)
            return render_to_response("post_form.html",
                    {'pform' : pform, 'post':parent},
                    RequestContext(request))
    return HttpResponseRedirect("/posts/"+id_num)
开发者ID:NSkelsey,项目名称:cvf,代码行数:27,代码来源:views.py

示例4: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def post(request, slug):
    """Adds a post to the chat identified by the given slug.  Also
    updates the current user's latest ping time, reflecting activity
    in this chat.

    This view will handle either normal POSTs or POSTs via Ajax (in
    which case it returns a JSON response with the timestamp of the
    created post and the post's HTML-escaped content."""
    chat = get_object_or_404(Chat, slug=slug)
    if request.POST:
        content = request.POST.get('content', '')
        post = Post(user=request.user, parent=chat, content=content)
        post.save()

        # Update the user's last ping value to reflect active
        # participation in this chat.
        user_ping(request.user)

        # If we're processing an Ajax request, return the timestamp of
        # the post we just created and its HTML-escaped content in
        # JSON format.
        if request.is_ajax():
            response = json.dumps({
                'timestamp': post.timestamp(),
                'content': force_escape(post.content),
            })
            return HttpResponse(response, mimetype='application/json')

    # Redirect the user back to this chat's page for normal, non-Ajax
    # requests.
    return HttpResponseRedirect(chat.get_absolute_url())
开发者ID:mccutchen,项目名称:watercooler,代码行数:33,代码来源:views.py

示例5: test_comment_approved

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
 def test_comment_approved(self):
     post = Post(author=self.me, title="Hi", created_date=timezone.now())
     post.save()
     comment = Comment(author=self.me.username, post=post)
     comment.approve()
     comment.save()
     assert comment in post.approved_comments()
开发者ID:bananayana,项目名称:blog-igi,代码行数:9,代码来源:tests.py

示例6: t070_Post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
	def t070_Post(self):
		"""articoli"""
		L.i("PostTestData load start")
		nu = len( self.users)
		ns = len( self.sectors)
		if not nu:
			L.w("No user to use to load user post :-) ")
			return False
		if not ns:
			L.w("No sectors available")
			return False
		c = 0
		for el in TestData.listPost:
			ref = list( [ x.key() for x in self.listOf( self.links, 4) ])
			L.i("    Dataloaded #{0}".format(c)); c+=1;
			L.i(ref);
			post = Post( 
				title = el['title'], 
				tags = ["tag1", "tags2", "tag3"], 
				sector = list( [x.key() for x in self.listOf( self.sectors,2 )] ),
				date = self.parseDate(el['date']),
				image = list( [ x.key() for x in self.listOf( self.images, 2)]), 
				body = unicode(el['body']),
				author = random.choice(self.users), 
				repositoryLink = list( [x.key() for x in self.links]), 
				reference = ref
 			)
			post.save()
		L.i("PostTestData load ended")
		return True
开发者ID:ozw1z5rd,项目名称:gdg-pescara,代码行数:32,代码来源:code.py

示例7: tweet_data

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def tweet_data(tweet):
	if "RT @" not in tweet['text']:
		try:
			print( '@%s tweeted: %s\nFavorites: %d  Retweets: %d' %\
			( tweet['user']['screen_name'], tweet['text'],tweet['favorite_count'],\
			tweet['retweet_count'] ))
			post = Post()	
			post.title = tweet['text']
			print post.title
			post.posted_by = tweet['user']['screen_name']
			print post.posted_by
			post.date_time = tweet["created_at"].replace(" +0000","")
			print post.date_time
			post.retweets = tweet['retweet_count']
			print post.retweets
			post.favorites=tweet['favorite_count']
			print post.favorites
			post.ups=None
			print post.ups
			post.from_twitter = True
			print post.from_twitter
			post.post_link = "http://www.twitter.com/"+str(tweet['user']['screen_name'])+"/status/"+str(tweet['id'])
			print post.post_link
			post.link=regex_tweet_link(tweet)
			print post.link
			post.save()
			return post
		except:
			print "saving failed!"
			import sys
			print sys.exc_info()
开发者ID:koheif2,项目名称:twitterreddit,代码行数:33,代码来源:views.py

示例8: publications

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def publications(request):
    if request.method == 'POST':
       # save new post
       title = request.POST['title']
       authors = request.POST['authors']
       publisher = request.POST['publisher']
       papertype = request.POST['papertype']
       page_num = request.POST['page_num']
       additional_info = request.POST['additional_info']
#       selectedpublication = request.POST['selectedpublication']
       str_date_published = request.POST['date_published']

       post = Post(title=title)
#       post.date_published = datetime.datetime.now() 
       post.date_published = datetime.fromtimestamp(mktime(time.strptime(str_date_published, "%b %d %Y")))
       post.authors = authors
       post.papertype = papertype
       post.page_num = page_num
       post.additional_info = additional_info
       post.publisher = publisher
       if request.POST.get('selectedpublication', True):
           post.selectedpublication = True;
       post.save()

    # Get all posts from DB
    posts = Post.objects

    return render_to_response('admin/publications.html', {'Posts': posts},
                              context_instance=RequestContext(request))                              
开发者ID:micadeyeye,项目名称:Blongo,代码行数:31,代码来源:views.py

示例9: save

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
 def save(self):
     topic_post = False
     if not self.topic:
         topic_type = self.cleaned_data["topic_type"]
         if topic_type:
             topic_type = TopicType.objects.get(id=topic_type)
         else:
             topic_type = None
         topic = Topic(
             forum=self.forum,
             posted_by=self.user,
             subject=self.cleaned_data["subject"],
             need_replay=self.cleaned_data["need_replay"],
             need_reply_attachments=self.cleaned_data["need_reply_attachments"],
             topic_type=topic_type,
         )
         topic_post = True
         topic.save()
     else:
         topic = self.topic
     post = Post(
         topic=topic,
         posted_by=self.user,
         poster_ip=self.ip,
         message=self.cleaned_data["message"],
         topic_post=topic_post,
     )
     post.save()
     if topic_post:
         topic.post = post
         topic.save()
     attachments = self.cleaned_data["attachments"]
     post.update_attachments(attachments)
     return post
开发者ID:alexliyu,项目名称:mobilesystem,代码行数:36,代码来源:forms.py

示例10: convert_posts

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [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()
开发者ID:bmelton,项目名称:briskforum,代码行数:37,代码来源:convert_from_smf.py

示例11: test_parse_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
    def test_parse_post(self):
        response = '''{"comments": {"can_post": 0, "count": 4},
                 "date": 1298365200,
                 "from_id": 55555,
                 "geo": {"coordinates": "55.6745689498 37.8724562529",
                  "place": {"city": "Moskovskaya oblast",
                   "country": "Russian Federation",
                   "title": "Shosseynaya ulitsa, Moskovskaya oblast"},
                  "type": "point"},
                 "id": 465,
                 "likes": {"can_like": 1, "can_publish": 1, "count": 10, "user_likes": 0},
                 "online": 1,
                 "post_source": {"type": "api"},
                 "reply_count": 0,
                 "reposts": {"count": 3, "user_reposted": 0},
                 "text": "qwerty",
                 "to_id": 201164356}
            '''
        instance = Post()
        owner = UserFactory(remote_id=201164356)  # Travis Djangov
        author = UserFactory(remote_id=55555)
        instance.parse(json.loads(response))
        instance.save()

        self.assertTrue(instance.remote_id.startswith('201164356_'))
        self.assertEqual(instance.wall_owner, owner)
        self.assertEqual(instance.author, author)
        self.assertEqual(instance.reply_count, 0)
        self.assertEqual(instance.likes, 10)
        self.assertEqual(instance.reposts, 3)
        self.assertEqual(instance.comments, 4)
        self.assertEqual(instance.text, 'qwerty')
        self.assertTrue(isinstance(instance.date, datetime))
开发者ID:Core2Duo,项目名称:django-vkontakte-wall,代码行数:35,代码来源:tests.py

示例12: post_form_operator

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def post_form_operator(action, form, request, post_id = 0):
    if action == 'add':
        post = Post(user = request.user)
        post.isdraft = True
        post.text_raw = post.text_html = ''
        post.tags_raw = form.cleaned_data['tags'].lower()
        post.title = form.cleaned_data['title']
        post.save()
            
    if action == 'edit':
        post = Post.objects.get(id__exact = post_id)
        post.updated = datetime.now()
        post.tags_raw = form.cleaned_data['tags'].lower()
        post.title = form.cleaned_data['title']
    
    post.text_raw = form.cleaned_data['text']
    post.text_html = parse_text(post.text_raw, post.id)    
    
    post.tags = form.cleaned_data['tags'].lower()
    post.save()
    
    if action == 'edit':
        messages.success(request,'Changes Saved')
        return
    else:
        messages.success(request,'Saved in Drafts')
        return post
开发者ID:r-ss,项目名称:shffl,代码行数:29,代码来源:views.py

示例13: upload_file_combined

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def upload_file_combined():
	form = UploadForm()
	if request.method == 'POST':
		file = request.files['file']
		if file and allowed_file(file.filename):
			filename = secure_filename(file.filename)
			hash = hashlib.md5()
			hash.update(filename);
			global counter
			new_filename = str(hash.hexdigest()[14:]) + '_' + str(random.random()*100) + str(counter)
			hash.update(new_filename)
			counter = counter + 1
			filename = hash.hexdigest()[20:] + '_' + filename
			hashstring = str(hash.hexdigest()[20:])
			path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
			print path
			file.save(path)
			url = url_for('uploaded_file', filename=filename)
			post = Post()
			post.title = form.title.data
			post.slug = hashstring
			post.geoLong = form.geoLong.data
			post.geoLat = form.geoLat.data
			post.image_url = url
			post.save()
			return redirect("/all-list")
开发者ID:rzlee,项目名称:moments-backend,代码行数:28,代码来源:views.py

示例14: save

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
    def save(self):
        topic_post = False
        if not self.topic:
            topic_type = self.cleaned_data['topic_type']
            if topic_type:
                topic_type = TopicType.objects.get(id=topic_type)
            else:
                topic_type = None

            self.qvod_address = self.cleaned_data['qvod_address']

            topic = Topic(forum=self.forum,
                          posted_by=self.user,
                          subject=self.cleaned_data['subject'],
                          need_replay=self.cleaned_data['need_replay'],
                          need_reply_attachments=self.cleaned_data['need_reply_attachments'],
                          topic_type=topic_type,
                          qvod_address=self.qvod_address,
                          has_qvod = has_qvod
                          )
            topic_post = True
            topic.save()
        else:
            topic = self.topic
        post = Post(topic=topic, posted_by=self.user, poster_ip=self.ip,
                    message=self.cleaned_data['message'], topic_post=topic_post)
        post.save()
        if topic_post:
            topic.post = post
            topic.save()
        attachments = self.cleaned_data['attachments']
        post.update_attachments(attachments)
        return post
开发者ID:daigong,项目名称:DForum,代码行数:35,代码来源:forms.py

示例15: add_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import save [as 别名]
def add_post(request):
    if request.method == "POST":
        post_form = PostForm(request.POST, request.FILES)
        if post_form.is_valid():
            title = post_form.cleaned_data['title']
            keywords = post_form.cleaned_data['keywords']
            description = post_form.cleaned_data['description']
            image = post_form.cleaned_data['image']
            text = post_form.cleaned_data['text']
            slug = title

            new_post = Post(title=title,
                                userid=request.user,
                                slug=slug,
                                keywords=keywords,
                                image=image,
                                text=text,
                                description=description,
                                date=datetime.now())
            new_post.save()
            post_form = PostForm()
            return render(request,
                              'blog/add_post.html',
                              {'post_form': post_form})

    else:
        post_form = PostForm()
    ctx = {'post_form': post_form}
    return render(request,
                  'blog/add_post.html',
                  ctx, )
开发者ID:gokhanciplak,项目名称:deneme,代码行数:33,代码来源:views.py


注:本文中的models.Post.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。