def mass_notification(request): if request.method != 'POST' or not request.user.is_superuser: raise Http403 form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] message += '\n\n--\nThe %(app_name)s administration.\n%(home)s' % {'app_name': getattr(settings, 'PROJECT_NAME'), 'home': get_full_url(reverse('home'))} maillist = [] addressset = set() for team in Team.objects.filter(project__enabled=True): for u in team.team_members: if not u.is_superuser and not u.is_staff: addressset.add(u.email) addresslist = list(addressset) for i in range(0,len(addresslist),25): maillist.append(EmailMessage(subject=subject, body=message, bcc=addresslist[i:i+25])) try: send_mass_mail_em(maillist) except Exception, e: logger.error(e) messages.warning(request, _("Your message couldn't be delivered to one or more recipients.")) else: messages.success(request, _('Your message has been sent.'))
def team_contact(request, id): logger.debug("Team contact %s" % (id)) team = get_object_or_404(Team, pk=id) if not team.is_member(request.user) and not request.user.is_superuser: raise Http403 if request.method == "POST": form = ContactForm(request.POST) userids = request.POST.getlist("contact_user") if form.is_valid(): if request.user.first_name: usern = "%s (%s)" % (request.user.get_full_name(), request.user.username) else: usern = request.user.username subject = form.cleaned_data["subject"] message = _("%(user)s wrote:") % {"user": usern} + "\n\n" + form.cleaned_data["message"] message += "\n\n--\n" + _("This message was sent through the %(app_name)s contact form.\n") % { "app_name": getattr(settings, "PROJECT_NAME") } userlist = User.objects.filter(username__in=userids) maillist = [] for u in userlist: maillist.append( EmailMessage(subject=subject, body=message, to=[u.email], headers={"Reply-To": request.user.email}) ) try: send_mass_mail_em(maillist) except Exception, e: logger.error(e) messages.warning(request, _("Your message couldn't be delivered to one or more recipients.")) else: messages.success(request, _("Your message has been sent.")) return HttpResponseRedirect( reverse("team_detail", kwargs={"project": team.project.slug, "lang": team.language.code}) )
def join_request(request, teamid): logger.debug("Team join request %s" % (teamid)) use_captcha = getattr(settings, "JOIN_USE_CAPTCHA", True) if use_captcha: from recaptcha.client import captcha captcha_error = "" captcha_valid = True team = get_object_or_404(Team, id=teamid) back = HttpResponseRedirect( reverse("team_detail", kwargs={"project": team.project.slug, "lang": team.language.code}) ) if team.is_member(request.user): messages.warning(request, _("You are already a member of this team.")) return back elif request.user in [r.user for r in team.join_requests.all()]: messages.warning(request, _("You have already sent a join request.")) return back if request.method == "POST": if use_captcha: captcha_response = captcha.submit( request.POST.get("recaptcha_challenge_field", None), request.POST.get("recaptcha_response_field", None), settings.RECAPTCHA_PRIVATE_KEY, request.META.get("REMOTE_ADDR", None), ) captcha_valid = captcha_response.is_valid if not captcha_valid: captcha_error = "&error=%s" % captcha_response.error_code else: team.join_requests.create(user=request.user) if request.user.get_full_name(): username = "******" % (request.user.get_full_name(), request.user.username) else: username = request.user.username sendm = [] sender = request.user.email for coord in team.coordinators.all(): set_user_language(coord) subject = getattr(settings, "EMAIL_SUBJECT_PREFIX", "") + _("Request to join the team") message = render_to_string( "teams/join.mail", {"username": username, "team": team.language.name, "project": team.project.name, "teamid": teamid}, ) sendm.append( EmailMessage(subject=subject, body=message, to=[coord.email], headers={"Reply-To": sender}) ) set_user_language(request.user) try: send_mass_mail_em(sendm) except Exception, e: logger.error(e) messages.success(request, _("Your request to join this team has been received.")) return HttpResponseRedirect( reverse("team_detail", kwargs={"project": team.project.slug, "lang": team.language.code}) )