예제 #1
0
def contact(request):
    if 'username' not in request.session:
        request.session['redirect'] = request.get_full_path()
        return HttpResponse('please signup first ;)')
    if request.method == 'POST':  # If the form has been submitted...
        form = ContactForm(request.POST)  # A form bound to the POST

        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            print form
            post = request.POST
            #print "=======POST======",post;

            # sending the email NOW...
            to = []
            for m in MANAGERS:
                to.append(list(m)[1])

            email = EmailMessage()
            for f in request.FILES.values():
                dest = RESUME_STORE + "/error/" + request.session[
                    'username'] + ".png"
                destination = open(dest, 'wb+')
                for c in f.chunks():
                    destination.write(c)
                destination.close()
                email.attach_file(dest)

            body = post['subject'] + "<BR><BR><BR>\n\n\n"
            body += post['message']
            body += post['url']
            email.from_email = request.session['username'] + '@sicsr.ac.in'
            email.subject = '[Laresumex' + post['messageType'] + ']'
            email.to = to
            email.body = body
            email.send()
            #print email.subject;

            return our_redirect(
                "/common/Thank-you/done")  # Redirect after POST
    else:
        form = ContactForm()  # An unbound form

    #if the form was invalid OR if there wasn't any submission, just display the form.
    t = loader.get_template('common/contact.html')
    c = RequestContext(request, {
        'form': form,
        'ROOT': ROOT,
    })
    return HttpResponse(t.render(c))
예제 #2
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['form'] = ContactForm()
     return context