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


Python Post.author方法代码示例

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


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

示例1: create

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [as 别名]
def create():
    form = RegistrationForm()
    if form.validate() is False:
        return render_template('blog/new.html', form=form)
    else:
        post = Post()
        post.title = form.title.data
        post.author = form.author.data
        post.text_content = form.text_content.data
        post.text_call = form.text_call.data
        post.postage_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        post.active = 0

        subjects_names = form.subject.data.replace(', ', ',').split(',')

        for name in subjects_names:
            subject = Subject.query.filter_by(name=name).first()
            if (not subject):
                subject = Subject()
                subject.name = name
            post.subjects.append(subject)
        db.session.add(post)

        db.session.flush()
        if len(form.thumb.data.split(',')) > 1:
            upload_folder = os.path.join(app.config['UPLOAD_FOLDER'], mod.name, str(post.id), 'images')
            post.thumb = save_b64_image(form.thumb.data.split(',')[1], upload_folder, 'thumb')

        db.session.commit()

        message = u'Muito obrigado! Seu post foi submetido com sucesso!'
        flash(message, 'success')
        return redirect(url_for('blog.admin'))
开发者ID:aromeira,项目名称:dataviva-site,代码行数:35,代码来源:views.py

示例2: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [as 别名]
 def post(self):
     p = Post()
     p.author = users.get_current_user()
     p.content = self.request.get('content')
     p.title = self.request.get('title')
     if self.request.get('is_published', None):
         p.is_published = True
     p.put()
     self.redirect('/admin/blog')
开发者ID:mdwrigh2,项目名称:cthaeh,代码行数:11,代码来源:admin_blog.py

示例3: add_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [as 别名]
def add_post(request):
    post_content = request.POST['post_content']
    post_topic = Topic.objects.get(id=request.POST['topic_id'])
    newPost = Post()
    newPost.author = request.user
    newPost.content = post_content
    newPost.topic = post_topic
    newPost.save()
    return redirect('topic-detail', topic_id=post_topic.id)
开发者ID:jakegny,项目名称:UdemyClasses,代码行数:11,代码来源:views.py

示例4: sign

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [as 别名]
def sign(request):
  form = GuestbookForm(request.POST)
  if form.is_valid():
    post = Post(message=form.clean_data['message'])
    if users.GetCurrentUser():
      post.author = users.GetCurrentUser()
  
    post.put()

  return HttpResponseRedirect('/')
开发者ID:liseryang,项目名称:openbotlist,代码行数:12,代码来源:views.py

示例5: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [as 别名]
 def post(self):
     post = Post()
     post.author = User.get_by_id(self.session['user'].email)
     assert author
     post.commit = self.request.get('commit')
     post.image = self.get_uploads('image')[0].key()
     post.share = bool(self.get('share', False))
     post.put()
     
     self.JsonResponse({"STATUS": "SUCCESS"})
开发者ID:georgefs,项目名称:ezselector,代码行数:12,代码来源:views.py

示例6: home

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [as 别名]
def home(request):
    user = request.user
    if user.is_authenticated():
        if request.method == "POST":
            post = Post()
            post.post_title = request.POST['title']
            post.post_body = request.POST['body']
            post.post_time = timezone.now()
            post.author = request.user
            post.save()
            return redirect('/home')

        user_id     = user.id
        post_list = Post.objects.all().order_by('-post_time')
        list = Profile.objects.get(profile_owner= user_id).image.thumbnail
        list_str = str(list)[7:]
        activity = Activity.objects.all().order_by('-activity_date')
        notice = Notice.objects.all()
    return render(request, 'network/home.html', {"posts": post_list, 'user': user, "profile" : list_str, "activities": activity, "notices":notice})
开发者ID:justvidyadhar,项目名称:shannon,代码行数:21,代码来源:views.py

示例7: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [as 别名]
    def post(self, title):
        if self.form.validate():
            post = None

            if self.form.post_id.data:
                post = yield Post.asyncQuery(id=self.form.post_id.data).first()
            if post:
                post.modified_time = datetime.datetime.utcnow()
            else:
                post = Post()
                post.create_time = \
                    self.BeiJing2UTCTime(self.form.create_time.data)

            title = self.form.title.data.replace(' ', '-')
            content = self.form.content.data
            markdown_text = self.form.markdown.data
            tags = self.separate_tags(self.form.tags.data)
            category_str = self.form.category.data.capitalize()
            category = yield Category.asyncQuery(
                name=category_str).first()
            if not category:
                category = Category()
                category.name = category_str
                yield category.save()

            post.title = title
            post.content = content
            post.markdown = markdown_text
            post.category = category
            post.tags = tags
            post.author = self.current_user

            yield post.save()
            self.flash("compose finsh!")
            return self.redirect('/blog')
        self.render("compose.html", form=self.form)
开发者ID:chinakyc,项目名称:blog,代码行数:38,代码来源:blog.py

示例8: answer

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [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(),
#.........这里部分代码省略.........
开发者ID:Aer-o,项目名称:zds-site,代码行数:103,代码来源:views.py

示例9: new

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [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})
开发者ID:Aer-o,项目名称:zds-site,代码行数:66,代码来源:views.py

示例10: parse_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import author [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
开发者ID:akropotov,项目名称:django-vkontakte-wall,代码行数:81,代码来源:parser.py


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