コード例 #1
0
ファイル: views.py プロジェクト: od-5/safari
def groups_detail(request, slug):
    try:
        setup = Setup.objects.all()[0]
    except:
        setup = None
    group_qs = Groups.objects.get(slug=slug)

    if request.method == "POST":
        comment_form = GroupsCommentForm(request.POST)
        if comment_form.is_valid():
            new_review = comment_form.save()
            new_review.save()
            return HttpResponseRedirect(request.path)
    else:
        if request.user.is_authenticated():
            comment_form = GroupsCommentForm(
                initial={
                    'user': request.user,
                    'groups': group_qs}
            )
        else:
            comment_form = GroupsCommentForm()

    return render(request, 'groups/groups_detail.html', {
        'setup': setup,
        'group': group_qs,
        'comment_form': comment_form,
    })
コード例 #2
0
ファイル: views.py プロジェクト: od-5/enjoy-africa
def groups_detail(request, slug):
    try:
        setup = Setup.objects.all()[0]
    except:
        setup = None
    group_qs = get_object_or_404(Groups, slug=slug)
    if group_qs.travel_start > date.today():
        actual_tour = True
    else:
        actual_tour = False

    if request.method == "POST":
        comment_form = GroupsCommentForm(request.POST)
        if comment_form.is_valid():
            new_review = comment_form.save()
            new_review.save()
            return HttpResponseRedirect(request.path)
    else:
        if request.user.is_authenticated():
            comment_form = GroupsCommentForm(
                initial={
                    'user': request.user,
                    'groups': group_qs}
            )
        else:
            comment_form = GroupsCommentForm()

    return render(request, 'groups/groups_detail.html', {
        'setup': setup,
        'group': group_qs,
        'comment_form': comment_form,
        'actual_tour': actual_tour
    })