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


Python Post.pubdate方法代码示例

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


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

示例1: add_initial_data

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

示例2: answer

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import pubdate [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

示例3: new

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import pubdate [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

示例4: save_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import pubdate [as 别名]
def save_post(post_id=None):
    """Save Post to database

    If post_id is None a new Post will be inserted in the database. Otherwise
    the existing Post will be updated.
    """
    message = 'Post updated'
    orig_tags = []

    post_form = PostForm(request.form)

    if not post_form.validate():
        flash('ERROR: errors detected. Post NOT saved!', category='error')
        return edit_post(post_id=post_id, post_form=post_form)

    # test if we're creating a new post, or updating an existing one
    if post_id is None:
        post = Post()
        post.status_id = 1
        post.user_id = session['user_id']
        post.createdate = datetime.now()
    else:
        post = get_post(post_id)
        orig_tags = [tag for tag in post.tags]

    post_form.populate_obj(post)
    post.lastmoddate = datetime.now()

    # compile input to html
    post.compile(app.config['REPL_TAGS'])

    # update pubdate if post's pubdate is None and its status is set
    # to public
    if request.form['status'] == 'public' and \
           unicode(post.status) != 'public' and \
           post.pubdate is None:
        post.pubdate = datetime.now()

    post.status = get_status(request.form['status'])

    if post.slug is None:
        post.slug = slugify(post.title)

    if post_id is None:
        db_session.add(post)
        message = 'New post was successfully added'

    db_session.commit()

    for tag in orig_tags:
        recalculate_tagcount(tag)

    for tag in post.tags:
        if tag not in orig_tags:
            recalculate_tagcount(tag)

    db_session.commit()

    flash(message, category='info')

    return redirect(url_for('edit_post', post_id=post.id))
开发者ID:jkossen,项目名称:imposter,代码行数:63,代码来源:admin.py


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