コード例 #1
0
ファイル: views.py プロジェクト: CulturePlex/moocng
def complaints(request):
    if request.method == 'POST':
        form = ComplaintsForm(request.POST)
        if form.is_valid():
            communication_type = form.cleaned_data['communication_type']
            subject = "%s | %s <%s>" % (communication_type.title(),
                                        form.cleaned_data['username'],
                                        form.cleaned_data['sender'])
            message = form.cleaned_data['message']
            mail_admins(subject, message)
            return HttpResponseRedirect('/complaints/sent')
    else:
        if request.user.is_authenticated():
            full_name = request.user.get_full_name()
            if full_name:
                name = "%s (%s)" % (request.user.username, full_name)
            else:
                name = request.user.username
            message = _("In relation to my course:")
            for course in request.user.courses_as_student.all():
                message = "%s\n- %s" % (message, course.name)
            initial = {
                "username": name,
                "sender": request.user.email,
                "message": message,
            }
        else:
            initial = {}
        form = ComplaintsForm(initial=initial)

    return render(request, 'complaints.html', {
        'form': form,
    })
コード例 #2
0
def complaints(request):
    if request.method == 'POST':
        form = ComplaintsForm(request.POST)
        if form.is_valid():
            communication_type = form.cleaned_data['communication_type']
            subject = "%s | %s <%s>" % (communication_type.title(),
                                        form.cleaned_data['username'],
                                        form.cleaned_data['sender'])
            message = form.cleaned_data['message']
            mail_admins(subject, message)
            return HttpResponseRedirect('/complaints/sent')
    else:
        if request.user.is_authenticated():
            full_name = request.user.get_full_name()
            if full_name:
                name = "%s (%s)" % (request.user.username, full_name)
            else:
                name = request.user.username
            message = _("In relation to my course:")
            for course in request.user.courses_as_student.all():
                message = "%s\n- %s" % (message, course.name)
            initial = {
                "username": name,
                "sender": request.user.email,
                "message": message,
            }
        else:
            initial = {}
        form = ComplaintsForm(initial=initial)

    return render(request, 'complaints.html', {
        'form': form,
    })
コード例 #3
0
ファイル: views.py プロジェクト: abdoullahi/moocng
def complaints(request):
    if request.method == 'POST':
        form = ComplaintsForm(request.POST)
        if form.is_valid():
            subject = "%s | %s" % (form.cleaned_data['communication_type'], form.cleaned_data['username'])
            message = form.cleaned_data['message']
            mail_admins(subject, message)
            return HttpResponseRedirect('/complaints/sent')
    else:
        form = ComplaintsForm()

    return render(request, 'complaints.html', {
        'form': form,
    })