def flag(request, username, sound_id): sound = get_object_or_404(Sound, user__username__iexact=username, id=sound_id, moderation_state="OK", processing_state="OK") user = None email = None if request.user.is_authenticated(): user = request.user email = request.user.email if request.method == "POST": flag_form = FlagForm(request, request.POST) if flag_form.is_valid(): flag = flag_form.save() flag.reporting_user=user flag.sound = sound flag.save() send_mail_template(u"[flag] flagged file", "sounds/email_flag.txt", dict(flag=flag), flag.email) return HttpResponseRedirect(sound.get_absolute_url()) else: if user: flag_form = FlagForm(request,initial=dict(email=email)) else: flag_form = FlagForm(request) return render_to_response('sounds/sound_flag.html', locals(), context_instance=RequestContext(request))
def flag(request, username, sound_id): sound = get_object_or_404(Sound, id=sound_id, moderation_state="OK", processing_state="OK") if sound.user.username.lower() != username.lower(): raise Http404 user = None email = None if request.user.is_authenticated(): user = request.user email = request.user.email if request.method == "POST": flag_form = FlagForm(request, request.POST) if flag_form.is_valid(): flag = flag_form.save() flag.reporting_user=user flag.sound = sound flag.save() send_mail_template(u"[flag] flagged file", "sounds/email_flag.txt", dict(flag=flag), flag.email) return HttpResponseRedirect(sound.get_absolute_url()) else: if user: flag_form = FlagForm(request,initial=dict(email=email)) else: flag_form = FlagForm(request) return render_to_response('sounds/sound_flag.html', locals(), context_instance=RequestContext(request))
def flag(request, username, sound_id): sound = get_object_or_404(Sound, id=sound_id, moderation_state="OK", processing_state="OK") if sound.user.username.lower() != username.lower(): raise Http404 user = None if request.user.is_authenticated: user = request.user if request.method == "POST": flag_form = FlagForm(request.POST) if flag_form.is_valid(): flag = flag_form.save() flag.reporting_user = user flag.sound = sound flag.save() if user: user_email = user.profile.get_email_for_delivery() else: user_email = flag_form.cleaned_data["email"] send_mail_template_to_support(u"Sound flag: %s - %s" % (sound.user.username, sound.original_filename), "sounds/email_flag.txt", {"flag": flag}, reply_to=user_email) return redirect(sound) else: initial = {} if user: initial["email"] = user.email flag_form = FlagForm(initial=initial) tvars = {"sound": sound, "flag_form": flag_form} return render(request, 'sounds/sound_flag.html', tvars)
def flag(request, username, sound_id): sound = get_object_or_404(Sound, id=sound_id, moderation_state="OK", processing_state="OK") if sound.user.username.lower() != username.lower(): raise Http404 user = None if request.user.is_authenticated: user = request.user if request.method == "POST": flag_form = FlagForm(request.POST) if flag_form.is_valid(): flag = flag_form.save() flag.reporting_user = user flag.sound = sound flag.save() if user: user_email = user.profile.get_email_for_delivery() else: user_email = flag_form.cleaned_data["email"] send_mail_template_to_support( u"Sound flag: %s - %s" % (sound.user.username, sound.original_filename), "sounds/email_flag.txt", {"flag": flag}, reply_to=user_email) return redirect(sound) else: initial = {} if user: initial["email"] = user.email flag_form = FlagForm(initial=initial) tvars = {"sound": sound, "flag_form": flag_form} return render(request, 'sounds/sound_flag.html', tvars)