Beispiel #1
0
def blog(blog_id):
    current_blog = Blog.query.get_or_404(blog_id)
    tags = get_tags(current_blog.tag)
    return render_template('blog.html',
                           subject=current_blog.subject,
                           blog=current_blog,
                           tags=tags,
                           comments=current_blog.comment)
Beispiel #2
0
def user_blogs(username):
    user = User.query.filter_by(username=username).first_or_404()
    blogs = user.blogs
    all_tags = [get_tags(blog.tag) for blog in blogs]
    blogs_and_tags = zip(blogs, all_tags)
    # print(blogs)
    return render_template('user_blogs.html',
                           blogs=user.blogs,
                           user=user,
                           blogs_and_tags=blogs_and_tags)
Beispiel #3
0
def users_who_posted_at_least_two_blogs_with_different_tags():
    users = User.query.all()
    # print(users)

    users_with_two_or_more_blogs = []
    for user in users:
        if len(Blog.query.filter_by(user_id=user.id).all()) > 1:
            users_with_two_or_more_blogs.append(user)
    # print(users_with_two_or_more_blogs)

    # Now I need to check the tags and see if the any tags in one blog are in the other tags
    for user in users_with_two_or_more_blogs:
        # getting all the blogs for a user
        blogs = Blog.query.filter_by(user_id=user.id)

        # then getting all the tags strings from all the blogs from that user in a list
        all_tags = []
        for blog in blogs:
            all_tags.append(get_tags(blog.tag))

        verified_users_who_posted_at_least_two_blogs_with_different_tags = []
        found = False
        # going through all tags strings
        for i, tagstring in enumerate(all_tags):
            # splitting
            tags = tagstring.split()
            for tag in tags:
                for j, other_tagstrings in enumerate(all_tags):
                    if i == j:
                        continue
                    else:
                        if tag in other_tagstrings:
                            break
                        else:
                            verified_users_who_posted_at_least_two_blogs_with_different_tags.append(
                                user)
                            found = True
                            break
                if found:
                    break
            if found:
                break

    return render_template(
        'users.html',
        users=verified_users_who_posted_at_least_two_blogs_with_different_tags,
        blogs=[])
Beispiel #4
0
def update_blog(blog_id):
    blog = Blog.query.get_or_404(blog_id)
    if blog.bloggedBy != current_user:
        abort(403)
    form = BlogForm()
    if form.validate_on_submit():
        blog.subject = form.subject.data
        blog.description = form.description.data
        blog.tag = [Tag(tag=tag) for tag in form.tags.data.split()]
        db.session.commit()
        flash('Your blog has been updated!', 'success')
        return redirect(url_for('blogs.blog', blog_id=blog.blog_id))
    elif request.method == 'GET':
        form.subject.data = blog.subject
        tags = get_tags(blog.tag)
        form.tags.data = tags
        form.description.data = blog.description
    return render_template('create_blog.html',
                           title='Update Blog',
                           form=form,
                           legend='Update Blog')