Ejemplo n.º 1
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['logout_redirect'] = '/escooters/escooter/{}'.format(self.object.pk)
     checkout_form = CommentCreateForm()
     checkout_form.fields['commented_order'].initial = self.object
     checkout_form.fields['commented_user'].initial = self.request.user
     context['form'] = checkout_form
     escooter_quantity_in_cart(self, context)
     return context
Ejemplo n.º 2
0
def open_classroom(requests,pk):
    classroom = get_object_or_404(Classroom,pk = pk)
    topics = classroom.topic_set.all()
    contents = []
    for topic in topics:
        contents.extend(list(topic.post_set.all()))
        contents.extend(list(topic.assignment_set.all()))
    
    contents.sort(key = lambda x: x.created_at)

    post_form = PostForm()
    comment_form = CommentCreateForm()

    context = {
        'classroom' : classroom,
        'contents': reversed(contents),
        'post_form': post_form,
        'comment_form': comment_form,
    }

    return render(requests, 'classroom/classroom.html', context)
Ejemplo n.º 3
0
def create(request, section, id, slug):
    post = id
    form = CommentCreateForm()

    if request.method == 'POST':
        form = CommentCreateForm(request.POST, request.FILES)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.post = post
            comment.save()
            return redirect(comment)

    return render(request, 'comments/create.html', dict(
        post=post,
        form=form,
    ))
Ejemplo n.º 4
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['comment_form'] = CommentCreateForm(self.request.POST or None)
     return context
Ejemplo n.º 5
0
def render_comments_create(context):
    return {
        'request': context['request'],
        'form': CommentCreateForm(auto_id='id_comment_%s')
    }
Ejemplo n.º 6
0
def comments_create(post):
    return dict(
        post=post,
        form=CommentCreateForm(),
    )