def user(request, username, section='essentials', action=None, template='djangobb_forum/profile/profile_essentials.html', form_class=EssentialsProfileForm): user = get_object_or_404(User, username=username) if request.user.is_authenticated( ) and user == request.user or request.user.is_superuser: profile_url = reverse('djangobb:forum_profile_%s' % section, args=[user.username]) form = build_form(form_class, request, instance=user.forum_profile, extra_args={'request': request}) if request.method == 'POST' and form.is_valid(): h.flash_success(request, 'Settings saved!') form.save() return HttpResponseRedirect(profile_url) return render(request, template, { 'active_menu': section, 'profile': user, 'form': form, }) else: return HttpResponseRedirect('/player/%s' % username)
def user(request, username, section='essentials', action=None, template='djangobb_forum/profile/profile_essentials.html', form_class=EssentialsProfileForm): user = get_object_or_404(User, username=username) if request.user.is_authenticated() and user == request.user or request.user.is_superuser: profile_url = reverse('djangobb:forum_profile_%s' % section, args=[user.username]) form = build_form(form_class, request, instance=user.forum_profile, extra_args={'request': request}) if request.method == 'POST' and form.is_valid(): h.flash_success(request, 'Settings saved!') form.save() return HttpResponseRedirect(profile_url) return render(request, template, {'active_menu': section, 'profile': user, 'form': form, }) else: return HttpResponseRedirect('/player/%s' % username)
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 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} )