Exemple #1
0
def sendMail(request, hardwareid):
	hardware = get_object_or_404(Hardware, id=hardwareid)
	user = request.user
	profile = user.get_profile()
	if hardware.owner != user:
		if user.email != "" and profile.mail_confirmed:
			if request.method == "POST":
				form = SendmailForm(request.POST)
				if form.is_valid():
					headers = {'Reply-To':user.email}  # From-header
					from_email = '*****@*****.**'          # Return-Path header
					subject = "Somebody is interested in your hardware!"
					body = """The user {0} is interested in your hardware.
He/She wrote the following text:
{1}""".format(user.username, form.cleaned_data["text"])
					EmailMessage(subject, body, from_email, [hardware.owner.email],
									   headers=headers).send()
			else:
				form = SendmailForm()
			context = {"form":form, "hardware":hardware}
			return render_to_response('hardware/sendmail.html',context , RequestContext(request))
		else:
			return render_to_response('hardware/sendmail.html', {"invalidmail":True} , RequestContext(request))

	else:
		return render_to_response('hardware/sendmail.html', {"ownhardware":True} , RequestContext(request))
Exemple #2
0
def sendMail(request, hardwareid):
	hardware = get_object_or_404(Hardware, id=hardwareid)
	user = request.user
	profile = user.get_profile()
	if hardware.owner != user:
		if user.email != "" and profile.mail_confirmed:
			if request.method == "POST":
				form = SendmailForm(request.POST)
				if form.is_valid():
					logentries = EmailLog.objects.filter(sender=user)
					now = datetime.now()
					logentries = logentries.filter(date__gte=(now - timedelta(days=7)))
					if len(logentries) > 10:
						messages.add_message(request, messages.ERROR, "Du hast bereits einige Mails diese Woche verschickt. Bitte mach doch eine Pause.")
						return HttpResponseRedirect(reverse(displayHardware, args=[hardware.id, hardware.slug]))

					usermails = logentries.filter(receiver=hardware.owner)
					if len(usermails) > 2:
						messages.add_message(request, messages.ERROR, "Du hast bereits einige Mails an diese/n User verschickt. Bitte mach doch eine Pause.")
						return HttpResponseRedirect(reverse(displayHardware, args=[hardware.id, hardware.slug]))


					today = logentries.filter(date=now)
					if len(logentries) > 4:
						messages.add_message(request, messages.ERROR, "Du hast bereits einige Mails heute verschickt. Bitte mach doch eine Pause.")
						return HttpResponseRedirect(reverse(displayHardware, args=[hardware.id, hardware.slug]))


					log = EmailLog()
					log.sender = user
					log.hardware = hardware
					log.receiver = hardware.owner
					log.date = now
					log.save()
					headers = {'Reply-To':user.email}  # From-header
					from_email = '*****@*****.**'          # Return-Path header
					subject = "[hardware für alle] Hardwareanfrage eines Benutzers/einer Benutzerin"
					accounts = SocialAccount.objects.filter(user=request.user)
					accountlist = []
					for account in accounts:
						accountlist.append(account)
					c = Context({"user":user, "hardware":hardware, "text":form.cleaned_data["text"], "usage":form.cleaned_data["usage"], "accountlist":accountlist})
					body = render_to_string("hardware/requestmail.html", c)
					EmailMessage(subject, body, from_email, [hardware.owner.email],
									   headers=headers).send()
					messages.add_message(request, messages.SUCCESS, "E-Mail an den Besitzer wurde verschickt.")
					return HttpResponseRedirect(reverse(displayHardware, args=[hardware.id, hardware.slug]))
			else:
				form = SendmailForm()
			context = {"form":form, "hardware":hardware}
			return render_to_response('hardware/sendmail.html',context , RequestContext(request))
		else:
			return render_to_response('hardware/sendmail.html', {"invalidmail":True} , RequestContext(request))

	else:
		return render_to_response('hardware/sendmail.html', {"ownhardware":True} , RequestContext(request))
def sendMail(request, hardwareid):
    hardware = get_object_or_404(Hardware, id=hardwareid)
    user = request.user
    profile = user.get_profile()
    if hardware.owner != user:
        if user.email != "" and profile.mail_confirmed:
            if request.method == "POST":
                form = SendmailForm(request.POST)
                if form.is_valid():
                    headers = {"Reply-To": user.email}  # From-header
                    from_email = "*****@*****.**"  # Return-Path header
                    subject = "[hardware für alle] Hardwareanfrage eines Benutzers/einer Benutzerin"
                    accounts = SocialAccount.objects.filter(user=request.user)
                    accountlist = []
                    for account in accounts:
                        accountlist.append(account)
                    c = Context(
                        {
                            "user": user,
                            "hardware": hardware,
                            "text": form.cleaned_data["text"],
                            "accountlist": accountlist,
                        }
                    )
                    body = render_to_string("hardware/requestmail.html", c)
                    EmailMessage(subject, body, from_email, [hardware.owner.email], headers=headers).send()
                    messages.add_message(request, messages.SUCCESS, "E-Mail an den Besitzer wurde verschickt.")
                    return HttpResponseRedirect(reverse(displayHardware, args=[hardware.id, hardware.slug]))
            else:
                form = SendmailForm()
            context = {"form": form, "hardware": hardware}
            return render_to_response("hardware/sendmail.html", context, RequestContext(request))
        else:
            return render_to_response("hardware/sendmail.html", {"invalidmail": True}, RequestContext(request))

    else:
        return render_to_response("hardware/sendmail.html", {"ownhardware": True}, RequestContext(request))