def misc(request): if "action" in request.GET: action = request.GET["action"] if action == "markread": user = request.user PostTracking.objects.filter(user__id=user.id).update(last_read=datetime.now(), topics=None) return HttpResponseRedirect(reverse("djangobb:index")) elif action == "report": if request.GET.get("post_id", ""): post_id = request.GET["post_id"] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == "POST" and form.is_valid(): form.save() return HttpResponseRedirect(post.get_absolute_url()) return render(request, "djangobb_forum/report.html", {"form": form}) elif "submit" in request.POST and "mail_to" in request.GET: form = MailToForm(request.POST) if form.is_valid(): user = get_object_or_404(User, username=request.GET["mail_to"]) subject = form.cleaned_data["subject"] body = form.cleaned_data["body"] + "\n %s %s [%s]" % ( Site.objects.get_current().domain, request.user.username, request.user.email, ) user.email_user(subject, body, request.user.email) return HttpResponseRedirect(reverse("djangobb:index")) elif "mail_to" in request.GET: mailto = get_object_or_404(User, username=request.GET["mail_to"]) form = MailToForm() return render(request, "djangobb_forum/mail_to.html", {"form": form, "mailto": mailto})
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action =='markread': user = request.user PostTracking.objects.filter(user__id=user.id).update(last_read=datetime.now(), topics=None) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(post.get_absolute_url()) return render(request, 'djangobb_forum/report.html', {'form':form}) elif 'submit' in request.POST and 'mail_to' in request.GET: form = MailToForm(request.POST) if form.is_valid(): user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] body = form.cleaned_data['body'] + '\n %s %s [%s]' % (Site.objects.get_current().domain, request.user.username, request.user.email) user.email_user(subject, body, request.user.email) return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: mailto = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return (request, 'djangobb_forum/mail_to.html', {'form':form, 'mailto': mailto, })
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action =='markread': user = request.user PostTracking.objects.filter(user__id=user.id).update(last_read=datetime.now(), topics=None) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(post.get_absolute_url()) return {'form':form} elif 'submit' in request.POST and 'mail_to' in request.GET: form = MailToForm(request.POST) if form.is_valid(): user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] body = form.cleaned_data['body'] + '\n %s %s [%s]' % (Site.objects.get_current().domain, request.user.username, request.user.email) # user.email_user(subject, body, request.user.email) ###sending the email with postmark data = {'sender': request.user.get_full_name(), 'recipient': user.get_full_name(), 'subject': form.cleaned_data['subject'], 'body': form.cleaned_data['body'], 'email': user.email, 'mydomain': Site.objects.get(id=1).domain, 'encryptedUsername': urlsafe_b64encode(str(user.id)), } if user.get_profile().idioma == u'es': subject = u'Tienes un mensaje nuevo' template = 'foro-email_es.html' else: subject = u'You have a new message' template = 'foro-email_en.html' if user.get_profile().accept_email_updates: sendHtmlMail("*****@*****.**", subject,template, data,user.email,form.cleaned_data['body'], 'forum/email-templates/') ################################# #aumentando en 1 el puntaje del usuario que envio el mail request.user.get_profile().add_points(1) ########################## return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: mailto = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return {'form':form, 'mailto': mailto, 'TEMPLATE': 'forum/mail_to.html' }
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action == 'markread': user = request.user PostTracking.objects.filter(user__id=user.id).update( last_read=timezone.now(), topics=None) messages.info(request, _("All topics marked as read.")) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() messages.info(request, _("Post reported.")) return HttpResponseRedirect(post.get_absolute_url()) return render(request, 'djangobb_forum/report.html', {'form': form}) elif 'submit' in request.POST and 'mail_to' in request.GET: if not forum_settings.USER_TO_USER_EMAIL and not request.user.is_superuser: raise PermissionDenied form = MailToForm(request.POST) if form.is_valid(): user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] body = form.cleaned_data['body'] + '\n %s %s [%s]' % ( Site.objects.get_current().domain, request.user.username, request.user.email) try: user.email_user(subject, body, request.user.email) messages.success(request, _("Email send.")) except Exception: messages.error(request, _("Email could not be sent.")) return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: if not forum_settings.USER_TO_USER_EMAIL and not request.user.is_superuser: raise PermissionDenied mailto = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return render(request, 'djangobb_forum/mail_to.html', { 'form': form, 'mailto': mailto })
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action == 'markread': user = request.user PostTracking.objects.filter(user__id=user.id).update(last_read=timezone.now(), topics=None) messages.info(request, _("All topics marked as read.")) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() messages.info(request, _("Post reported.")) return HttpResponseRedirect(post.get_absolute_url()) return render(request, 'djangobb_forum/report.html', {'form':form}) elif 'submit' in request.POST and 'mail_to' in request.GET: if not forum_settings.USER_TO_USER_EMAIL and not request.user.is_superuser: raise PermissionDenied form = MailToForm(request.POST) if form.is_valid(): user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] body = form.cleaned_data['body'] + '\n %s %s [%s]' % (Site.objects.get_current().domain, request.user.username, request.user.email) try: user.email_user(subject, body, request.user.email) messages.success(request, _("Email send.")) except Exception: messages.error(request, _("Email could not be sent.")) return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: if not forum_settings.USER_TO_USER_EMAIL and not request.user.is_superuser: raise PermissionDenied mailto = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return render(request, 'djangobb_forum/mail_to.html', {'form':form, 'mailto': mailto} )
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action =='markread': user = request.user PostTracking.objects.filter(user__id=user.id).update(last_read=datetime.now(), topics=None) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(post.get_absolute_url()) return {'form':form} elif 'submit' in request.POST and 'mail_to' in request.GET: form = MailToForm(request.POST) if form.is_valid(): user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] body = form.cleaned_data['body'] + '\n %s %s [%s]' % (Site.objects.get_current().domain, request.user.username, request.user.email) user.email_user(subject, body, request.user.email) return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: user = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return {'form':form, 'user': user, 'TEMPLATE': 'forum/mail_to.html' }
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action == 'markread': user = request.user PostTracking.objects.filter(user__id=user.id).update( last_read=datetime.now(), topics=None) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(post.get_absolute_url()) return render(request, 'djangobb_forum/report.html', {'form': form}) elif 'submit' in request.POST and 'mail_to' in request.GET: form = MailToForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] from_email = request.user.email or email if not from_email or '@' not in from_email: form.errors['email'] = 'Please enter a valid email address!' return render(request, 'djangobb_forum/mail_to.html', {'form': form}) if not request.user.email: request.user.email = from_email request.user.save() body_html = convert_text_to_html(form.cleaned_data['body'], 'bbcode') from_player = request.user.forum_profile.player if from_player: sent_by = '<a href="https://%(website)s/player/%(username)s">%(username)s</a>' % \ {'username': request.user.username, 'website': Site.objects.get_current().domain} else: sent_by = user.username body = '%s<br><br><hr>Sent by <b>%s</b> on the Standard Survival Forum<br>%s' \ % (body_html, sent_by, Site.objects.get_current().domain) message = EmailMessage( subject, body, '%s <%s>' % (request.user.username, settings.DEFAULT_FROM_EMAIL), [user.email], bcc=[settings.DEFAULT_FROM_EMAIL], headers={'Reply-To': from_email}) message.content_subtype = 'html' message.send() h.flash_success(request, 'Email sent to <b>%s</b>!' % user.username) return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: mailto = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return render(request, 'djangobb_forum/mail_to.html', { 'form': form, 'mailto': mailto })
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action == 'markread': user = request.user PostTracking.objects.filter(user__id=user.id).update( last_read=datetime.now(), topics=None) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(post.get_absolute_url()) return {'form': form} elif 'submit' in request.POST and 'mail_to' in request.GET: form = MailToForm(request.POST) if form.is_valid(): user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] body = form.cleaned_data['body'] + '\n %s %s [%s]' % ( Site.objects.get_current().domain, request.user.username, request.user.email) # user.email_user(subject, body, request.user.email) ###sending the email with postmark data = { 'sender': request.user.get_full_name(), 'recipient': user.get_full_name(), 'subject': form.cleaned_data['subject'], 'body': form.cleaned_data['body'], 'email': user.email, 'mydomain': Site.objects.get(id=1).domain, 'encryptedUsername': urlsafe_b64encode(str(user.id)), } if user.get_profile().idioma == u'es': subject = u'Tienes un mensaje nuevo' template = 'foro-email_es.html' else: subject = u'You have a new message' template = 'foro-email_en.html' if user.get_profile().accept_email_updates: sendHtmlMail("*****@*****.**", subject, template, data, user.email, form.cleaned_data['body'], 'forum/email-templates/') ################################# #aumentando en 1 el puntaje del usuario que envio el mail request.user.get_profile().add_points(1) ########################## return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: mailto = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return { 'form': form, 'mailto': mailto, 'TEMPLATE': 'forum/mail_to.html' }
def misc(request): if 'action' in request.GET: action = request.GET['action'] if action =='markread': user = request.user PostTracking.objects.filter(user__id=user.id).update(last_read=datetime.now(), topics=None) return HttpResponseRedirect(reverse('djangobb:index')) elif action == 'report': if request.GET.get('post_id', ''): post_id = request.GET['post_id'] post = get_object_or_404(Post, id=post_id) form = build_form(ReportForm, request, reported_by=request.user, post=post_id) if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(post.get_absolute_url()) return render(request, 'djangobb_forum/report.html', {'form':form}) elif 'submit' in request.POST and 'mail_to' in request.GET: form = MailToForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] user = get_object_or_404(User, username=request.GET['mail_to']) subject = form.cleaned_data['subject'] from_email = request.user.email or email if not from_email or '@' not in from_email: form.errors['email'] = 'Please enter a valid email address!' return render(request, 'djangobb_forum/mail_to.html', { 'form': form }) if not request.user.email: request.user.email = from_email request.user.save() body_html = convert_text_to_html(form.cleaned_data['body'], 'bbcode') from_player = request.user.forum_profile.player if from_player: sent_by = '<a href="https://%(website)s/player/%(username)s">%(username)s</a>' % \ {'username': request.user.username, 'website': Site.objects.get_current().domain} else: sent_by = user.username body = '%s<br><br><hr>Sent by <b>%s</b> on the Standard Survival Forum<br>%s' \ % (body_html, sent_by, Site.objects.get_current().domain) message = EmailMessage(subject, body, '%s <%s>' % (request.user.username, settings.DEFAULT_FROM_EMAIL), [user.email], bcc=[settings.DEFAULT_FROM_EMAIL], headers={'Reply-To': from_email}) message.content_subtype = 'html' message.send() h.flash_success(request, 'Email sent to <b>%s</b>!' % user.username) return HttpResponseRedirect(reverse('djangobb:index')) elif 'mail_to' in request.GET: mailto = get_object_or_404(User, username=request.GET['mail_to']) form = MailToForm() return render(request, 'djangobb_forum/mail_to.html', {'form':form, 'mailto': mailto} )