def complete(request,id): from django.core.mail import send_mail entry = Comment.objects.get(pk=id) if entry.isDeleted or entry.completed: # no double completes! nor completing deleted things. return HttpResponseRedirect(reverse('requests.views.completed',current_app='requests')) if request.method == 'POST': form = ModifyForm(request.POST) if form.is_valid(): if len(form.cleaned_data['completingServer']) > 0: try: entry.completed = True entry.completingName = form.cleaned_data['completingName'] if len(form.cleaned_data['completingServer']) > 1: entry.completingServer = form.cleaned_data['completingServer'].upper().replace('\\','') else: entry.completingServer = request.META['HTTP_X_FORWARDED_FOR'] entry.completerComment = form.cleaned_data['completerComment'] entry.completedTime = datetime.now() entry.save() recipients = ['*****@*****.**'] if entry.email: recipients += [entry.email] message = "From %(host)s:\n\n%(completercomment)s\n\nEnjoy!\n\n This is an automated message; please do not reply to this address" % {'host':entry.completingServer,'completercomment':entry.completerComment} send_mail('Request Completed!', message, '*****@*****.**', recipients, ) test = 3 return HttpResponseRedirect(reverse('requests.views.completed',current_app='requests')) except Exception,e: form.non_field_errors = e test = 2 else: test = 1