コード例 #1
0
ファイル: views.py プロジェクト: DrewDos/forum
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})
コード例 #2
0
ファイル: __init__.py プロジェクト: nikillpop/imageboard
def new_thread():
    """
    POST API endpoint for creating new threads.
    """

    form = NewThreadForm()
    if form.validate_on_submit():

        data = form.data.copy()
        poster = Poster.from_details(data.pop('name'))
        t = poster.create_thread(**data)
        return redirect(url_for('thread', thread_id=t.id))

    else:
        flash_form_errors(form)
        return redirect(url_for('index'))
コード例 #3
0
ファイル: __init__.py プロジェクト: nikillpop/imageboard
def index():
    """
    Index, showing a "NewThreadForm" and a
    list of all existing threads.

    """
    return render_template('index.html',
                           form=NewThreadForm(),
                           threads=Thread.query.join(Post)\
                                    .order_by(Post.time_created.desc()).all())
コード例 #4
0
ファイル: views.py プロジェクト: katajakasa/Raidcal
def forum(request):
    t = 1

    # Validate new thread form
    if request.method == 'POST':
        thread_form = NewThreadForm(request.POST)
        if thread_form.is_valid():
            topic, message = thread_form.save(user=request.user)
            return HttpResponseRedirect(u'{}#msg_{}'.format(reverse('thread', args=[topic.pk]), message.pk))
    else:
        thread_form = NewThreadForm()

    # Topic page
    pg = request.GET.get('t')
    if pg and len(pg) > 0:
        t = pg[0]

    # Get topics and messages, set correct paging amount
    topics = Paginator(Topic.objects.order_by('-id'), 10)
    messages = Message.objects.order_by('-id')[:8]

    # Get topics page
    try:
        topics_page = topics.page(t)
    except PageNotAnInteger:
        topics_page = topics.page(1)
    except EmptyPage:
        topics_page = topics.page(topics.num_pages)

    return render_to_response('maincal/forum.html', {
        'page': 'forum',
        'topics': topics,
        'topics_page': topics_page,
        'messages': messages,
        'thread_form': thread_form,
    }, context_instance=RequestContext(request))