예제 #1
0
def index():
    form = PostForm()
    if current_user.can(Permission.WRITE_ARTICLES) and \
            form.validate_on_submit():
        post = Post(body=form.body.data,
                    author=current_user._get_current_object())
        db.session.add(post)
        return redirect(url_for('.index'))
    page = request.args.get('page', 1, type=int)
    show_followed = False
    if current_user.is_authenticated:
        show_followed = bool(request.cookies.get('show_followed', ''))
    if show_followed:
        query = current_user.followed_posts
    else:
        query = Post.query
    pagination = query.order_by(Post.timestamp.desc()).paginate(
        page,
        per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    return render_template('index.html',
                           form=form,
                           posts=posts,
                           show_followed=show_followed,
                           pagination=pagination)
예제 #2
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        if form.picture.data == None:
            flash("Select any image before submitting!", "danger")
            return redirect("/")
        imgname = save_picture(form.picture.data)
        cols = request.form.get('cols')
        scale = request.form.get('scale')
        if scale == None:
            scale = 0.43
        else:
            scale = float(scale)

        if cols == None:
            cols = 500
        else:
            cols = int(cols)
        
        result = convert_img_to_ascii(imgname, cols, scale)
        os.remove(imgname)
        if result != None:
            return render_template('index.html',form=form, result=result)
        else:
            return redirect("/")
    return render_template('index.html',form=form)
예제 #3
0
def new_post(request):
    if request.method == 'POST':
        post_form = PostForm(request.POST, request.FILES)
        new_postt = post_form.save(commit=False)
        new_postt.user = request.user
        new_postt.save()
        categories = request.POST.getlist("category")
        for cat in categories:
            new_postt.category.add(cat)
        tagss = request.POST.getlist("tag")
        for ta in tagss:
            new_postt.category.add(ta)
        my_tags = request.POST.get("my_tags")
        my_tags = my_tags.strip()
        my_tags = my_tags.split(",")
        for ta_g in my_tags:
            n_t = my_models.Tag.objects.create(name=ta_g)
            n_t.save()
            new_postt.tag.add(n_t)
        return HttpResponseRedirect(('{}?post_id=' + str(new_postt.id)).format(
            reverse('post', kwargs={})))
    else:
        post_form = PostForm()
        return render(request, 'main/new_post.html', {
            'parts': my_models.Part.objects.all(),
            "post_form": post_form,
        })
예제 #4
0
파일: views.py 프로젝트: Pycart/blog-app
def post_admin(request):

    posts = Post.objects.all().order_by('-date_posted')

    context = {"posts": posts}

    if request.method == 'POST':

        id = request.POST.get('id')

        if id:

            post = Post.objects.get(id=id)
            form = PostForm(request.POST, request.FILES, instance=post)

        else:

            form = PostForm(request.POST, request.FILES)

        if form.is_valid():
            post = form.save()
            context['message'] = "Your post has been saved"
        else:
            context['message'] = form.errors

    return render(request, 'post-admin.html', context)
예제 #5
0
def create_post(request):
    form = PostForm(request.POST)
    if form.is_valid():
        post = form.save()
        return redirect('index')
    else:
        message = form.errors
        return render(request, 'index.html', {'message': message})
예제 #6
0
파일: views.py 프로젝트: mosbasik/blog_app
def create_post(request):
    form = PostForm(request.POST, request.FILES)
    if form.is_valid():
        post = form.save()
        message = 'Your post has been saved'
    else:
        message = form.errors

    return render(request, 'post_admin.html', {'message': message})
예제 #7
0
def new_post():
    form = PostForm()

    if form.validate_on_submit():
        post = Post(title = form.title.data, content=form.content.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html', title='New post', form = form, legend= 'New Post')
예제 #8
0
파일: routes.py 프로젝트: ysnacrk/blog
def add_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data, content=form.content.data)
        post.slug_(str(form.title.data))
        db.session.add(post)
        db.session.commit()
        return redirect(url_for('index'))

    return render_template('add_post.html', form=form)
예제 #9
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Blog added to community', 'success')
        return redirect(url_for('home'))
    return render_template('new_post.html', form=form, titlt="NEW BLOG")
예제 #10
0
파일: routes.py 프로젝트: olaborde/Blogz
def newpost():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(
            title=form.title.data,
            content=form.content.data,
            author=current_user)  #use author the backref to grab the user
        db.session.add(post)
        db.session.commit()
        flash('Post submitted successfully', 'success')
        return redirect(url_for('index'))
    return render_template('newpost.html', title='New Post', form=form)
예제 #11
0
파일: views.py 프로젝트: alietac/my-first
def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.published_date = timezone.now()
            post.save()
            return redirect('main.views.post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'main/post_edit.html', {'form': form})
예제 #12
0
def new(request):
    if request.method == 'POST':
        form = PostForm(request.POST, request.FILES, instance=Post.default())
        if form.is_valid():
            post = form.save()
            return redirect(view, post.id)
    else:
        form = PostForm()
    context = RequestContext(request, {
        'form': form
    })
    return render_to_response('new.html', context)
예제 #13
0
파일: views.py 프로젝트: de-v/test
def post_add(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save()
            return redirect('main_page')
    else:
        form = PostForm()
    return render(
        request,
        'post_add.html',
        {'form': form}
    )
예제 #14
0
    def post(self, request):
        form = PostForm(request.POST)
        if form.is_valid():
            topic_id = request.POST.get("topic")
            title = request.POST.get("title")
            body = request.POST.get("body")
            author = request.user

            topic = Topic.objects.get(pk=topic_id)
            Post.objects.create(title=title,
                                author=author,
                                body=body,
                                topic=topic)
            return redirect("topic", name=topic.name)
예제 #15
0
def edit(id):
    post = Post.query.get_or_404(id)
    if current_user != post.author and \
            not current_user.can(Permission.ADMINISTER):
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.body = form.body.data
        db.session.add(post)
        db.session.commit()
        flash('The post has been updated.')
        # print(post.id)
        return redirect(url_for('main.post', id=post.id))
    form.body.data = post.body
    return render_template('edit_post.html', form=form)
예제 #16
0
def edit(id):
    post = Post.query.get_or_404(id)
    if current_user != post.author and \
            not current_user.can(Permission.ADMINISTER):
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.body = form.body.data
        db.session.add(post)
        db.session.commit()
        flash('The post has been updated.')
        # print(post.id)
        return redirect(url_for('main.post', id=post.id))
    form.body.data = post.body
    return render_template('edit_post.html', form=form)
예제 #17
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('post', post_id=post.id))
    elif request.method == 'GET':
        form.title.data = post.title
        form.content.data = post.content
    return render_template('create_post.html', title='Update post', form=form, legend= 'Update Post')
예제 #18
0
파일: tag.py 프로젝트: slashdevsda/Rodolphe
def search(request, pattern):
    tags = TagsSet.from_string(pattern)
    q, search = get_search(request)
    regex = r'(\s|\A)\.{}(\W|\Z)'
    for tag in tags:
        q &= Q(content__iregex=regex.format(re.escape(tag)))
    for tag in tags.iter_exclude():
        q &= ~Q(content__iregex=regex.format(re.escape(tag)))
    paginator = Paginator(
        Post.objects.filter(q, active=True).order_by('-created_at'), 10)
    page_id = request.GET.get('page')
    try:
        posts = paginator.page(page_id)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    context = RequestContext(
        request, {
            'page': posts,
            'form': PostForm(),
            'title': '{} - {}'.format(_('tag'), pattern),
            'search': search
        })
    return render_to_response('index.html', context)
예제 #19
0
파일: views.py 프로젝트: kvsem/K_project
def modify(request):
    user_info = get_user_info(request)

    form = PostForm()
    post_id = request.GET.get('id')
    modified = False

    if request.POST.get('title'):
        now = timezone.now()
        title = request.POST.get('title')
        post_id = request.POST.get('id')
        category = request.POST.get('category')
        context = request.POST.get('context')
        user_id = request.user.id

        Post.objects.filter(id=post_id).update(
            title=title,
            category=category,
            context=context,
            updated_at=now,
        )
        modified = True

    post_info = Post.objects.filter(id=post_id).values().last()

    side_popular_contents_list = get_side_popular_contents()
    side_latest_contents_list = get_side_latest_contents()
    return render(request, 'main/modify.html',
                  dict(form=form, side_popular_contents_list=side_popular_contents_list, side_latest_contents_list=side_latest_contents_list, user_info=user_info, post_info=post_info, modified=modified))
예제 #20
0
파일: views.py 프로젝트: kvsem/K_project
def write(request):
    user_info = get_user_info(request)
    form = PostForm()
    created = False

    if request.POST.get('title'):
        now = timezone.now()
        title = request.POST.get('title')
        category = request.POST.get('category')
        context = request.POST.get('context')
        user_id = request.user.id

        Post.objects.create(
            title=title,
            category=category,
            context=context,
            write_date=now,
            user_id=user_id,
        )

        created = True

    side_popular_contents_list = get_side_popular_contents()
    side_latest_contents_list = get_side_latest_contents()
    return render(request, 'main/write.html',
                  dict(form=form, side_popular_contents_list=side_popular_contents_list, side_latest_contents_list=side_latest_contents_list, user_info=user_info, created=created))
예제 #21
0
파일: routes.py 프로젝트: ysnacrk/blog
def update_post(post_id):
    form = PostForm()
    if request.method == 'GET':
        post = Post.query.get(post_id)
        form.title.data = post.title
        form.content.data = post.content

        return render_template('update.html', form=form)

    elif request.method == 'POST' and form.validate_on_submit():
        post = Post.query.get(post_id)
        post.title = form.title.data
        post.content = form.content.data
        post.slug_(str(form.title.data))
        db.session.commit()
        return redirect(url_for('index'))
예제 #22
0
def view(request, post_id):
    post = get_object_or_404(Post, id=int(post_id), active=True, parent=None)
    if request.method == 'POST':
        form = PostForm(request.POST, request.FILES,
                        instance=Post.default(parent=post))
        if form.is_valid():
            resp = form.save()
            form = PostForm()
            post.last_resp_at = resp.created_at
            post.save()
    else:
        form = PostForm()
    context = RequestContext(request, {
        'post': post,
        'form': form
    })
    return render_to_response('view.html', context)
예제 #23
0
def test_new_ad(client, user):
    client.login(username=user.username, password="******")
    resp_get = client.get("/ad/new")
    assert resp_get.status_code == 200
    data = {"title": "asdasd", "text": "sdefghhgj"}
    assert PostForm(data=data).is_valid()
    resp_post = client.post("/ad/new", data)
    assert resp_post.status_code == 302
예제 #24
0
def update(post_id):

    post = Post.query.get_or_404(post_id)

    if post.author != current_user:
        abort(403)
    form = PostForm()

    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Blog updated successfully', 'success')
        return redirect(url_for('post', post_id=post_id))
    elif request.method == 'GET':
        form.title.data = post.title
        form.content.data = post.content

    return render_template('update_post.html', form=form, post=post)
예제 #25
0
def update_post(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if request.user == post.user:
        ImageFormSet = modelformset_factory(Image, form=ImageForm, max_num=1)
        post_form = PostForm(request.POST or None, instance=post)
        formset = ImageFormSet(request.POST or None,
                               request.FILES or None,
                               queryset=Image.objects.filter(post=post))
        if post_form.is_valid() and formset.is_valid():
            post = post_form.save()

            for form in formset:
                image = form.save(commit=False)
                image.post = post
                image.save()
                return redirect(post.get_absolute_url())
        else:
            return render(request, 'update-post.html', locals())
    else:
        # return HttpResponse('<h1>403 Forbidden<h/1>')
        return render(request, 'update-post.html', locals())
예제 #26
0
def edit(request, post_id):
    post = get_object_or_404(Post, id=int(post_id), active=True)
    if request.method == 'POST':
        form = PostForm(request.POST, request.FILES, instance=post)
        if form.is_valid():
            old = Post.objects.get(id=post.id)
            old.id = None
            old.active = False
            old.save()
            post = form.save(commit=False)
            post.old_post = old
            post.updated_at = timezone.now()
            post.save()
            return redirect(view, post.thread.id)
    else:
        form = PostForm(instance=post)
    context = RequestContext(request, {
        'post': post,
        'form': form
    })
    return render_to_response('edit.html', context)
예제 #27
0
def delete_post(request, pk):
    post_item = get_object_or_404(Post, pk=pk)
    if post_item.author != request.user:
        raise ValidationError(
            'You are not the owner of the post',
            code='error.not.post.owner',
        )
    if request.method == "POST":
        post_item.delete()
        return redirect('user_posts', pk=request.user.id)
    return render(request, 'post_delete.html',
                  {'form': PostForm(instance=post_item)})
예제 #28
0
def page(request):
    paginator = Paginator(
        Post.objects.filter(active=True,
                            parent=None).order_by('-last_resp_at'), 10)
    page_id = request.GET.get('page')
    try:
        posts = paginator.page(page_id)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    context = RequestContext(request, {'page': posts, 'form': PostForm()})
    return render_to_response('index.html', context)
예제 #29
0
def index():
    form = PostForm()
    if current_user.can(Permission.WRITE_ARTICLES) and \
            form.validate_on_submit():
        post = Post(body=form.body.data,
                    author=current_user._get_current_object())
        db.session.add(post)
        return redirect(url_for('.index'))
    page = request.args.get('page', 1, type=int)
    show_followed = False
    if current_user.is_authenticated:
        show_followed = bool(request.cookies.get('show_followed', ''))
    if show_followed:
        query = current_user.followed_posts
    else:
        query = Post.query
    pagination = query.order_by(Post.timestamp.desc()).paginate(
        page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    return render_template('index.html', form=form, posts=posts,
                           show_followed=show_followed, pagination=pagination)
예제 #30
0
def view(request, post_id):
    post = get_object_or_404(Post, id=int(post_id), active=True, parent=None)
    if request.method == 'POST':
        form = PostForm(request.POST,
                        request.FILES,
                        instance=Post.default(parent=post))
        if form.is_valid():
            resp = form.save()
            form = PostForm()
            post.last_resp_at = resp.created_at
            post.save()
    else:
        form = PostForm()
    context = RequestContext(request, {'post': post, 'form': form})
    return render_to_response('view.html', context)
예제 #31
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.post.data,
                    title=form.title.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Blog post successful.')
        return redirect(url_for('index'))
    page = request.args.get('page', 1, type=int)
    posts = current_user.followed_posts().paginate(
        page, blog.config['POSTS_PER_PAGE'], False)
    next_url = url_for('index', page=posts.next_num) \
        if posts.has_next else None
    prev_url = url_for('index', page=posts.prev_num) \
        if posts.has_prev else None
    return render_template('index.html',
                           title='Home',
                           form=form,
                           posts=posts.items,
                           next_url=next_url,
                           prev_url=prev_url)
예제 #32
0
def post_create(request):
    """Route Create Post."""
    errors = ''
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            form.save()
        else:
            errors = "Cannot save the post"
    else:
        form = PostForm()
    context = {"form": form, "errors": errors}
    return render(request, "main/post_create.html", context=context)
예제 #33
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        language = guess_language(form.post.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        post = Post(body=form.post.data, author=current_user,
                    language=language)
        db.session.add(post)
        db.session.commit()
        flash(_('Your post is now live!'))
        return redirect(url_for('main.index'))
    page = request.args.get('page', 1, type=int)
    posts = current_user.followed_posts().paginate(
        page, current_app.config['POSTS_PER_PAGE'], False)    
    comments = Comment.query.order_by(Comment.timestamp.desc()).paginate(
        page, current_app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('main.index', page=posts.next_num) \
        if posts.has_next else None
    prev_url = url_for('main.index', page=posts.prev_num) \
        if posts.has_prev else None
    return render_template("index.html", title='Home', form=form,
                           posts=posts.items, next_url=next_url,
                           prev_url=prev_url, comments=comments.items)
예제 #34
0
def Topic(playlist_id=None, topic=None):
    if current_user.is_authenticated:
        print("Authenticated user")
        try:
            spotify.activate(current_user.access_token)
            me = spotify.active.me(
            )  #without this logout is not working properly. (verification for api access needed here)
        except Exception as e:
            print(e)
            logout_user()

        #try:
        #    spotify.call_playlists(current=0, next=50)
        #    spotify.insert_playlists(me['id'])
        #except Exception as e:
        #    #print(e)
        #    pass
    else:
        print("Non-authenticated user")

    form = PostForm()
    if form.validate_on_submit():
        try:
            spotify.insert_current_playlist(me['id'])
            spotify.insert_songs(spotify.current_playlist['local_id'])
        except:
            pass
        post = Post(title='test',
                    content=form.content.data,
                    user_id=current_user.id,
                    playlist_id=spotify.current_playlist['local_id'])
        db.session.add(post)
        db.session.commit()
        return redirect(
            url_for('Topic', playlist_id=spotify.current_playlist['local_id']))
    return render_template('home.html', form=form)
예제 #35
0
def new(request):
    if request.method == 'POST':
        form = PostForm(request.POST, request.FILES, instance=Post.default())
        if form.is_valid():
            post = form.save()
            return redirect(view, post.id)
    else:
        form = PostForm()
    context = RequestContext(request, {'form': form})
    return render_to_response('new.html', context)
예제 #36
0
파일: views.py 프로젝트: Mendibaev/BFDjango
def index(request):
	latest_post_list = Post.objects.order_by('-created_at')
	if request.method == 'POST':
		form = PostForm(request.POST)
		if form.is_valid():
			form.save()
			return redirect('/blog/')
	else:
		form = PostForm()
	context = {
		'latest_post_list': latest_post_list,
		'form': form
	}
	return render(request, 'main/index.html', context)
예제 #37
0
def post_create(request):
    """Route Create Post."""
    errors = ''
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect("posts_all")
        else:
            errors = "Не возможно сохранить пост."
    else:
        form = PostForm()
    context = {"form": form, "errors": errors}
    return render(request, "main/post_create.html", context=context)
예제 #38
0
def add_post(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post_item = form.save(commit=False)
            post_item.author = request.user
            post_item.save()
            return redirect('post_view', pk=post_item.pk)
    else:
        form = PostForm(instance=Post())
    return render(request, 'post_edit.html', {'form': form, 'action': 'add'})
예제 #39
0
def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.published_date = timezone.now()
            post.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'main/post_edit.html', {'form': form})
예제 #40
0
def post_new(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save()
            post.save()
            messages.info(request, 'Your post is added successfully!')

            return redirect('postlist')
    else:
        form = PostForm()
    return render(request, 'main/create or edit post.html', {'form': form})